如何使用Npgsql和OrmLite(使用postgresql,postgis,c#)定义“地理"类型 [英] How to define 'geography' type using Npgsql and OrmLite (using postgresql, postgis, c#)

查看:183
本文介绍了如何使用Npgsql和OrmLite(使用postgresql,postgis,c#)定义“地理"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#类模型中定义postgis的地理"类型,以便OrmLite可以轻松地将其传递给Postgresql,以便除了将空间数据保存到地理"列之外,还可以运行空间查询?

How do I define a postgis 'geography' type in my C# class model so that OrmLite can easily pass it through to Postgresql so I can run spatial queries in addition to saving spatial data to the 'geography' column?

推荐答案

最好的库是 NetTopologySuite 这种情况;

The best library is NetTopologySuite for this case;

您可以像这样使用

protected GisSharpBlog.NetTopologySuite.Geometries.Geometry _geom;
public GisSharpBlog.NetTopologySuite.Geometries.Geometry Geom
   {
      get { return _geom; }
      set { _geom = value; }
   }

protected string _geomwkt;
public virtual string GeomWKT
   {
     get
       {
         if (this.Geom != null)
             return this.Geom.ToText();
         else
             return "";
       }
     set
       {
         string wktString = value;
         if (string.IsNullOrEmpty(wktString))
             _geom = null;
         else
           {
             var fact = new GeometryFactory();
              var wktreader = new WKTReader(fact);
              _geom = (Geometry)wktreader.Read(wktString);
           }
        }
   }

这篇关于如何使用Npgsql和OrmLite(使用postgresql,postgis,c#)定义“地理"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆