Hello all,
I have a question about SQL Server and Geography functions. I'm looking to get the Centroid of a specific shape within a KML file.
Here's my little query
DECLARE @h VARCHAR(MAX);
set @h = 'SELECT [Id]
,[Name]
,[placemark_sd_id]
,[ACC]
,[EXS]
,[NAM]
,[TXT]
,[UID_1]
,[placemark]
FROM [dbKMLTemp].[dbo].[myTable]
where [NAM] = "G";'
DECLARE @g geometry;
SET @g = geometry::STGeomFromText (@h,0)
select @g.STCentroid().ToString();
I get this error.
Msg 6522, Level 16, State 1, Line 6
A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":
System.FormatException: 24114: The label SELECT [Id],[Name],[ in the input well-known text (WKT) is not valid. Valid labels are POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON and FULLGLOBE (geography Data Type only).
System.FormatException:
at Microsoft.SqlServer.Types.OpenGisTypes.ParseLabel(String input)
at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid)
What I'm trying to do is take the following query but where it says POLYGON I want to get the polygon from a select statement:
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g.STCentroid().ToString();
I got this from
https://docs.microsoft.com/en-us/sql/t-sql/spatial-geometry/stcentroid-geometry-data-type
How do I merge the two? I have a polygon from the KML file and now I need to find the center of it.
Thanks
Mike
What I have tried:
Look at my code in the question.