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 data with Fiona

The following code reads a file from our Natural Earth dataset and prints its dictionary keys:

In:   import fiona      c = fiona.open(r"C:\data\gdal\NE\      110m_cultural\ne_110m_admin_1_states_provinces.shp")      rec = next(iter(c))      rec.keys()Out:  dict_keys(['type', 'id', 'geometry', 'properties'])

Using the data pretty-print (pprint) library that is part of Python's standard library, we can print the corresponding values to the keys of the first feature from our dataset:

In:   import pprint      pprint.pprint(rec['type'])      pprint.pprint(rec['id'])      pprint.pprint(rec['properties'])      pprint.pprint(rec['geometry'])Out:  'Feature'      '0'      OrderedDict([('adm1_code', 'USA-3514'),                  ('diss_me', 3514),                  ('iso_3166_2', 'US-MN'),                  ('wikipedia',                                                'http://en.wikipedia.org/wiki/Minnesota'), ...
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