Question

get distance from centroid to outer boundary of polygon

  • 9 November 2016
  • 4 replies
  • 16 views

Badge +6
  • Contributor
  • 53 replies

I have some polygons, but I need points (centroid) with an attribute, which holds the maximum distance from the centroid to the polygon-border. I can get the centroid (centerpointExtractor), but how can I get the maximum distance?

Thanks

Vera


4 replies

Userlevel 2
Badge +17

Hi @vki, this might be a possible way.

  1. Counter: Add a sequential number attribute (e.g. "_count") to each polygon as temporary unique identifier.
  2. Chopper (Mode: By Vertex, Maximum Vertices: 1): Decompose the boundary of each polygon into individual vertex points.
  3. VertexCreator (Mode: Add Point): Add the center point to each vertex point to form a line segment connecting between the vertex and the center point.
  4. LengthCalculator: Calculate the length for each line segment.
  5. Sorter: Sort the line segments by length descending.
  6. DuplicateFilter (Key Attributes: _count): Pick the first (i.e. the longest) line segment for each polygon. The length of the resulting line is the "maximum distance" of a polygon.
Userlevel 5
Badge +25

I came up with an alternative solution, but I think the one @takashi came up with is better actually, the downside of mine is that you have to set a max distance in the NeighborFinder and it has to be big enough to catch your maximum centroid-boundary distance.

Badge +6

I tried Takashi's solution and stumbled over another post of him:

https://knowledge.safe.com/answers/21680/view.html

>> I just need a rough approximation of the distance, so this is perfect for me.

Thanks!

Userlevel 4
Badge +25

I see you have an answer, but I will chip in my 2c for posterity and say that the Triangulator transformer might be another solution. Basically compute triangles and select the one with the longest edge. It's what first came to mind for me.

As I was taught as a land surveyor, if in doubt, chop it into triangles!

Reply