Â
Â
Hello - I am trying to compare polygons I have saved in a database to polygons I am creating using the polygonbuilder. The polygons are basically the same. I am trying to find polygons that have changed shape. I am using the CRCcalulator. I don't really want to use the changedector or matcher. The problem I am having is that some of the polygons are exactly the same except for the order of the vertices which in turn causes different CRC values to be calculated. Is there any way to re-order the polygon vertices so that a polygon's 1st vertex is always in the same place eg. lower left corner. The polygonbuilder seems to randomly pick which vertex will be the 1st vertex.
Page 1 / 1
I should add that I have trying using the Orientor and it doesn't help.
Â
Â
Hi,
Â
Â
Round about solution is to generate points with numbers and unique ID such that you can rebuild the polyon by starting the lower left point (considering near to previous polygon) or else you can take the lower X and lower Y of all the points (some logically calcualtion is required based on the data).Â
Â
Hope it helps...Â
Â
PratapÂ
Hi,Â
Â
If you added coordinate values of required first vertex to each feature as attributes (e.g. "x" and "y"), the PythonCaller may be a quick way.Â
-----Â
# Python Script ExampleÂ
# Assume feature geometry is a single-part polygon having a Line boundary;Â
# every feature has attributes "x" and "y" for specifying the first vertex.Â
import fmeobjectsÂ
Â
def rotatePolygonVertices(feature):Â
  # Get coordinate list of original polygon, except end node.Â
  coords = feature.getAllCoordinates()A:-1]Â
  ÂÂ
  # Get specified coordinate.Â
  x = float(feature.getAttribute('x'))Â
  y = float(feature.getAttribute('y'))Â
  ÂÂ
  # Find index of vertex that matches with the specified coordinate.Â
  # To avoid computational error, find closest vertex from the coordinate.Â
  index = 0Â
  min_d = (coordsÂ0]Â0] - x)**2 + (coordsÂ0]Â1] - y)**2Â
  for i, xy in enumerate(coords)1:]):Â
    d = (xyi0] - x)**2 + (xyd1] - y)**2Â
    if d < min_d:Â
      index , min_d = i +1, dÂ
      ÂÂ
  # Reset polygon if the first vertex doesn't match with the specified coordinate.Â
  # Rotate and close the coordinate list, and then create new polygon.Â
  if 0 < index:Â
    coords = coords index:] + coordso:index] # rotateÂ
    coords.append(coords 0]) # closeÂ
    newBoundary = fmeobjects.FMELine(coords)Â
    feature.setGeometry(fmeobjects.FMEPolygon(newBoundary))Â
-----Â
Â
Takashi
Hi,
Â
Â
what is the reason for not wanting to use the Matcher? It is very efficient and handles large datasets without problem. Takashi's solution is elegant, but I doubt it'd be quicker than the Matcher.Â
Â
David
Yes, scripting is the second best of course. I too would like to know the reason for not using the Matcher.
I agree with Daid that the Matcher should suffice.
Â
You nee to use the option "lenient matching" .Â
That will ignore vertex ordering.Â
Â
Â
Also you can compare the vertices using only fme transformers, no need to script at all.