Reputation: 85
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
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