I have polygons created from an intersection with other polygons existing in a single shapefile:
And so the dataframe for this shapefile consists of 4 rows, with separate geometries, each row corresponding to a different intersection zone polygon, and so a row for each color. In this dataframe, there is a “Value” column, where the values of these rows are shown in each section of the intersected polygon. And now, in another shapefile, I have a single point (marked as a red dot), containing a value. When overlayed on top of the first shapefile, we now see this, with the point being spatially “contained” within the lavender zone:
What I am trying to do, using python and geopandas, is to "spatially join" the red point to the lavender intersection zone, so that the current 23 value of the lavender intersection zone is replaced by the 19 value from the point, while the values from the other intersection zones are left unchanged.
I have been trying to use the spatial join function from geopandas to accomplish this, specifically the .sjoin()
function, but am having some confusion here, because when I try to spatially join the point to the polygons, all that remains is the single lavender intersection zone, while the other intersection zones (rows) are missing from the output dataframe. I suppose this is because spatially joining only leaves those features that are actually "spatially joined", though I want to keep all of the intersected zone polygons, just with the intended value replaced.
So far I have tried this:
point_in_poly = gpd.sjoin(intersected_polygons, point, how='inner', op='contains')
which just produces a geodataframe with a single row. How can I augment my spatial join code so that I am given a geodataframe of all of my intersected polygons, but with just the lavender intersection zone's "Value" value replaced with 19, and so four polygon rows?