Java “建筑地理工具几何”;“段”;从路线坐标

Java “建筑地理工具几何”;“段”;从路线坐标,java,algorithm,geotools,Java,Algorithm,Geotools,从定义路线的一组坐标中,我想画一个几何图形,模拟该轨道的理论公路,给定任意数米宽(例如20米) 我不知道GeoTools是否提供了使用此类输入构建几何体的工具,因此我最初的想法是将轨道坐标(数千)成对拆分(coord0,coord1),(coord1,coord2),…,(coordN,coordN-1),每对,假设两点是20米宽线段(如中所示)的中点,并连接所有生成的几何图形,构建一个矩形 也许这太过分了,但我还没有找到一个更便宜的方法 任何想法都将不胜感激 最简单的方法是在从点创建的直线周围

从定义路线的一组坐标中,我想画一个
几何图形
,模拟该轨道的理论公路,给定任意数米宽(例如20米)

我不知道
GeoTools
是否提供了使用此类输入构建
几何体的工具,因此我最初的想法是将轨道坐标(数千)成对拆分
(coord0,coord1)
(coord1,coord2)
,…,
(coordN,coordN-1)
,每对,假设两点是20米宽线段(如中所示)的中点,并连接所有生成的
几何图形,构建一个矩形

也许这太过分了,但我还没有找到一个更便宜的方法


任何想法都将不胜感激

最简单的方法是在从点创建的直线周围使用20m缓冲区。因此,一些类似这样的代码可以从点(:

然后是缓冲线方法,如:

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;

}
公共SimpleFeature缓冲区功能(SimpleFeature功能,测量距离){ //提取几何体 GeometryAttribute gProp=feature.getDefaultGeometryProperty(); CoordinateReferenceSystem origCRS=gProp.getDescriptor().getCoordinateReferenceSystem(); 几何图形几何图形=(几何图形)特征。getDefaultGeometry(); 几何图形pGeom=几何图形; MathTransform-toTransform,fromTransform=null; //将几何体重新投影到局部投影 如果(!(项目CRS的原始CRS实例)){ 点c=geom.getCentroid(); double x=c.getCoordinate().x; 双y=c.getCoordinate().y; 字符串代码=“自动:42001,”+x+,“+y; //System.out.println(代码); 自动协调参考系统; 试一试{ 自动=CRS.解码(代码); toTransform=CRS.findMathTransform(defaultGeographics.WGS84,自动); fromTransform=CRS.findMathTransform(auto,defaultGeographics.WGS84); pGeom=JTS.变换(geom,toTransform); }捕获(不匹配的DimensionException | TransformException | FactoryException e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } } //缓冲区 几何输出=缓冲区(pGeom,距离.双值(SI.米)); 几何retGeom=输出; //将几何体重新投影到原始投影 如果(!(项目CRS的原始CRS实例)){ 试一试{ retGeom=JTS.transform(out,fromTransform); }捕获(不匹配的DimensionException | TransformException e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } } //返回包含几何图形的新特征 SimpleFeatureType架构=feature.getFeatureType(); SimpleFeatureTypeBuilder ftBuilder=新SimpleFeatureTypeBuilder(); ftBuilder.SETCR(原始GCR); //ftBuilder.setDefaultGeometry(“缓冲区”); ftBuilder.addAll(schema.getAttributeDescriptors()); ftBuilder.setName(schema.getName()); SimpleFeatureType nSchema=ftBuilder.buildFeatureType(); SimpleFeatureBuilder=新SimpleFeatureBuilder(nSchema); List atts=feature.getAttributes(); 对于(int i=0;i
棘手的部分是重新投影到局部平坦的CRS中,以便可以使用米作为缓冲区大小。如果您知道局部良好的投影,您可以使用它(在本例中,我们可以使用OSGB(EPSG:27700)以获得更好的结果)

这给出了以下地图:

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;

}