问题
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