user779625
user779625

Reputation: 85

Retrieve a polygon Geometry object(Microsoft.SqlServer.Types) and get the information about the coordinates

I'm facing a problem about handling a geometry object retrieved form a spatial database in sql server 10.

I've created a database which got 2 geometry objects (polygons) in it :{POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))}

After a creating a connection with the database(using asp.net) I retrieve the geometry object with the command:

SqlGeometry obj = (SqlGeometry)dataset.Tables[0].Rows[0][1];

This is all working fine, my obj got the polygon in it, but most of the attributes (e.g. STX,STY) are null, but my object got the value "{POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))}" and is a Microsoft.SqlServer.Types type...

Why are these attributes null? I think that the attributes STX and STY aren't enough to describe a polygon's coordinates(based on his 5 points to creating it).

Thanks in advance!

Upvotes: 2

Views: 1101

Answers (1)

steenhulthin
steenhulthin

Reputation: 4773

From msdn:

STX Gets the X-coordinate property of a Point instance.
STY Gets the Y-coordinate property of a Point instance.

A polygon is not a Point instance. If you want to use the centroid of the polygon use:

STCentroid  Returns the geometric center of a SqlGeometry instance 
            consisting of one or more polygons.

The STCentroid should have STX and STY.

Upvotes: 1

Related Questions