Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyshp
- from Shapely import Point # Point class
- from Shapely import shape # shape() is a function to convert geo objects through the interface
- point = (1234,5678) # an x,y tuple
- shp = shapefile.reader('path/to/shp') #open the shapefile
- all_shapes = shp.shapes() # get all the polygons
- all_records = shp.records()
- for i in len(all_shapes):
- boundary = all_shapes[i] # get the first polygon
- if Point(pt).within(shape(boundary)): # make a point as see if it's in the polygon
- name = all_records[i][2] # get the second field of the corresponding record
- print "The point is in", name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement