Skip to main content

Hello everyone,

 

I have a shapefile with polygons (neighborhoods) and a shapefile with lines (waterways). Each polygon has a specific code attached to it. I want to provide each line with the code of the polygon it runs through. When the line runs through several polygons, it must get the code of the polygon through which the line runs the longest. 

 

Does anyone know how I can best handle this?

 

Regards Bas

 

The attached workbench should give you the desired results. To sum it up:

  • Archive the original geometry of the lines
  • Split the lines per the polygons, which merges the code onto the lines
  • Calculate the length, and find the max length
  • Test for length equaling the max length, keeping those.
  • Replace the geometry with the archived original geometry.

(If you already have a unique ID on the lines, you can use that instead of creating one in the Counter transformer. You will just need to update the StatisticsCalculator to your unique ID.)

 

image


Here is the workbench:


Thank you, this is very useful!!


Hello @dustin​ ,

 

I have a few questions about the workbench:

 

do I have to add 1 file geodatabase to the reader where the polygons and the lines are located?

do you have the parameters for the LengthCalculator? I had to re-add this.

where can I find my output data? Because there is no writer.

 

thanks in advance,

 

Bas

 


@bascopier​ Yes. You will need to add your geodatabase reader feature types, feeding your lines and polygons as I did my test data. The LengthCalculator used the default settings (_length). You will need to add a writer for the format you are wanting to write to, which will go right after the GeometryReplacer (instead of the Inspector I was using for testing)


@dustin​ so i have 1 geodatabase that includes the lines ánd the polygons and use this for both readers (lines and polygons).


When you read in the geodatabase, it will read in both the line and polygon feature classes (whatever your feature classes are named, not necessarily 'line' and 'polygon'). The lines would be fed into the Counter, polygons would be fed into the area port of the LineonAreaOverlayer.image


Reply