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

Accessing vector geometry in shapefiles using Shapely and Fiona

Using Fiona, you can open a shapefile and access attribute data, such as geometries. For example, our Natural Earth dataset contains a shapefile with all of the states in the US with their vector geometries. Use the following code to open the shapefile and get all of the vector geometry of the first feature (starting from index number 0):

In:   import pprint, fiona      with fiona.open\                   (r"C:\data\gdal\NE\110m_cultural\ne_110m_admin_1_states_provinc             es.shp") as src:      pprint.pprint(src[0])

We can use the shape method and pass in all of the coordinates from Minnesota:

In:   from shapely.geometry import shape      minnesota = {'type': 'Polygon', 'coordinates':  [[(-89.61369767938538, 47.81925202085796), ...
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