Centroids wrong computated  twice
hgleixner
Global Mapper UserTrusted User
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
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

Hello,
until now I got no answer. Very sad!
Henry

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 email 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. 
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/globalmapper/dailybuilds/ for you to try.
Thanks,
Mike
Global Mapper Guru
geohelp@bluemarblegeo.com
http://www.bluemarblegeo.com/

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

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.)

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/

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

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/

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.

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

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 roundoff 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/globalmapper/dailybuilds/ for you to try.
Thanks,
Mike
Global Mapper Guru
geohelp@bluemarblegeo.com
http://www.bluemarblegeo.com/

Mike,
thanks. Now we get the same results at least in that case. (May be slight differences in large polygons.)
Henry
Categories
 12.7K All Categories
 5.6K Features Discussion
 343 Downloading Imagery
 1.3K Elevation Data
 381 Georeferencing Imagery Discussion
 630 GM Script Language
 53 User Scripts
 114 GPS Features
 414 Projection Questions
 820 Raster Data
 1.3K Vector Data
 6.6K Support
 177 Announcement and News
 908 Bug Report
 558 SDK
 1.2K Suggestion Box
 3.7K Technical Support
 563 Other Discussion
 130 GIS Data Sources
 27 Global Mapper Showcase
 233 How I use Global Mapper
 107 Global Mapper Forum Website