使用几何数据类型和 WKT 在 SQL Server 中存储 3D 形状

发布于 2024-11-09 07:35:10 字数 99 浏览 7 评论 0原文

我正在查看 Sql Server 2008 中的几何数据类型,它看起来很有趣,但文档似乎不太好。我可以以 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 traditionally have a radius and not hundreds of points.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

优雅的叶子 2024-11-16 07:35:11

据我所知,您将不得不使用外部应用程序将形状渲染为大量点。请参阅此博客了解渲染圆圈的技术。

可以考虑的一种可能性是使用 CLR 过程来渲染所需的形状和带有索引的视图。我不知道它会表现得如何,但它可能会起作用。

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.

凑诗 2024-11-16 07:35:11

抱歉回复晚了。您始终可以编写自己的用户定义类型,称为,具有两个属性,即质心 >半径

在新形成的 UDT 中,创建一个采用属性 Centroid (Point3D) 和 Radius (Double) 的方法。之后,创建一个使用 SqlGeometrySqlGeometryBuilder 来构建新形成的对象的方法。

首先,创建一个GeometryPoint实例。从类对象继承 Centroid 值,然后创建另一个从 Point 对象派生的 Geometry PolygonSTBuffer强>(半径)它。

下面是我的示例:(用 30 分钟编写)

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;
    }

当您在 VS2010 中使用 CLR 项目类型完成此操作后,您可以将其部署到数据库。

在 SQL 中,您可以这样调用对象::Parse(XYZM,R)

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

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()
诗化ㄋ丶相逢 2024-11-16 07:35:11

快速浏览了一下,发现这个 MSDN 页面 空间样本。它涵盖了在 WKT、WKB 和 WKT 中输入数据的所有方法。 XML(GML) 以及以人类可读形式查看的函数。它还涵盖 MakeValid、STIsValid 和STSrid。

看起来有相当多的 SQL 示例可能对您有用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文