Esempio n. 1
0
def test_multipolygon():
    g = geojson.MultiPolygon([
        ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
        ([(23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)],)])
    itr = coords(g)
    pairs = list(itr)
    assert pairs[0] == (3.78, 9.28)
    assert pairs[-1] == (23.18, -34.29)
Esempio n. 2
0
 def test_multipolygon(self):
     g = geojson.MultiPolygon([
         ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
         ([(23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)],)])
     itr = coords(g)
     pairs = list(itr)
     self.assertEqual(pairs[0], (3.78, 9.28))
     self.assertEqual(pairs[-1], (23.18, -34.29))
Esempio n. 3
0
def coords(obj):
    """Yield all coordinate coordinate tuples from a geometry or feature."""
    if isinstance(obj, (tuple, list)):
        coordinates = obj
    elif 'geometry' in obj:
        coordinates = obj['geometry']['coordinates']
    else:
        coordinates = obj.get('coordinates', obj)
    for e in coordinates:
        if isinstance(e, (float, int)):
            yield tuple(coordinates)
            break
        else:
            for f in coords(e):
                yield f
Esempio n. 4
0
def test_dict():
    itr = coords({'type': 'Point', 'coordinates': [-115.81, 37.24]})
    assert next(itr) == (-115.81, 37.24)
Esempio n. 5
0
def test_point():
    itr = coords(geojson.Point((-115.81, 37.24)))
    assert next(itr) == (-115.81, 37.24)
Esempio n. 6
0
def test_point_feature():
    itr = coords(geojson.Feature(geometry=geojson.Point((-115.81, 37.24))))
    assert next(itr) == (-115.81, 37.24)
Esempio n. 7
0
 def test_point(self):
     itr = coords(geojson.Point((-115.81, 37.24)))
     self.assertEqual(next(itr), (-115.81, 37.24))
Esempio n. 8
0
 def test_point_feature(self):
     itr = coords(geojson.Feature(geometry=geojson.Point((-115.81, 37.24))))
     self.assertEqual(next(itr), (-115.81, 37.24))
Esempio n. 9
0
 def test_dict(self):
     itr = coords({'type': 'Point', 'coordinates': [-115.81, 37.24]})
     self.assertEqual(next(itr), (-115.81, 37.24))
Esempio n. 10
0
 def test_point_feature(self):
     itr = coords(geojson.Feature(geometry=geojson.Point((-115.81, 37.24))))
     self.assertEqual(next(itr), (-115.81, 37.24))
Esempio n. 11
0
 def test_dict(self):
     itr = coords({'type': 'Point', 'coordinates': [-115.81, 37.24]})
     self.assertEqual(next(itr), (-115.81, 37.24))
Esempio n. 12
0
 def test_point(self):
     itr = coords(geojson.Point((-115.81, 37.24)))
     self.assertEqual(next(itr), (-115.81, 37.24))