NetTopologySuite Geometry&WKT&WKB&GeoJSON互转

送分小仙女□ 提交于 2020-04-23 13:11:00

WKT To WKB

private static byte[] ConvertWKTToWKB(string wkt)
{
	WKBWriter writer = new WKBWriter();
	WKTReader reader = new WKTReader();
	var wkb = writer.Write(reader.Read(wkt));
	return wkb;
}

WKB To WKT

private static string ConvertWKBToWKT(byte[] wkbBytes)
{
	WKBReader reader = new WKBReader();
	WKTWriter writer = new WKTWriter();
	var wktText = writer.Write(reader.Read(wkbBytes));
	return wktText;
}

WKT To Geometry

WKTReader reader = new WKTReader();
NetTopologySuite.Geometries.Geometry geom = reader.Read(WKTText);

GeoJSON To Geometry

//引用NetTopologySuite.IO.GeoJSON
//https://github.com/NetTopologySuite/NetTopologySuite.IO.GeoJSON
GeoJsonReader reader = new GeoJsonReader();
var geometry = reader.Read<NetTopologySuite.Geometries.Geometry>(geoJSONText);

WKB To Geometry

WKBReader reader = new WKBReader();
NetTopologySuite.Geometries.Geometry geom = reader.Read(wkbBytes);

示例代码

ConvertDataWindow

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