Points: ID HN Street 1 5 Examplestreet 2 6 Examplestreet 3 2 Otherstreet 4 2 Anotherstreet Polygons: Name Firstpolygon Secondpolygon Otherpolygon
So I want to performe a one(polygon) to many (points) spatial join and concatenate the joined valus from the points
HN column to a new column "all_HN" in the Polygonsfile.
So the result should look like this:
Name all_HN Firstpolygon 5,6 -> if the points ID1 and ID2 lie within the same polygon (`"Firstpolygon"`) Secondpolygon 2 -> point ID3 within the `"Secondpolygon"` Otherpolygon NULL -> no point within "Otherpolygon" and so on
I thought of solving this with geopandas. (I have about 200.000 Points and 100.000 polygons) Using the following code:
from geopandas import gpd points = gpd.GeoDataFrame.from_file('MyPointsFile) # or geojson etc polys = gpd.GeoDataFrame.from_file('MyPolygonsFile.shp') pointInPoly = gpd.sjoin(points, polys, op='within',how='inner')
Now I thought using something like:
But instead of sum() the right command to concantinate all values of the matching points into a new column "all_HN".
Anyone, any idea how to solve this problem?Its also ok using another package and not geopandas. Since geopandas is based on pandas an pandas solution should also work. It would also be enough to just append all columns of the matches to the corresponding Polygons Tables.