计算大多边形和大线串之间的相交距离

时间:2020-02-23 02:47:20

标签: geotools

我有一个大的Polygon和LineLine,足以说明地球的曲率,我想计算两者之间的相交距离。我尝试使用自动投影,但仍然无法获得接近的结果。我已经遍历了Ian's blog来计算多边形的面积,因为JTS并未在GeodeticCalculator那里考虑地球的曲率,所以显然提到它仅适用于小多边形。我是否应该找到第一个和最后一个相交点,然后可以使用GeodeticCalculator来计算相交距离,或者有其他方法可以做到这一点,就像等面积投影一样?

    DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
    GeometryFactory geomFactory = new GeometryFactory();

    //my WGS 84 crs axis order is longitude first hence all coordinates are long,lat
    Coordinate[] polygonCoOrdinates = new Coordinate[]{new Coordinate(44.783323, -13.115134),
            new Coordinate(43.381886, -10.994365),
            new Coordinate(45.367769, -4.368934),
            new Coordinate(51.220897, 4.818909),
            new Coordinate(59.268949, 16.105438),
            new Coordinate(67.52604, 10.616453),
            new Coordinate(69.825484, 4.402182),
            new Coordinate(73.274649, -0.923968),
            new Coordinate(65.749198, -10.789091),
            new Coordinate(52.579659, -10.686401),
            new Coordinate(44.783323, -13.115134)
    };

    Coordinate[] lineStringCoordinates = new Coordinate[]{new Coordinate(72.8777, 19.0760),
            new Coordinate(31.049999, -29.883333)
    };

    LineString lineString = geomFactory.createLineString(lineStringCoordinates);

    LinearRing ring = geomFactory.createLinearRing(polygonCoOrdinates);

    org.locationtech.jts.geom.Polygon polygon = geomFactory.createPolygon(polygonCoOrdinates);

    Geometry geometryIntersection = polygon.intersection(lineString);
    Point centroid = polygon.getCentroid();
    String code = "AUTO:42001," + centroid.getX() + "," + centroid.getY();
    CoordinateReferenceSystem auto = CRS.decode(code);

    MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, auto);
    Geometry projgeometryIntersection = JTS.transform(geometryIntersection, transform);
    double areaa = projgeometryIntersection.getArea();

0 个答案:

没有答案
相关问题