Creating polygon geometry from GeoJSON

You can also create a geometry by passing in GeoJSON to OGR, which saves space compared to the first example:

In: from osgeo import ogr    geojson = """{"type":"Polygon","coordinates":[[[1,1],[5,1],    [5,5],[1,5], [1,1]]]}"""    polygon = ogr.CreateGeometryFromJson(geojson)    print(polygon)  Out: POLYGON ((1 1,5 1,5 5,1 5,1 1))

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.