I have two Geodataframes. First GeoDataframe contains polygons columns, and the other one contains points (latitude and longitude). I want to do this to check whether the coordinates I was provided are inside the polygon of the city. Please click on the image below to see both dataframe.
GDF_1 contains polygon/multi-polygon
GDF_2 contains city points (coordinate)
When the ID is in gdf_1.id and gdf_2.id equal to each then uses the within the function to see if the coordinate in gdf_2 is inside the polygon in the gdf_1. For example, the code below would result in True because the coordinate is within the polygon.
poly = gdf_1[gdf_1.id == '17085']['geometry']
p1 = gdf_2[gdf_2.id == '17085']['geometry']
p1.within(poly, align=False)
I've been having hard time to iterate both Dataframe and compare them to each other. Is there anyways for me to compare both Dataframe to each other?
Desired output: (This is just an example)
id | gdf_2.geometry | bool |
---|---|---|
17085 | POINT(19.82092 41.32791) | True |
4505 | POINT(153.02560 -2746738) | True |
18526 | POINT(145.12103 -37.85048) | True |
5049 | POINT(146.36182 -41.18134) | False |
4484 | POINT(150.84249 -33.80261) | False |