2017-07-26 186 views
0

我有座標的數組列表:從數組列表中創建多邊形點 - 座標序列?

List<Coordinate> coords; 

我想創建一個基於這些值的多邊形。

我想:

GeometryFactory geometryFactory = new GeometryFactory(); 
Polygon polyg = geometryFactory.createPolygon(coords); 

但它表明,它想的CoordinateSequence:

The method createPolygon(CoordinateSequence) in the type GeometryFactory is not applicable for the arguments (List<Coordinate>) 

如果我嘗試創建的CoordinateSequence它顯示的方法bucnh,我不知道如何繼續(或者無論如何需要序列)。

回答

1

您也可以使用一組點。

查看http://docs.geotools.org/stable/userguide/library/jts/geometry.html舉例。

下面是一些示例代碼:

ArrayList<Coordinate> points = new ArrayList<Coordinate>(); 
    points.add(new Coordinate(longitude, latitude)); 
    ... 
    points.add(new Coordinate(lon, lat)); 
    ... 
    //make sure to close the linear ring 
    points.add(new Coordinate(longitude, latitude)); 
    poly = geometryFactory.createPolygon((Coordinate[]) points.toArray(new Coordinate[] {})); 
    valid = poly.isValid(); 
+1

你的意思是使用'LinearRing'後首先從'List'轉換'coords'到'Array'並通過'holes'我們指的是多邊形內部的空白區域? ?謝謝! – George

+0

爲了找出一個點是否位於多邊形中,我可以簡單地使用'point.within(polygon)'? – George

+0

我認爲包含的是你想要的方法,或者實際上通常不是不相交的。 –