Ravid
Ravid

Reputation: 1

How can I mimic 'Intersect' arcGIS tool, using geo-spatial packages in python, for large linestring geometry GeoDataFrames?

I have two GeoDataFrames, one is composed of LINESTRINGs ('orig_layer'), and the other of MULTILINESTRINGs ('model_layer'). Both are completely overlap each other - only their line attributes are divided differently (i.e., if I plot them in arcGIS as shp files, they seem as two identical layers, but each is divided differently into different line segments and different amount of attributes). When I use the 'intersect' tool of arcGIS with 'orig_layer' shp (figure 1) as the first input, and 'model_layer' shp (figure 2) as the second input, I receive a new layer ('info_layer' - figure 3) of line attributes, where each line segment from 'orig_layer' that intersected different segments from 'model_layer' is outputted as a new segment, with the boundaries defined based on the intersections of the segments from both layers, and with the columns' values of those segments. When I tried to follow this practice in python, and using geopandas methods, I failed to create the same output.

First, I used the explode function on 'model_layer' gdf (model_layer.explode()), because it contains MULTILINESTRINGs geometries, which make spatial operations very slow and impossible to execute. This divided each attribute in 'model_layer' gdf into several smaller attributes in 'model_layer_explode' gdf.

Then I used -

info_layer_gdf = gpd.overlay(orig_layer, model_layer_explode, how='union')

and I did get new attributes, divided based on the intersections between segments from both gdf's, although some of them did not received the columns' values from both intersecting segments. Note that in figure 4, values of 0 represent nan values which received 0 when exporting the gdf to shp. In addition, some of the resulted attributes overlap each other.

'orig_layer' attributes and columns' values

'model_layer' attributes and columns' values

output layer of the 'intersect' tool ('info_layer') attributes and columns' values

output layer of the 'overlay' and 'explode' functions

Upvotes: 0

Views: 55

Answers (0)

Related Questions