2017-05-12 10 views
1

ルートを定義する座標のセットから、任意の数のメートル幅(たとえば20)を指定すると、Geometryを描画してそのトラックの理論的なハイウェーを模倣します。GeoToolsジオメトリ "ルートセグメントからのセグメント"の構築

GeoToolsがそのような入力でGeometryを構築するためのツールを提供するかどうかわからないので、私の最初のアイデアは、(coord0, coord1)(coord1, coord2)、....、(coordN, coordN-1)のペアでトラック座標(数千)を分割し、 2つの点が(Knowing two points of a rectangle, how can I figure out the other two?のように)20m幅のセグメントの中間点であると仮定して、すべての結果としてgeometriesを結合すると仮定して矩形を構築します。

多分それはやり過ぎだけど、私はこの

を行うための安価な方法を発見していない任意のアイデアをいただければ幸いです!

答えて

1

これを行う簡単な方法は、ポイントから作成された線の周りに20mのバッファを使用することです。だから、ポイント(からのラインを作成するには、このようないくつかのコード:

String[] wkt = { 
    "Point (-0.13666168754467312 50.81919869153657743)", 
    "Point (-0.13622277073931291 50.82205165077141373)", 
    "Point (-0.13545466632993253 50.82512406840893959)", 
    "Point (-0.13457683271921211 50.82687973563037787)", 
    "Point (-0.13413791591385191 50.82907431965718104)", 
    "Point (-0.13951464677951447 50.8294035072611976)", 
    "Point (-0.14346489802775639 50.83082998687861931)", 
    "Point (-0.14697623247063807 50.83072025767727808)", 
    "Point (-0.15004865010815954 50.83390240451614517)", 
    "Point (-0.15740050659794308 50.8349996965295432)", 
    "Point (-0.16486209228906662 50.83741373895902171)", 
    "Point (-0.17276259478555042 50.83894994777778464)", 
    "Point (-0.18549118214099652 50.8387304893751022)" 
    }; 

    //build line 
    WKTReader2 reader = new WKTReader2(); 
    GeometryFactory gf = new GeometryFactory(); 
    Coordinate[] points = new Coordinate[wkt.length]; 
    int i=0; 
    for(String w:wkt) { 
     Point p; 
    try { 
    p = (Point) reader.read(w); 
    points[i++]=p.getCoordinate(); 
    } catch (ParseException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 

    } 
    LineString line = gf.createLineString(points); 
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema); 
    builder.set("locations", line); 
    SimpleFeature feature = builder.buildFeature("1"); 

そして同様BufferLine方法:

public SimpleFeature bufferFeature(SimpleFeature feature, Measure<Double, Length> distance) { 
    // extract the geometry 
    GeometryAttribute gProp = feature.getDefaultGeometryProperty(); 
    CoordinateReferenceSystem origCRS = gProp.getDescriptor().getCoordinateReferenceSystem(); 

    Geometry geom = (Geometry) feature.getDefaultGeometry(); 
    Geometry pGeom = geom; 
    MathTransform toTransform, fromTransform = null; 
    // reproject the geometry to a local projection 
    if (!(origCRS instanceof ProjectedCRS)) { 

     Point c = geom.getCentroid(); 
     double x = c.getCoordinate().x; 
     double y = c.getCoordinate().y; 

     String code = "AUTO:42001," + x + "," + y; 
     // System.out.println(code); 
     CoordinateReferenceSystem auto; 
     try { 
      auto = CRS.decode(code); 
      toTransform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, auto); 
      fromTransform = CRS.findMathTransform(auto, DefaultGeographicCRS.WGS84); 
      pGeom = JTS.transform(geom, toTransform); 
     } catch (MismatchedDimensionException | TransformException | FactoryException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

    } 

    // buffer 
    Geometry out = buffer(pGeom, distance.doubleValue(SI.METER)); 
    Geometry retGeom = out; 
    // reproject the geometry to the original projection 
    if (!(origCRS instanceof ProjectedCRS)) { 
     try { 
      retGeom = JTS.transform(out, fromTransform); 
     } catch (MismatchedDimensionException | TransformException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
    // return a new feature containing the geom 
    SimpleFeatureType schema = feature.getFeatureType(); 
    SimpleFeatureTypeBuilder ftBuilder = new SimpleFeatureTypeBuilder(); 
    ftBuilder.setCRS(origCRS); 
    // ftBuilder.setDefaultGeometry("buffer"); 
    ftBuilder.addAll(schema.getAttributeDescriptors()); 
    ftBuilder.setName(schema.getName()); 

    SimpleFeatureType nSchema = ftBuilder.buildFeatureType(); 
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(nSchema); 
    List<Object> atts = feature.getAttributes(); 
    for (int i = 0; i < atts.size(); i++) { 
     if (atts.get(i) instanceof Geometry) { 
      atts.set(i, retGeom); 
     } 
    } 
    SimpleFeature nFeature = builder.buildFeature(null, atts.toArray()); 
    return nFeature; 
} 

/** 
* create a buffer around the geometry, assumes the geometry is in the same 
* units as the distance variable. 
* 
* @param geom 
*   a projected geometry. 
* @param dist 
*   a distance for the buffer in the same units as the projection. 
* @return 
*/ 
private Geometry buffer(Geometry geom, double dist) { 

    Geometry buffer = geom.buffer(dist); 

    return buffer; 

} 

あなたが使用できるようにトリッキーな部分が局部的にフラットCRSに再投影されますバッファサイズのメーターローカルで良い投影を知っている場合は、あなただけ(このケースでは、我々はOSGB(EPSG使用することもできます:より良い結果のために27700を))ことを使用することができます。。

これは、次のマップを与える:

enter image description here

+0

それは完全に動作しました、ありがとうございます! – jonayreyes

関連する問題