I referenced this very helpful question, but still cannot crack the issue.
I downloaded Zillow's neighborhood shapefile for Connecticut and have a latitude and longitude:
41.344602, -73.071443 which exists in CT, according to Google Maps.
As far as I can see, the shapefile is using the same format, yet when I use the following snippet:
import shapefile import shapely.geometry as geometry shapefile_location = 'C:/Downloads/zillow_ct_neighborhood_boundaries/ZillowNeighborhoods-CT.shp' shp = shapefile.Reader(shapefile_location) pt = 41.344602, -73.071443 all_shapes = shp.shapes() # get all the polygons all_records = shp.records() for i in range(0,len(all_shapes)): boundary = all_shapes[i] # get a boundary polygon print( all_records[i],boundary.points) name_ = all_records[i] if 'New Haven' in name_: ok_regions.append(boundary) # print(name_,geometry.Point(pt).within(geometry.shape(boundary))) if geometry.Point(pt).within(geometry.shape(boundary)): # make a point and see if it's in the polygon name_ = all_records[i] # get the second field of the corresponding record print("The point is in", name )
I also tried to reverse the
latitude, longitude combo, but no luck. My code does not find my latitude, longitude combo in any of the neighborhoods.
Does anyone have some guidance on what I may be doing wrong?