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'),
('iso_a2', 'US'),
('adm0_sr', 1),
('name', 'Minnesota'), ….
Use the following methods on the data file object for printing the following information:
In: print(len(c)) # prints total amount of features
print(c.driver) # prints driver name
print(c.crs) # prints coordinate reference system of data file
Out: 51
ESRI Shapefile
{'init': 'epsg:4326'}