2016-04-06 8 views
3

バッファーの周囲にバウンディングボックス(四角形)を生成するJava関数が必要です。バッファーは、中心点(WGS84座標)と半径(メートル単位)で定義されます。 JTSのバッファのためのバウンディングボックスを取得Geotools:wgs84のバッファーのバウンディングボックス

は非常に簡単であるように思わ:

Point center = .... 
Geometry boundingBox = center.buffer(...).getEnvelope(); 

これが純粋な平面形状です。距離をメートルで指定した座標参照システムを使用してこれを行う方法はありますか?

最適Geotoolsが、他のJavaソリューションも動作すると...

答えて

1

私は手動で箱の角を見つけるために、GeodeticCalculatorを使用して終了。率直に言って結果は非常に正確ではありませんが、それは私が今までに見つかった最適なソリューションです:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); 
CoordinateReferenceSystem wgs84 = DefaultGeographicCRS.WGS84; 
GeodeticCalculator geodeticCalculator = new GeodeticCalculator(wgs84); 
geodeticCalculator.setStartingGeographicPoint(center.getX(), center.getY()); 
Coordinate[] coordinates = new Coordinate[5]; 
for (int i = 0; i < 4; i++) { 
    geodeticCalculator.setDirection(-180 + i * 90 + 45, bufferRadiusMeters * Math.sqrt(2)); 
    Point2D point2D = geodeticCalculator.getDestinationGeographicPoint(); 
    coordinates[i] = new Coordinate(point2D.getX(), point2D.getY()); 
} 
coordinates[4] = coordinates[0]; 
Polygon box = geometryFactory.createPolygon(coordinates); 
1

あなたが別の方法でそれに近づいているが、私は、そのための別の解決策を持っています。結果は提案されたソリューションよりも正確になります。

GeometryFactory GEOMETRY_FACTORY = JTSFactoryFinder.getGeometryFactory(); 

// Remember, order is (longitude, latitude) 
Coordinate center = Coordinate(2.29443, 48.85816); 
Point point = GEOMETRY_FACTORY.createPoint(center); 

// Buffer 50KM around the point, then get the envelope 
Envelope envelopeInternal = buffer(point, 50000).getEnvelopeInternal(); 

// Then you can play with the envelope, e.g., 
double minX = envelopeInternal.getMinX(); 
double maxX = envelopeInternal.getMaxX(); 

// The buffer using distanceInMeters 
private Geometry buffer(Geometry geometry, double distanceInMeters) throws FactoryException, TransformException { 
    String code = "AUTO:42001," + geometry.getCentroid().getCoordinate().x + "," + geometry.getCentroid().getCoordinate().y; 
    CoordinateReferenceSystem auto = CRS.decode(code); 

    MathTransform toTransform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, auto); 
    MathTransform fromTransform = CRS.findMathTransform(auto, DefaultGeographicCRS.WGS84); 

    Geometry pGeom = JTS.transform(geometry, toTransform); 
    Geometry pBufferedGeom = pGeom.buffer(distanceInMeters); 
    return JTS.transform(pBufferedGeom, fromTransform); 
} 

結果は、赤色のバッファ、黒色の封筒で表示されます。

Buffer and envelope

関連する問題