I need to find a point that is a visual center of an irregularly shaped polygon. By visual center, I mean a point that appears to be in the center of a large area of the polygon visually. The application is to put a label inside the polygon.
Here is a solution that uses inside buffering:
If this is to be used, what is an effective and fast way to find the buffer? If any other way is to be used, which is that way?
A good example of really tough polygons is a giant thick U (written in Arial Black or Impact or some such font).
I have found a very good solution to this from MapBox called Polylabel. The full source is available on their Github too.
Essentially it tries to find the visual centre of the polygon as T Austin said.
Certain details suggest this may be a practical solution:
Unfortunately, calculating [the ideal solution ] is both complex and slow. The published solutions to the problem require either Constrained Delaunay Triangulation or computing a straight skeleton as preprocessing steps — both of which are slow and error-prone.
For our use case, we don’t need an exact solution — we’re willing to trade some precision to get more speed. When we’re placing a label on a map, it’s more important for it to be computed in milliseconds than to be mathematically perfect.
A quick note about usage though. The source code works great for Javascript out of the box however if you intend on using this with a "normal" polygon then you should wrap it in an empty array as the functions here take GeoJSONPolygons rather than normal polygons i.e.
var myPolygon = [[x1, y1], [x2, y2], [x3, y3]];
var center = polylabel([myPolygon]);