9. Attribute and Spatial Queries


9.1. Retrieving records using ArcPy


9.2. Retrieving records using Geopandas

import geopandas
import maplotlib
district_gdf = geopandas.read_file("/Users/.../school_district.shp", encoding='utf-8')

# view the attribute information
district_gdf.head()

# view the geometry
district_gdf.plot()


district_gdf.query("DISTRICT=='Ypsilanti'")

#Optionally save the output
district_gdf.to_file(filename)



|

9.3. Pyshp

import shapefile
edit_file = shapefile.Editor('/Users/.../school_districts.shp')
i=0


#Set i as 0 and iterate over the records for the column in which you want to search by passing the index and check with equal operator

for rec in edit_file.records:
       if edit_file.records[i][0] == 'Almora':
         print(rec)
       i= i+1

9.4. References

https://www.geosnips.com/tutorials/python-vector-buffer/