I'm drawing regions (using SqlGeometry
/SqlGeography
and translating them to the WPF LocationCollection
equivalent) on the Bing Maps WPF Control and needed to label them. I got the labels drawn on the regions and attached them to the point found by STCentroid()
. Of course as you imagine this is a problem with the 'U' or 'C' shaped regions where the centroid ends up outside the region, which makes the label incorrect.
Is there a way using SqlGeometry
/SqlGeography
to find the "visual" center or perhaps find the largest circle that can fit in the shape and use that center? I've tried various methods using STPointOnSurface()
but it seems that STPointOnSurface()
always picks a point on the edge like so DCREHA (the label for the bottom dark green region always ends up on the edges:
Spatial data represents information about the physical location and shape of geometric objects. These objects can be point locations or more complex objects such as countries, roads, or lakes. SQL Server supports two spatial data types: the geometry data type and the geography data type.
SQL Server Change Tracking, also known as CT, is a lightweight tracking mechanism, introduced the first time in SQL Server 2008, that can be used to track the DML changes performed in SQL Server database tables. SQL Change Tracking can be configured in all SQL Server editions, including the free Express edition.
The planar spatial data type, geometry, is implemented as a common language runtime (CLR) data type in SQL Server. This type represents data in a Euclidean (flat) coordinate system. SQL Server supports a set of methods for the geometry spatial data type.
MySQL has spatial data types that correspond to OpenGIS classes. The basis for these types is described in Section 11.4. 2, “The OpenGIS Geometry Model”.
An almost identical question has already been asked here. In your case, the most relevant answer is probably this one. The hard part of that answer is determining where to draw the line that splits the polygon into two equal areas. Therefore, I propose a slightly modified version below for SQL Server:
STCentroid
to find the centre of massSTWithin
), then no need to process further; otherwise:STEnvelope
to get the polygon's envelope and pass that as the argument to STCentroid
)STWithin
), it may be good enough (would need testing); otherwise:STIntersection
)For instance, given the polygon for the DCREHA example above, the following GIF animates the procedure listed above (judged by eye - actual result will differ):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With