开发者

Storing 3d shapes in sql server using geometry data type and WKT

I'm looking at the geometry data type in Sql Server 2008 and it looks interesting but the documentation does not seem that good. Would I be able to store cones, cylinders and spheres in the WKT format? These features tr开发者_如何学Goaditionally have a radius and not hundreds of points.


To the best of my knowledge your are going to have to use an external application to render your shape as a large number of points. See this blog for a technique for rendering circles.

One possibility to consider is a CLR proc to render the shapes you need and a view with indexes. I don't know how well that will perform, but it just might work.


sorry for the late reply. You could always write your own User-Defined-Type called Circle, with two properties namely Centroid and Radius.

Inside the newly formed UDT, create a method that takes the properties Centroid (Point3D), and Radius (Double). After this, create a method that uses both SqlGeometry and SqlGeometryBuilder to build the newly formed object.

First, create a Point instance of Geometry. Inherit the Centroid values from the class object, then, create another Geometry Polygon that's derived from the Point object, and STBuffer(Radius) it.

Below is my example: (written in 30min)

public SqlGeometry ToSQLGeometry()
    {
        int srid = this.SRID; // i.e. 4326

        SqlGeometry geom = new SqlGeometry();
        SqlGeometryBuilder gb = new SqlGeometryBuilder();
        OpenGisGeometryType pt = OpenGisGeometryType.Point;

        gb.SetSrid(srid);

        gb.BeginGeometry(pt);
        gb.BeginFigure(this.Centroid.X, this.Centroid.Y, this.Centroid.Z, this.Centroid.M);
        gb.EndFigure();
        gb.EndGeometry();

        geom = gb.ConstructedGeometry;
        geom = geom.MakeValid(); // Optional for Point data

        SqlGeometry geomCircle = new SqlGeometry();
        geomCircle = geom.STBuffer(this.Radius);

        return geomCircle;
    }

When you've done this in VS2010 by using the CLR project type, you can deploy it to your database.

In SQL, you can call the object as such:: Parse(X Y Z M,R)

declare @c Circle
set @c = Circle::Parse('5 6 7 8,2')
select 'Circle', @c.ToString(), @c.ToSQLGeometry()


Had a quick look around and found this MSDN page on Spatial Samples. It covers all the Methods to enter data in WKT, WKB & XML(GML) as well as functions to view the in Human Readable form. It also covers MakeValid, STIsValid & STSrid.

There looks to be a fair few SQL examples that you may find useful

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜