2015-09-27 50 views
3

我有多邊形形狀,我想將其轉換爲MultiLineString。請注意,通常方向不同:從點,座標,線條等使用GeometryFactory構建多邊形。我開始思考GeometryTransformer但它是很難理解的文檔存在。所以我有這樣的:JTS:如何將多邊形轉換爲MultiLineString

import com.vividsolutions.jts.geom.*; 
... 
GeometryFactory gFactory = new GeometryFactory(); 
GeometryTransformer gTransform = new GeometryTransformer(); 
Polygon polygon = gFactory.createPolygon(someLinearRing, null); 
MultiLineString mlString = polygon.TODO? 

如何繼續在TODO

+0

你想提取多邊形的邊界?如果不是,請更好地解釋你的意思 –

+0

@TommasoDiBucchianico是的,多邊形是由線條構成的,並且所有線條構成一個多線串 – michael

回答

5

方法Polygon.getBoundary()計算多邊形的邊界。如果多邊形沒有孔(也只有一個邊界),則返回LinearRing類型的對象。 如果多邊形有孔 - 也有多個邊界 - 則返回MultiLineString類型的對象。

使用梅索德Polygon.getNumInteriorRing(),以檢查是否多邊形有洞,比建一個MULTILINESTRING是必要的:

GeometryFactory gFactory = new GeometryFactory(); 
if (polygon.getNumInteriorRing() == 0){ 
    // polygon has not holes, so extract the exterior ring 
    // and build a multilinestring 
    return gFactory.createMultiLineString(polygon.getExteriorRing()); 
} 

else{ 
    // Polygon has holes, also several boundaries. 
    // Simply run getBoundary(), it will return a multilinestring 
    return polygon.getBoundary(); 
} 
+0

Hello。相反是可能的嗎?將多線串轉換爲多邊形?謝謝。 – George