如何在geoTools中使用GeometricShapeFactory在地图上创建圆 [英] How to use GeometricShapeFactory in geoTools to create a Circle on map

查看:1229
本文介绍了如何在geoTools中使用GeometricShapeFactory在地图上创建圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用以下代码创建GeoJson多边形.这给了我一个不好的圈子,这是无效的...

I am currently using the below code to create a GeoJson Polygon. this gives me a bad circle which is not valid...

在这种情况下为RADIUS = 1609.34,即1英里(米).

in this case RADIUS = 1609.34 , which is 1 mile in meters.

        public  GeoJsonPolygon createRadiusPolygon(  Point point,double RADIUS) {       

              GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
              shapeFactory.setNumPoints(32);
              shapeFactory.setCentre(new com.vividsolutions.jts.geom.Coordinate(point.getX(), point.getY()));
              shapeFactory.setSize(RADIUS * 2);
              com.vividsolutions.jts.geom.Geometry circle = shapeFactory.createCircle();
              List<Point> points = new ArrayList<Point>();
                for (com.vividsolutions.jts.geom.Coordinate coordinate : circle.getCoordinates()) {
                    Point lngLatAtl = new Point(coordinate.x, coordinate.y);
                    points.add(lngLatAtl);
                }
                Collections.reverse(points);
                return new GeoJsonPolygon(points);
            }

已引用: http://docs.geotools.org/stable/userguide/library/jts/geometry.html

当前,如果我使用Point(-73.87,40.84)RADIUS = 1609.34,我将获得以下链接. https://gist.githubuserf1e7c4e5c1e7c4e5c1e7c7e7e4e1e7c7e7e5e1c7e5e1c7e7e5e1e7c7e7e5e1e7c7e7e5e1e7c7e7e5e7e1e7e5e1e7e5e1e7e5e1e7e5e1e7e1e7e1e6e8c5e7e1e7e4e1c7e7e5c1e7e7bfbfffc圈

currently if i use Point(-73.87,40.84) RADIUS = 1609.34, i get the below link. https://gist.githubusercontent.com/VanitySoft/56c4ce0f5c1c7e7fe0461ed46fd5ed11/raw/94544750a140d81780ebe9206395a21ab88bb1f7/circle

===已解决==来自@Ian答案: 在他的答案中使用方法. RADIUS以英里为单位,以使Circle可以用于创建GeoJson.

===SOLVED== from @Ian answer: Using method in his answer. RADIUS is in miles, to get the Circle used to create the GeoJson.

...
  com.vividsolutions.jts.geom.Point jtsPoint =  new GeometryFactory().createPoint(new com.vividsolutions.jts.geom.Coordinate(point.getY(), point.getX()));
                  javax.measure.Measure measure = Measure.valueOf(RADIUS, NonSI.MILE);
                  com.vividsolutions.jts.geom.Geometry circle = createCircleRadis(measure,CRS.decode("epsg:4326"),jtsPoint );
...

...

推荐答案

您的输出圆是有效的,它恰好超过了地球表面的直径,因此您的GIS可能无法绘制它!问题是您在乱七八糟地混合度和米,而GeoTools却不知道要做什么.

Your output circle is valid, it just happens to exceed the diameter of the Earth's surface so your GIS may have issues drawing it! The problem is that you are mixing degrees and meters indiscriminately and GeoTools has no clue what you want it to do.

您需要在程序中添加有关该点的坐标参考系统的一些信息,并且如果该投影是地理投影(即度),则将问题转换为以米为单位的投影.

You need to add some information about the coordinate reference system of the point to the program, and if that projection is geographic (i.e. in degrees), transform the problem to a projection that is in meters.

public Geometry bufferPoint(Measure<Double, Length> distance, CoordinateReferenceSystem origCRS, Geometry geom) {
    Geometry pGeom = geom;
    MathTransform toTransform, fromTransform = null;
    // reproject the geometry to a local projection
    Unit<Length> unit = distance.getUnit();
    if (!(origCRS instanceof ProjectedCRS)) {

      double x = geom.getCoordinate().x;
      double y = geom.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);
        unit = SI.METER;
      } catch (MismatchedDimensionException | TransformException | FactoryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } else {
      unit = (Unit<Length>) origCRS.getCoordinateSystem().getAxis(0).getUnit();

    }


    // buffer
    Geometry out = pGeom.buffer(distance.doubleValue(unit));
    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 retGeom;
  }

AUTO:42001,x,y是一个特殊的投影,以米为中心的x,y点,使我们可以使用JTS

AUTO:42001,x,y is a special projection centred on the point x,y in meters that allows us to use the JTS buffer method which is easier than the circle operation you are using.

对于您的输入,这使我在纽约上空出现椭圆形,请注意,这是预料之中的,这是由于在弯曲地球上使用未投影的纬度/经度坐标会产生扭曲效果.

For your inputs this gives me an ellipse over New York, note this is expected and is due to the distorting effects of using unprojected Lat/Lon coordinates on a curved Earth.

您可以使用以下方式调用它:

You can call it using:

//Measure<Double, Length> dist = Measure.valueOf(50.0, SI.KILOMETER);
Measure<Double, Length> dist = Measure.valueOf(1.0, NonSI.MILE);
GeometryFactory gf = new GeometryFactory();
Point p = gf.createPoint(new Coordinate(-73.87,40.84));
buf.bufferPoint(dist, DefaultGeographicCRS.WGS84, p);

这篇关于如何在geoTools中使用GeometricShapeFactory在地图上创建圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆