1

I have several spatial layers created in QGIS that are held as spatial data in SQL Server 2008 R2. What I want to do is to find the centroid (OS Easting and Northing) of the polygon from the geometry. But I want to do this in a view that I have of the data. Each table I want to do this on, has a Geometry field. I've looked at examples of using ST.Centroid, but none of them seem to use a geometry field from a table.

Help on this will be invaluable.

Reelu
  • 7
  • 4
PTrodd
  • 33
  • 2
  • 5
  • Is your data in Geometry or Geography types? http://gis.stackexchange.com/questions/21108/create-a-geography-geometry-column-from-x-and-y-fields-sql-server-2008 – Mapperz Oct 13 '15 at 13:55

1 Answers1

3

In SQL Server 2008 R2, you should be able to use spatial function: STCentroid

If you have a geometry column (i.e. called geom) stored in the myTable, you can do the following:

select geom.STCentroid() from myTable

To create a view:

CREATE VIEW dbo.View1
  AS
    SELECT     geom, geom.STCentroid() AS CentroidPoint, geom.STCentroid().STAsText() AS Centroid
    FROM       dbo.myTable
GO
Matej
  • 1,758
  • 1
  • 13
  • 20