简体   繁体   English

当我们有坐标列表时如何在 JTS 中创建多边形?

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

We can create a LineString using coordinates list like this:我们可以使用坐标列表创建一个 LineString,如下所示:

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

How can we create a polygon using coordinates list?我们如何使用坐标列表创建多边形?

Thanks in advance.提前致谢。

The accepted answer might have still been valid (still awkward) in 2012 but nowadays you should really do it simply like this: 在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);

Use these line of codes: 使用以下代码行:

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

I hope it will help :) 我希望它会有所帮助:)

Have you seen their documentation ? 你看过他们的文件吗? Take a look - http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Polygon.html 看看 - http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Polygon.html

I think this is very much straight forward. 我认为这非常直截了当。 I hope this will solve your problem. 我希望这能解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM