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][2],boundary.points)
    name_ =  all_records[i][2]
    if 'New Haven' in name_:
    #     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][2] # 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?

  • 1
    You need to verify that all_shapes has the same CRS (e.g. epsg:4326) as shp. Also, you might want to look into geopandas which will let you do this without a loop.
    – Jon
    Nov 19 '18 at 2:53

Apparently, your point does not fall within any of the polygons of your shapefile. It falls somewhere in Ansonia. Your code will never find a matching polygon for that coordinate:

enter image description here

  • What did you use for this plot?
    – jason m
    Nov 19 '18 at 13:18
  • I simply displayed the shapefile in Google Earth Pro
    – FSimardGIS
    Nov 19 '18 at 17:07

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .