NetTopologySuite Geometry&WKT&WKB&GeoJSON互转

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

上一篇:【GAMES101-现代计算机图形学课程笔记】Lecture 10 Geometry 1 (介绍)


下一篇:超图SuperMap iObjects .NET Geometry转geoJSON&WKT&WKB