I am using Python geopandas and I have two shapefiles. One of them is a grid file containing equal polygons. The other shapefile is a linestring file with several lines and its Attributes.
The idea is to do a multiplication with the intersection length of each individual line within a grid cell and finally sum up all multiplication results which belong to this certain grid cell. Each row is one grid cell in the grid shapefile. I need the length of each intersection which is inside a grid cell. So there might be only one grid cell, but multiple intersections within this certain grid cell.
This simple multiplication should be like this:
df['new_column_result']= line['intersection_length_inside _cell_i']*line['factor_x']
And afterwards use this multiplication to calculate the sum of all
df['new_column_result'] that are in the cell.
Additionally, the grid cells which are not touching any lines at all should be removed and the two shapefiles should be merged as an output. This part I managed to do by using the sjoin function of geopandas. But I am not sure if it is suitable for my goals. Sadly at the moment I get the same grid cell (with the same grid cell ID) multiple times. I guess it is produced for each "intersection_length_inside _cell_i".
For joining this two dataframes(or shapefiles) I use:
intersections = geopandas.sjoin(gridshapefile, lineshapefile, how="inner", op='intersects')