开发者

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

开发者 https://www.devze.com 2023-03-16 22:54 出处:网络
We can create a LineString using coordinates list like开发者_Go百科 this: Geometry g1 = new GeometryFactory().createLineString(coordinates);

We can create a LineString using coordinates list like开发者_Go百科 this:

     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:

// 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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消