<bdo id='63bly'></bdo><ul id='63bly'></ul>
  1. <legend id='63bly'><style id='63bly'><dir id='63bly'><q id='63bly'></q></dir></style></legend>

    <tfoot id='63bly'></tfoot>

    1. <i id='63bly'><tr id='63bly'><dt id='63bly'><q id='63bly'><span id='63bly'><b id='63bly'><form id='63bly'><ins id='63bly'></ins><ul id='63bly'></ul><sub id='63bly'></sub></form><legend id='63bly'></legend><bdo id='63bly'><pre id='63bly'><center id='63bly'></center></pre></bdo></b><th id='63bly'></th></span></q></dt></tr></i><div id='63bly'><tfoot id='63bly'></tfoot><dl id='63bly'><fieldset id='63bly'></fieldset></dl></div>

      <small id='63bly'></small><noframes id='63bly'>

      使用JAVA中的geotools从定义距离(km)内的线(GPS坐标)生成多边形

      Generate a polygon from a line(GPS coordinate) in a defined distance(km) with geotools in JAVA(使用JAVA中的geotools从定义距离(km)内的线(GPS坐标)生成多边形)
    2. <i id='lZf9P'><tr id='lZf9P'><dt id='lZf9P'><q id='lZf9P'><span id='lZf9P'><b id='lZf9P'><form id='lZf9P'><ins id='lZf9P'></ins><ul id='lZf9P'></ul><sub id='lZf9P'></sub></form><legend id='lZf9P'></legend><bdo id='lZf9P'><pre id='lZf9P'><center id='lZf9P'></center></pre></bdo></b><th id='lZf9P'></th></span></q></dt></tr></i><div id='lZf9P'><tfoot id='lZf9P'></tfoot><dl id='lZf9P'><fieldset id='lZf9P'></fieldset></dl></div>
    3. <small id='lZf9P'></small><noframes id='lZf9P'>

        <legend id='lZf9P'><style id='lZf9P'><dir id='lZf9P'><q id='lZf9P'></q></dir></style></legend>
            • <bdo id='lZf9P'></bdo><ul id='lZf9P'></ul>
              <tfoot id='lZf9P'></tfoot>
                <tbody id='lZf9P'></tbody>
                本文介绍了使用JAVA中的geotools从定义距离(km)内的线(GPS坐标)生成多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                使用 geotools 是否有可能从定义距离内的线 (coords[]) 生成多边形?例如.(100,100), (101,100), (102,100) 距离 1 公里.所以从每一点它生成一个圆圈并变成某事.喜欢:

                With geotools would it be possible that generating a polygon from a line (coords[]) in a defined distance? E.g. (100,100), (101,100), (102,100) with distance 1km. So from each point it generates a circle and becomes sth. like:

                -------------之前

                -------------- before

                (========) 之后

                (========) after

                或者我必须先将 GPS 坐标转换为以 km 为单位的正交坐标,然后使用三角函数生成多边形,最后再将其转换回 GPS?

                Or I have to firstly convert GPS coordinates into orthogonal coordinates in km, and then generating a polygon using Trigonometric functions, and finally, convert it back into GPS?

                推荐答案

                最简单的方法是调用底层 JTS 几何的 buffer(distance) 方法.棘手的一点是处理与以米为单位的投影之间的重投影(因此您可以以米或公里为单位指定缓冲区).

                At it's simplest you simply need to call the buffer(distance) method on the underlying JTS geometry. The tricky bit is handling the reprojection to and from a projection which is in meters (so you can specify your buffer in meters or kilometers).

                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;
                    }
                

                完整代码在 https://gist.github.com/ianturton/9a7cfee378e7072ec3cd这显示了如何处理整个事情.

                The full code is at https://gist.github.com/ianturton/9a7cfee378e7072ec3cd which shows how to handle the whole thing.

                这篇关于使用JAVA中的geotools从定义距离(km)内的线(GPS坐标)生成多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                How to convert Integer to int?(如何将整数转换为整数?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                Inconsistent behavior on java#39;s ==(java的行为不一致==)
                Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                <i id='3X45V'><tr id='3X45V'><dt id='3X45V'><q id='3X45V'><span id='3X45V'><b id='3X45V'><form id='3X45V'><ins id='3X45V'></ins><ul id='3X45V'></ul><sub id='3X45V'></sub></form><legend id='3X45V'></legend><bdo id='3X45V'><pre id='3X45V'><center id='3X45V'></center></pre></bdo></b><th id='3X45V'></th></span></q></dt></tr></i><div id='3X45V'><tfoot id='3X45V'></tfoot><dl id='3X45V'><fieldset id='3X45V'></fieldset></dl></div>
              • <legend id='3X45V'><style id='3X45V'><dir id='3X45V'><q id='3X45V'></q></dir></style></legend>

                1. <tfoot id='3X45V'></tfoot>
                    • <bdo id='3X45V'></bdo><ul id='3X45V'></ul>

                      <small id='3X45V'></small><noframes id='3X45V'>

                            <tbody id='3X45V'></tbody>