如何使用Npgsql和OrmLite定义’geography’类型(使用postgresql,postgis,c#)

前端之家收集整理的这篇文章主要介绍了如何使用Npgsql和OrmLite定义’geography’类型(使用postgresql,postgis,c#)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在我的C#类模型中定义postgis’geography’类型,以便OrmLite可以轻松地将其传递给 Postgresql,这样我除了将空间数据保存到’geography’列之外还可以运行空间查询
对于这种情况,最好的图书馆是 NetTopologySuite;

你可以像这样使用;

  1. protected GisSharpBlog.NetTopologySuite.Geometries.Geometry _geom;
  2. public GisSharpBlog.NetTopologySuite.Geometries.Geometry Geom
  3. {
  4. get { return _geom; }
  5. set { _geom = value; }
  6. }
  7.  
  8. protected string _geomwkt;
  9. public virtual string GeomWKT
  10. {
  11. get
  12. {
  13. if (this.Geom != null)
  14. return this.Geom.ToText();
  15. else
  16. return "";
  17. }
  18. set
  19. {
  20. string wktString = value;
  21. if (string.IsNullOrEmpty(wktString))
  22. _geom = null;
  23. else
  24. {
  25. var fact = new GeometryFactory();
  26. var wktreader = new WKTReader(fact);
  27. _geom = (Geometry)wktreader.Read(wktString);
  28. }
  29. }
  30. }

猜你在找的Postgre SQL相关文章