簡體   English   中英

當我們有坐標列表時如何在 JTS 中創建多邊形?

[英]How to create a polygon in JTS when we have list of coordinate?

我們可以使用坐標列表創建一個 LineString,如下所示:

     Geometry g1 = new GeometryFactory().createLineString(coordinates);

我們如何使用坐標列表創建多邊形?

提前致謝。

在2012年,接受的答案可能仍然有效(仍然很尷尬),但現在你真的應該這樣做:

// Create a GeometryFactory if you don't have one already
GeometryFactory geometryFactory = new GeometryFactory();

// Simply pass an array of Coordinate or a CoordinateSequence to its method
Polygon polygonFromCoordinates = geometryFactory.createPolygon(coordinates);

使用以下代碼行:

 GeometryFactory fact = new GeometryFactory();
 LinearRing linear = new GeometryFactory().createLinearRing(coordinates);
 Polygon poly = new Polygon(linear, null, fact);

我希望它會有所幫助:)

你看過他們的文件嗎? 看看 - http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Polygon.html

我認為這非常直截了當。 我希望這能解決你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM