Global Mapper v25.0

Centroids wrong computated - twice

hgleixner
hgleixner Global Mapper UserTrusted User
edited February 2015 in Bug Report
Hello
as you see in the attachments both computations of 23 centroids obviously failed.

centroid_01.png with checked "Move centroid Point if outside area boundary"
centroid_02.png without

Please have a look!

GM 16.1.2 (b021515) 64 bit

Thanks
Henry

Comments

  • hgleixner
    hgleixner Global Mapper User Trusted User
    Hello,
    until now I got no answer. Very sad!
    Henry
  • bmg_bob
    bmg_bob Global Mapper Programmer
    If you don't get a response here, you should try sending a formal support request via the Help->Send Support Request... menu in Global Mapper, or by sending and e-mail containing a description of your workflow and the error message, along with sample data, if possible, to Blue Marble Geographics Support (geohelp@bluemarblegeo.com).  Either of these methods will ensure that the support team sees the problem and that you get a timely response.

    Before you do that, I recommend getting the latest version of Global Mapper 16.2 to see if this problem has been fixed.

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Henry,

    I just noticed this bug and took a look. It appears there was a problem calculating some centroids based on overflows with the math with large easting/northing values. I have fixed this and we now get very nice centroids for your sample data. I have placed new builds with the latest changes at http://data.bluemarblegeo.com/downloads/global-mapper/dailybuilds/ for you to try.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • hgleixner
    hgleixner Global Mapper User Trusted User
    Mike,
    thanks but, using the new build, unfortunately the centroid of another area is computated wrong again, see the screenshot: its obviously wrong (use EPSG:31468 and change the area file back from *.txt to *.xyz)

    (It already worked about 2 or 3 years ago. If I find the old discussion, I will give a hint...)
    Henry

  • tjhb
    tjhb Global Mapper User Trusted User
    FWIW that centroid looks correct to me.

    It is the centre of the enclosing circle of the area. That is what it should be.

    (It is not a weighted centroid.)
  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    As far as I can tell that calculated centroid is correct. If you draw a circular area centered on the calculated centroid it looks like the minimum bounding circle in the coordinate system is centered on that point. Note the default circle will use great circle coordinates and not the coordinate system so it is slightly off if you have great circle distance enabled (the default).

    It's possible some older versions of GM may have used the label position instead of the actual mathematical centroid (barycenter of the polygon) when creating the centroid points. Some parts of GM will use the center of the longest of the lines through the horizontal and vertical centers of the bounding box of the polygons after clipping to the polygons for labels. This may have been used in some versions and produced a more desirable location as compared to the mathematical centroid. If you want I could add an option to always use that rather than the mathematical centroid.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • hgleixner
    hgleixner Global Mapper User Trusted User
    Mike,
    please implement the mathematical centroid as described in https://en.wikipedia.org/wiki/Centroid (section "centroid of a polygon"). Thats what I mean and what I successfully used in GlobalMapper over years - included the 2 options "move centroid point, if Outside area boundary" and "Create a Single Point for Grouped Areas".

    If usefull compare with centroids computed by QGIS, ArcGIS and so on.
    Thanks
    Henry

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Henry,

    For some reason I'm not getting notifications about posts to this thread so I had no idea that you replied.

    The method specified on Wikipedia in the 'centroid of a polygon' section is exactly the algorithm used by Global Mapper. Note that the centroid is calculated in the native projection of the layer, so if you move the data to a layer that is natively in a different projection the centroid will be slightly different due to the different distortions in that map projection.

    The other method discussed at the top of the Wikipedia page calculates the center of mass for a set of points by averaging the XY locations of the points. That method would not be appropriate for a polygon as the distribution of the vertices around the edge would change the centroid even if the shape didn't change.

    The other method that is used inside GM when the centroid is outside the polygon is to draw a line through the horizontal and vertical centers of the polygon bounding box. Each of those lines is cropped to the polygon, then the center of the longest cropped segment is used as the label location. This method will often likely give you a better position for drawing a label. I could add an option to always use that rather than the mathematical centroid.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • Mykle
    Mykle Global Mapper User Trusted User
    This is what I get for Henry's 3280 file.   Looks good to me.   (current version of GM)

    For the map polygon, I get the same location as shown in Henry's example.

    If this should be the center of the minimum diameter circle that encompasses the polygon,
    that would be for a 110km circle centered about 10km south of the "centroid" calculated point. 

  • hgleixner
    hgleixner Global Mapper User Trusted User
    Mike,
    I think the centroid computation is still wrong.

    Please try to reproduce as follows:
    1. Load the file Mittelpunkt_Ofr_nur_Programmtest_Fläche.xyz (after changing txt to xyz - EPSG:31468)
    2. Compute the centroid. It is the right one in the screenshot.
    3. Compare with the attached excel computation, which formulas we agree. See the centroid coordinates from the last xls line: 4450267.521, 5594395.903. That centroid is the left point feature in the screenshot - obviously the correct one.

    Henry





  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Henry,

    Your formulas are completely different than what GM is using (the ones from the Wikipedia 'Centroid of a Polygon' section), but I see that when I updated the formulas to scale the values to avoid floating point round-off I messed up the final division by the total area (multiplied instead). The scaling had minimized the size of that error so the results looked reasonable, but were incorrect. Once I corrected the final step the calculated centroids are again correct.

    The math now matches what was always used, with the addition of scaling the XY values to the range [0.0,1.0] to avoid floating point issues with very large values. I have placed new builds with the latest changes at http://data.bluemarblegeo.com/downloads/global-mapper/dailybuilds/ for you to try.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • hgleixner
    hgleixner Global Mapper User Trusted User
    Mike,
    thanks. Now we get the same results at least in that case. (May be slight differences in large polygons.)
    Henry