从点列表创建多边形的最佳方法是什么?
我有一个点数组,如果点至少是3个,我想加入创建一个多边形。
Dim ClickedPoint As New NetTopologySuite.Geometries.Point(coordinates)
ClickedPointArray.Add(ClickedPoint)
if ClickedPointArray.Count > 2 then
Polygonizer = New Polygonizer()
Polygonizer.Add(ClickedPointArray)
end if
return Polygonizer.GetPolygons我觉得我离解决方案还很远。你能帮我一下吗?
发布于 2018-05-17 12:02:18
您可以使用GeometryFactory创建具有坐标数组的多边形,如下所示:
Dim coordinatesArray as Coordinate[] = YourMethodToGetCoordinates
Dim geomFactory As New GeometryFactory
Dim poly As geomFactory.CreatePolygon(coordinatesArray) //this returns an IPolygon that you can cast to Polygon发布于 2021-09-09 17:31:31
这是C#
Coordinate[] imageOutlineCoordinates = new Coordinate[] { new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(2, 2), new Coordinate(1, 1) }; GeometryFactory geometryFactory = new GeometryFactory(); Polygon poly = geometryFactory.CreatePolygon(imageOutlineCoordinates);
发布于 2022-03-08 15:01:04
下面是使用网络拓扑套件(https://github.com/NetTopologySuite/NetTopologySuite)实现https://github.com/NetTopologySuite/NetTopologySuite的解决方案
Polygon GetGeometry(Coordinate[] coordinates)
{
var geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
var polygon = new Polygon(new LinearRing(coordinates), geometryFactory);
return polygon;
}注:此处4326为无坐标系。没有这个几何运算,就不能给出正确的结果。
var coordinates = new List<Coordinate>();
for (var index = 0; index < doubleList.Count; index = index + 2)
{
var coordinate = new Coordinate(doubleList[index], doubleList[index + 1]);
coordinates.Add(coordinate);
}
coordinates.Add(new Coordinate(points[0], points[1]));
GetGeometry(coordinates.ToArray())https://stackoverflow.com/questions/32838720
复制相似问题