是否可以从 Sql Server 2008 以 gml2 格式导出空间数据?

发布于 2024-07-09 16:34:59 字数 125 浏览 10 评论 0原文

Sql Server 2008 支持具有新几何和地理 UDT 的空间数据。 它们都支持 AsGml() 方法来序列化 gml 格式的数据。 然而,它们将数据序列化为 GML3 格式。 有什么办法告诉它将数据序列化为GML2格式吗?

Sql Server 2008 supports spatial data with new geometry and geography UDT's. They both support AsGml() method to serialize data in gml format. However they serialize data into GML3 format. Is there any way to tell it to serialize data into GML2 format?

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

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

发布评论

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

评论(4

独孤求败 2024-07-16 16:34:59

AFAIK,没有内置功能可以将地理空间数据序列化为 GML 2.x。 您需要使用一些第三方工具,自己实现一个编写器,或者,这个建议听起来有点奇怪,使用 PostGIS< /a> 用于此转换。

PostGIS 是替代地理空间数据库,与 SQL Server 类似的解决方案,但对两种格式实现解/序列化:GML 2 和 GML 3

我建议使用 PostGIS 作为中间和翻译存储。

  1. 使用 SQL Server 函数将数据存储到 GML 3

  2. GML 3

    使用 PostGIS 函数加载序列化到 GML 3 的数据 ST_GeomFromGML

  3. 使用 ST_AsGML 允许您指定 GML 的目标版本: text ST_AsGML(integer version, Geometry g1);

提出另一个地理空间数据库可能听起来很奇怪,但我确信它会工作得相当顺利和良好。

AFAIK, there is no built-in feature to serialize geospatial data to GML 2.x. You need to use some third-party tools, implement a writer youserlf or, this suggestion may sound a bit strange, use PostGIS for this transition.

PostGIS is alternative geospatial database, similar solution to SQL Server, but implementing de-/serialization for both formats: GML 2 and GML 3.

What I'd suggest is to use PostGIS as an intermediate and translating storage.

  1. Store data to GML 3 using SQL Server functions

  2. Load data serialized to GML 3 using PostGIS function ST_GeomFromGML

  3. Store data from PostGIS to GML 2 format using ST_AsGML which allows you to specify target version of GML: text ST_AsGML(integer version, geometry g1);

It may sound strange to propose another geospatial database, but I'm sure it would work fairly smoothly and well.

浅浅 2024-07-16 16:34:59

不支持 GML2,但有可扩展 API 可用于实现自定义序列化。

以下是使用 SqlGeometry.Populate(IGeometrySink) 方法(C# 代码)进行自定义序列化的示例:

CustomWriter w = new CustomWriter();
SqlGeometry.Parse("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))").Populate(w);
System.Console.WriteLine(w);

public class CustomWriter : IGeometrySink {
    private StringBuilder _builder = new StringBuilder();

    public string ToString() {
        return _builder.ToString();
    }

    public void SetSrid(int srid) {
        _builder.Append('@');
        _builder.Append(srid);
    }

    public void BeginGeometry(OpenGisGeometryType type) {
        _builder.Append(" (");
        _builder.Append(type);
    }

    public void BeginFigure(double x, double y, double? z, double? m) {
        _builder.Append(" [");
        _builder.Append(x);
        _builder.Append(' ');
        _builder.Append(y);
    }

    public void AddLine(double x, double y, double? z, double? m) {
        _builder.Append(',');
        _builder.Append(x);
        _builder.Append(' ');
        _builder.Append(y);
    }

    public void EndFigure() {
        _builder.Append(']');
    }

    public void EndGeometry() {
        _builder.Append(')');
    }
}

要进行反序列化,请使用 SqlGeometryBuilder 类:

// Create "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))" using Builder API
SqlGeometryBuilder b = new SqlGeometryBuilder();
b.SetSrid(0);
b.BeginGeometry(OpenGisGeometryType.Polygon);
    b.BeginFigure(0, 0);
    b.AddLine(10, 0);
    b.AddLine(10, 10);
    b.AddLine(0, 10);
    b.AddLine(0, 0);
    b.EndFigure();
b.EndGeometry();
SqlGeometry g = b.ConstructedGeometry;

There is no support for GML2, but there is extensibility API that can be used to implement custom serialization.

Here is an example of custom serialization using SqlGeometry.Populate(IGeometrySink) method (C# code):

CustomWriter w = new CustomWriter();
SqlGeometry.Parse("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))").Populate(w);
System.Console.WriteLine(w);

public class CustomWriter : IGeometrySink {
    private StringBuilder _builder = new StringBuilder();

    public string ToString() {
        return _builder.ToString();
    }

    public void SetSrid(int srid) {
        _builder.Append('@');
        _builder.Append(srid);
    }

    public void BeginGeometry(OpenGisGeometryType type) {
        _builder.Append(" (");
        _builder.Append(type);
    }

    public void BeginFigure(double x, double y, double? z, double? m) {
        _builder.Append(" [");
        _builder.Append(x);
        _builder.Append(' ');
        _builder.Append(y);
    }

    public void AddLine(double x, double y, double? z, double? m) {
        _builder.Append(',');
        _builder.Append(x);
        _builder.Append(' ');
        _builder.Append(y);
    }

    public void EndFigure() {
        _builder.Append(']');
    }

    public void EndGeometry() {
        _builder.Append(')');
    }
}

To do deserialization use SqlGeometryBuilder class:

// Create "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))" using Builder API
SqlGeometryBuilder b = new SqlGeometryBuilder();
b.SetSrid(0);
b.BeginGeometry(OpenGisGeometryType.Polygon);
    b.BeginFigure(0, 0);
    b.AddLine(10, 0);
    b.AddLine(10, 10);
    b.AddLine(0, 10);
    b.AddLine(0, 0);
    b.EndFigure();
b.EndGeometry();
SqlGeometry g = b.ConstructedGeometry;
初熏 2024-07-16 16:34:59

正如Marko所说,Sql Server 2008中不支持gml2,所以我最终编写了一个函数,用于将服务器返回的gml3转换为我需要的gml2。

As Marko said, there is no support for gml2 in Sql Server 2008, so I just ended up writing a function for transforming gml3 returned by the server to gml2 that I needed.

第七度阳光i 2024-07-16 16:34:59

既然你已经完成了,那就没什么意义了,但我建议将 geoserver 放在 SQL Server 前面。 Geoserver 内置了几乎任何您想要的格式的所有序列化代码,安装起来很简单,并且按照广告宣传的那样工作。

http://docs.geoserver.org/2.0。 x/en/user/services/wfs/outputformats.html

Well since you finished there is not much point but I would recommend putting geoserver in front of SQL Server. Geoserver has all the serialization code built in for almost any format you want, is easy cheezy to install, and works as advertised.

http://docs.geoserver.org/2.0.x/en/user/services/wfs/outputformats.html

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