Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import pyshp
  2. from Shapely import Point # Point class
  3. from Shapely import shape # shape() is a function to convert geo objects through the interface
  4.  
  5. point = (1234,5678) # an x,y tuple
  6. shp = shapefile.reader('path/to/shp') #open the shapefile
  7. all_shapes = shp.shapes() # get all the polygons
  8. all_records = shp.records()
  9. for i in len(all_shapes):
  10. boundary = all_shapes[i] # get the first polygon
  11. if Point(pt).within(shape(boundary)): # make a point as see if it's in the polygon
  12. name = all_records[i][2] # get the second field of the corresponding record
  13. print "The point is in", name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement