0

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

5
  • gpd.overlay is the function that should give an equivalent (or at least a very similar) answer. A significant difference between both is though that ArcGIS uses a tolerance, so if the lines are very close to each other, but not exactly, ArcGIS will treat them as intersecting while geopandas won't. Can that explain the differences you see? Commented Sep 16, 2024 at 11:33
  • The overlay function does creates all optional segments which result from all intersections between attributes from both layers, but, not all of them received the columns' values from both layers, even though the segments appear as overlapping (or at least intersecting). So, on one hand, it does finds well the intersections, but on the other, the transfer of data from both layers to the new segments seems to work differently. I'm not sure if the tolerance is the reason for this behaviour. Is there a way to define a tolerance for the overlay function? Commented Sep 17, 2024 at 9:03
  • The result of the intersection being in the output geographically but without column values is something odd, and at first sight I don't think this can be explained by the different treatment due to using a tolerance (ArcGIS) versus not having the option to use one (geopandas). I think the only way to get forward on this if you can edit your question and add a simple code example that shows the weird behaviour you are seeing: a script with an example of input data (e.g. in WKT format) + the overlay call you are doing, the result you are getting and the result you are expecting to get. Commented Sep 17, 2024 at 9:19
  • I added some example figures of each layer, how it is divided into different segments and its column values. I hope this will be helpful. Commented Sep 18, 2024 at 14:10
  • I now noticed that you are using 'union' for the geopandas overlay, which explains why pieces that are not intersecting according to the algorithm without tolerance used by geopandas are still in the output, but without joined attributes. So, this confirms that the reason of the diffence is indeed almost certainly that arcgis uses a tolerance and geopandas doesn't. Commented Sep 18, 2024 at 16:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.