Assuming that this table has a table full of ordered lengths and lats:
CREATE TABLE [dbo].[LongAndLats]( [Longitude] [decimal](9, 6) NULL, [Latitude] [decimal](9, 6) NULL, [SortOrder] [int] NULL )
This converts these points to a polygon:
DECLARE @BuildString NVARCHAR(MAX) SELECT @BuildString = COALESCE(@BuildString + ',', '') + CAST([Longitude] AS NVARCHAR(50)) + ' ' + CAST([Latitude] AS NVARCHAR(50)) FROM dbo.LongAndLats ORDER BY SortOrder SET @BuildString = 'POLYGON((' + @BuildString + '))'; DECLARE @PolygonFromPoints geography = geography::STPolyFromText(@BuildString, 4326); SELECT @PolygonFromPoints
Some notes:
- The landfill must be closed. i.e. the first and last points must be the same.
- Must have a minimum of 4 points.
- The order of the items is important. He must follow the βleft arm / leg ruleβ (areas lying on the left side of the line drawn between the points are counted inside the polygon)
source share