How to use the geojson.GeometryCollection function in geojson

To help you get started, we’ve selected a few geojson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jazzband / geojson / tests / test_validation.py View on Github external
def test_invalid_geometrycollection(self):
        point = geojson.Point((10, 20))
        bad_poly = geojson.Polygon([[(2.38, 57.322), (23.194, -20.28),
                                   (-120.43, 19.15), (25.44, -17.91)]])

        geom_collection = geojson.GeometryCollection(
                geometries=[point, bad_poly]
            )
        self.assertFalse(geom_collection.is_valid)
github jazzband / geojson / tests / test_coords.py View on Github external
def test_geometrycollection(self):
        p1 = geojson.Point((-115.11, 37.11))
        p2 = geojson.Point((-115.22, 37.22))
        ln = geojson.LineString(
            [(-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5)])
        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(geojson.GeometryCollection([p1, p2, ln, g]))
        pairs = set(itr)
        self.assertEqual(pairs, set([
            (-115.11, 37.11), (-115.22, 37.22),
            (-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5),
            (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)
        ]))
github jazzband / geojson / tests / test_validation.py View on Github external
def test_valid_geometrycollection(self):
        point = geojson.Point((10, 20))
        poly = geojson.Polygon([[(2.38, 57.322), (23.194, -20.28),
                                (-120.43, 19.15), (2.38, 57.322)]])

        geom_collection = geojson.GeometryCollection(
                geometries=[point, poly]
            )
        self.assertTrue(geom_collection.is_valid)
github bukun / book_python_gis / part010 / ch09_others / sec2_geojson / test_2_geojson_x_x.py View on Github external
(-20.51, 1.51), (-5.21, 23.51)]
])
###############################################################################
from geojson import MultiPolygon
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)],)
])
###############################################################################
from geojson import GeometryCollection, Point, LineString
from pprint import pprint
my_point = Point((23.532, -63.12))
my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])
pprint(GeometryCollection([my_point, my_line]))
###############################################################################
from geojson import Feature, Point
my_point = Point((-3.68, 40.41))
Feature(geometry=my_point)
###############################################################################
Feature(geometry=my_point,properties={"country":"Spain"})
###############################################################################
Feature(geometry=my_point, id=27)
###############################################################################
from geojson import FeatureCollection
my_feature = Feature(geometry=Point((1.6432, -19.123)))
my_other_feature = Feature(
    geometry=Point((-80.234, -22.532)))
pprint(FeatureCollection([my_feature, my_other_feature]))
github descarteslabs / descarteslabs-python / descarteslabs / common / shapely_support / __init__.py View on Github external
# Shapely cannot handle GeoJSON Features or FeatureCollections
    if isinstance(geoj, geojson.Feature):
        geoj = _parse_geojson_safe(geojson_dict["geometry"])
    elif isinstance(geoj, geojson.FeatureCollection):
        features = []
        for feature in geojson_dict.get("features", []):
            try:
                features.append(_parse_geojson_safe(feature["geometry"]))
            except (TypeError, KeyError, UnicodeEncodeError) as ex:
                raise ValueError(
                    "feature in FeatureCollection not recognized as valid ({}): {}".format(
                        str(ex), feature
                    )
                )
        geoj = geojson.GeometryCollection(features)
    return geoj
github atlregional / bus-router / bus_router.py View on Github external
if not legpoints:
				continue
			else:
				simplified = simplify(legpoints, .0002, True)
				# print "new:" + str(simplified)
				count = 0
				for point in simplified:
					jsonpoints.append((point['x'], point['y']))
					shppoint = [point['x'], point['y']]
					shppoint.insert(0, trip)
					shppoint.insert(1, count)
					shppoint.insert(2, "")
					shapeswriter.writerow(shppoint)
					count += 1
				ls = LineString(jsonpoints)
				gc = GeometryCollection([ls])

				gtfsfile = os.path.join(geojsondir, trip + '.geojson')

				with open(gtfsfile, 'wb') as tripgeo:
					geojson.dump(gc, tripgeo)