NetTopologySuite Geometry&WKT&WKB&GeoJSON互转

Posted Lulus

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于NetTopologySuite Geometry&WKT&WKB&GeoJSON互转的主要内容,如果未能解决你的问题,请参考以下文章

如何从 ASP.Net 核心中的 Json 文件中播种 NetTopologySuite.Geometries.Point 数据

hibernate 混合了vividsolutions.jts Geometry 和locationtech.jts.Geometry

Esri geometry api java 学习文档 几何图形 (Geometry)与数据结构

java程序操作Geometry对象

Java判断Geometry点是否在线Geometry LineString上

Java判断Geometry点是否在线Geometry LineString上