[GIS] geopandas + shapely. Point within a shape

geopandasshapefileshapelywithin

I am using geopandas to import a shapefile and then check if a point is within that shape. I am using the shapefile found in http://opendata.atlantaregional.com/datasets/cities-georgia?geometry=-87.766%2C33.036%2C-81.448%2C34.633 to get the shape of Atlanta. However, whenever I "ask" if a point is within that shape (the point is surely within the shape), the function returns False. I have tried creating a Polygon and then asking if a point is within that polygon and it works as expected.

I don't know what else to do to troubleshot or debug this issue.

I am doing all of this using a jupyter notebook. Here is the MWE: https://github.com/vcaballero-salle/mwe-shapefile

The code looks like (full code with imports can be found at the github repo, in the README.md):

plt.clf()
shape = gp.read_file(r'./Cities_Georgia/Cities_Georgia.shp')

atlanta_shape = shape[shape["Name"] == "Atlanta"]

atlanta_shape.plot()

plt.show()
plt.ion()


# In[10]:


def within_shape(df, shapes):
    in_shape = []
    for sh in shapes.geometry:
        within = df.within(sh)
        in_shape.append(within)
    return in_shape


print(within_shape(Point(33.751079, -84.443274), atlanta_shape)) # This returns [False]

Best Answer

You inverted the "Latitude" and "Longitude" when you create the point...

print(within_shape(Point(-84.443274, 33.751079), atlanta_shape)) #This returns [True]