Exemplo n.º 1
0
def test_LocationSet_asXY():
    pts = [(2, 3), (4, 2), (5, 7)]
    ls = LocationSet(pts)
    xyvals = ls.asXY(srs=EPSG4326)

    assert np.isclose(xyvals[1], (4, 2)).all()
    assert np.isclose(xyvals[2], (5, 7)).all()
Exemplo n.º 2
0
def test_LocationSet_asString():
    pts = [(2,3), (4,2), (5,5)]
    ls = LocationSet(pts)

    s = ls.asString()
    if not s[1]=="(4.00000,2.00000)": error("asString")

    print( "LocationSet_asString passed")
Exemplo n.º 3
0
def test_LocationSet_asHash():
    pts = [(2, 3), (4, 2), (5, 7)]
    ls = LocationSet(pts)
    h = ls.asHash()

    assert h[0] == 3927246602883527356
    assert h[1] == 3568298024840608381
    assert h[2] == 3686734391468548956
Exemplo n.º 4
0
def test_LocationSet_asGeom():
    pts = [(2, 3), (4, 2), (5, 7)]
    ls = LocationSet(pts)
    geoms = ls.asGeom()

    assert np.isclose(geoms[1].GetX(), 4)
    assert np.isclose(geoms[1].GetY(), 2)
    assert np.isclose(geoms[2].GetX(), 5)
    assert np.isclose(geoms[2].GetY(), 7)
Exemplo n.º 5
0
def test_LocationSet_getBounds():
    ls = LocationSet(pointsInAachen4326)

    bounds = ls.getBounds(3035)

    assert np.isclose(bounds[0], 4039553.1900635841)
    assert np.isclose(bounds[1], 3052769.5385426758)
    assert np.isclose(bounds[2], 4065568.4155270099)
    assert np.isclose(bounds[3], 3087947.74365965)
Exemplo n.º 6
0
def test_LocationSet_makePickleable():
    pts = [(2, 3), (4, 2), (5, 5)]
    ls = LocationSet(pts)
    geoms = ls.asGeom()

    assert not ls[1]._geom is None

    ls.makePickleable()

    assert ls[1]._geom is None
Exemplo n.º 7
0
def test_LocationSet_getBounds():
    ls = LocationSet(pointsInAachen4326)

    bounds = ls.getBounds(3035)

    compare(bounds[0], 4039553.1900635841)
    compare(bounds[1], 3052769.5385426758)
    compare(bounds[2], 4065568.4155270099)
    compare(bounds[3], 3087947.74365965)

    print( "LocationSet_getBounds passed")
Exemplo n.º 8
0
def test_LocationSet_asHash():
    pts = [(2, 3), (4, 2), (5, 7)]
    ls = LocationSet(pts)
    h = ls.asHash()

    assert isinstance(h[0], int)
    assert isinstance(h[1], int)
    assert isinstance(h[2], int)

    assert h[0] != h[1]
    assert h[0] != h[2]
    assert h[1] != h[2]
Exemplo n.º 9
0
def test_LocationSet___getitem__():
    ls = LocationSet([[1, 1],
                      [1, 2],
                      [2, 2.5],
                      [2, 3], ])

    assert ls[2] == (2, 2.5)
Exemplo n.º 10
0
def test_Extent_fromLocationSet():
    ls = LocationSet(pointsInAachen3035)

    ex1 = Extent.fromLocationSet(ls)

    assert np.isclose(ex1.xMin, 4039553.19006)
    assert np.isclose(ex1.yMin, 3052769.53854)
    assert np.isclose(ex1.xMax, 4065568.41553)
    assert np.isclose(ex1.yMax, 3087947.74366)
Exemplo n.º 11
0
def test_LocationSet_splitKMeans():
    pts = [(-1, -1), (-1, -1.5), (2, 1), (2, 1.5),
           (2, -1), (2, -1.5), (2, -1.25)]
    locs = LocationSet(pts)

    sublocsGen = locs.splitKMeans(groups=3, random_state=0)

    sublocs = list(sublocsGen)

    assert sublocs[0].count == 3
    assert sublocs[0][0] == (2, -1)
    assert sublocs[0][1] == (2, -1.5)
    assert sublocs[0][2] == (2, -1.25)

    assert sublocs[1].count == 2
    assert sublocs[1][0] == (-1, -1)
    assert sublocs[1][1] == (-1, -1.5)

    assert sublocs[2].count == 2
    assert sublocs[2][0] == (2, 1)
    assert sublocs[2][1] == (2, 1.5)
Exemplo n.º 12
0
def test_LocationSet___init__():
    # From xy list
    ls = LocationSet(pointsInAachen4326)

    # From numpy array
    ls2 = LocationSet( np.array(pointsInAachen4326))
    if not ls[1] == ls2[1]: error("LocationSet init")

    # From numpy array with srs change
    ls2 = LocationSet( np.array(pointsInAachen3035), srs=3035)
    if not ls[1] == ls2[1]: error("LocationSet init")

    # From single pt
    ls3 = LocationSet(xy)
    if not ls3.count==1: error("LocationSet single xy")

    # From single geom
    pt = point(*xy, srs=4326)
    ls4 = LocationSet(pt)
    if not ls4.count==1: error("LocationSet single geom")
    if not ls3[0]==ls4[0]: error("LocationSet single xy")

    # From many geoms
    pts = [ point(x,y, srs=4326) for x,y in np.random.random(size=(10,2)) ]
    ls5 = LocationSet(pts)
    if not ls5.count==10: error("LocationSet single geom")
   
    print( "LocationSet___init__ passed")
Exemplo n.º 13
0
def test_LocationSet___init__():
    # From xy list
    ls = LocationSet(pointsInAachen4326)

    # From numpy array
    ls2 = LocationSet(np.array(pointsInAachen4326))
    assert ls[1] == ls2[1]

    # From numpy array with srs change
    ls2 = LocationSet(np.array(pointsInAachen3035), srs=3035)
    assert ls[1] == ls2[1]

    # From single pt
    ls3 = LocationSet(xy)
    assert ls3.count == 1

    # From single geom
    pt = geom.point(*xy, srs=4326)
    ls4 = LocationSet(pt)
    assert ls4.count == 1
    assert ls3[0] == ls4[0]

    # From many geoms
    pts = [geom.point(x, y, srs=4326)
           for x, y in np.random.random(size=(10, 2))]
    ls5 = LocationSet(pts)
    assert ls5.count == 10
Exemplo n.º 14
0
def test_LocationSet_bisect():
    pts = [(-1, -1), (-1, -1.5), (2, 1), (2, 1.5),
           (2, -1), (2, -1.5), (2, -1.25)]
    locs = LocationSet(pts)

    # Lon Only
    sublocsGen = locs.bisect(lon=True, lat=False)

    sublocs = list(sublocsGen)

    assert sublocs[0].count == 2
    assert sublocs[0][0] == (-1, -1)
    assert sublocs[0][1] == (-1, -1.5)

    assert sublocs[1].count == 5
    assert sublocs[1][0] == (2, 1)
    assert sublocs[1][1] == (2, 1.5)
    assert sublocs[1][2] == (2, -1)
    assert sublocs[1][3] == (2, -1.5)
    assert sublocs[1][4] == (2, -1.25)

    # Lat Only
    sublocsGen = locs.bisect(lon=False, lat=True)

    sublocs = list(sublocsGen)

    assert sublocs[0].count == 3
    assert sublocs[0][0] == (-1, -1.5)
    assert sublocs[0][1] == (2, -1.5)
    assert sublocs[0][2] == (2, -1.25)
    
    assert sublocs[1].count == 4
    assert sublocs[1][0] == (-1, -1)
    assert sublocs[1][1] == (2, 1)
    assert sublocs[1][2] == (2, 1.5)
    assert sublocs[1][3] == (2, -1)
Exemplo n.º 15
0
def test_Extent_load():
    # Explicit
    ex1 = Extent.load((1, 2, 3, 4), srs=4326)
    assert np.isclose(ex1.xMin, 1)
    assert np.isclose(ex1.xMax, 3)
    assert np.isclose(ex1.yMin, 2)
    assert np.isclose(ex1.yMax, 4)
    assert ex1.srs.IsSame(EPSG4326)

    # Geometry
    ex2 = Extent.load(GEOM)
    assert np.isclose(ex2.xMin, 10.10000)
    assert np.isclose(ex2.xMax, 14.60000)
    assert np.isclose(ex2.yMin, 30.50000)
    assert np.isclose(ex2.yMax, 38.10000)
    assert ex2.srs.IsSame(EPSG4326)

    # vector
    ex3 = Extent.load(AACHEN_POINTS)

    assert np.isclose(ex3.xMin, 6.03745)
    assert np.isclose(ex3.xMax, 6.33091)
    assert np.isclose(ex3.yMin, 50.5367)
    assert np.isclose(ex3.yMax, 50.9227)
    assert ex3.srs.IsSame(EPSG4326)

    # Raster
    ex4 = Extent.load(CLC_RASTER_PATH)
    assert np.isclose(ex4.xMin, 4012100)
    assert np.isclose(ex4.yMin, 3031800)
    assert np.isclose(ex4.xMax, 4094600)
    assert np.isclose(ex4.yMax, 3111000)
    assert ex4.srs.IsSame(EPSG3035)

    # Location set
    ls = LocationSet(pointsInAachen3035, srs=3035)
    ex5 = Extent.load(ls)

    assert np.isclose(ex5.xMin, 6.02141)
    assert np.isclose(ex5.yMin, 50.51939)
    assert np.isclose(ex5.xMax, 6.371634)
    assert np.isclose(ex5.yMax, 50.846025)
    assert ex5.srs.IsSame(EPSG4326)
Exemplo n.º 16
0
def test_LocationSet_asString():
    pts = [(2, 3), (4, 2), (5, 5)]
    ls = LocationSet(pts)

    s = ls.asString()
    assert s[1] == "(4.00000,2.00000)"