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

    <legend id='LmUxu'><style id='LmUxu'><dir id='LmUxu'><q id='LmUxu'></q></dir></style></legend>

        <small id='LmUxu'></small><noframes id='LmUxu'>

        <tfoot id='LmUxu'></tfoot>
        • <bdo id='LmUxu'></bdo><ul id='LmUxu'></ul>

        使用JAVA中的geotools从定义距离(km)内的线(GPS坐标

        时间:2023-09-30

          <small id='M6SMu'></small><noframes id='M6SMu'>

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

            • <bdo id='M6SMu'></bdo><ul id='M6SMu'></ul>

                  <tbody id='M6SMu'></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坐标)生成多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 MaxMind 的 GeoIP 数据库来确定位置? 下一篇:如何使用 jdbc 中的 ResultSet.getBinaryStream() 从所有列

                  相关文章

                  最新文章

                  1. <small id='nrcyQ'></small><noframes id='nrcyQ'>

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

                      • <bdo id='nrcyQ'></bdo><ul id='nrcyQ'></ul>

                      <legend id='nrcyQ'><style id='nrcyQ'><dir id='nrcyQ'><q id='nrcyQ'></q></dir></style></legend>