How to define 'geography' type using Npgsql and OrmLite (using postgresql, postgis, c#)

╄→гoц情女王★ 提交于 2019-12-21 12:03:03

问题


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?


回答1:


The best library is NetTopologySuite for this case;

you can use like this;

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


来源:https://stackoverflow.com/questions/17343946/how-to-define-geography-type-using-npgsql-and-ormlite-using-postgresql-postg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!