I would like to extract a named subset of the text records from a shapefile using Python/pyshp. Is there a clean/efficient way to do this?
Ideally I'd like to use dictionary-like access such as:
import shapefile
sf = shapefile.Reader("MyFile.shp")
data = sf.record['desired_record_name']
But of course this doesn't work. So far my solution is the brute force approach of looping over all entries:
import shapefile
sf = shapefile.Reader("MyFile.shp")
for r in sf.iterRecords():
if r[0]=='desired_record_name':
data = r
break
But this leaves a lot to be desired, especially for large/many files.
Note: Although I like the simplicity of pyshp, I am not tied to it, so other free & open-source solutions using python are also of interest.