Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

Reading JSON geometries with Shapely

Although Shapely does not read or write data files, you can access geometries from outside of the library, for instance, by feeding it vector data written in json. The following script creates a polygon in json that is read into Shapely in line. Next, the mapping command returns a new, independent geometry with coordinates copied from the context:

In:    import json       from shapely.geometry import mapping, shape       p = shape(json.loads('{"type": "Polygon", "coordinates":                                            [[[1,1], [1,3 ], [3,3]]]}'))       print(json.dumps(mapping(p)))       p.areaOut:   {"type": "Polygon", "coordinates": [[[1.0, 1.0], [1.0, 3.0],                                    [3.0, 3.0], [1.0, 1.0]]]}       2.0          # result of p.area
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content