簡體   English   中英

如何使用OpenTripPlanner API獲取正確的凹面船體?

[英]How to get the correct Concave Hull using OpenTripPlanner API?

以下代碼沒有給我我期望的結果。 我希望所有點都作為多邊形的節點,並且多邊形包含所有點。 如何正確使用API​​? 同樣,如果我將閾值設置為小於1,則程序會陷入某種無限循環。

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.util.Set;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.opensphere.geometry.algorithm.ConcaveHull;


public class ConcaveHullTrial {

    public static void main(String args[]) {

        ConcaveHull cch = null;
        com.vividsolutions.jts.geom.Point point[] = new Point[5];
        Set<GeometryFactory> testing = JTSFactoryFinder.getGeometryFactories();
        for (GeometryFactory f : testing) {
            System.out.println(f);
        }
        GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
        point[0] = gf.createPoint(new Coordinate(0.0, 0.0));
        point[1] = gf.createPoint(new Coordinate(0.0, 2.0));
        point[2] = gf.createPoint(new Coordinate(2.0, 0.0));
        point[3] = gf.createPoint(new Coordinate(2.0, 2.0));
        point[4] = gf.createPoint(new Coordinate(1.8, 1.5));

        GeometryCollection gc = new GeometryCollection(point, gf);
        double threshold = 4;
        cch = new ConcaveHull(gc, threshold);
        Geometry hull = cch.getConcaveHull();
        for (int i = 0; i < 5; i++) {
            System.out.println(hull.covers(point[i]));
        }
        for (Coordinate c: hull.getCoordinates()) {
            System.out.println(c);
        }
    }
}

結果:

false
true
false
true
false
(0.0, 2.0, NaN)
(2.0, 2.0, NaN)

這對我來說可以。 我使用了ConcaveHull-0.2和geospark-1.1.3庫。 這是運行您的代碼后的結果:

com.vividsolutions.jts.geom.GeometryFactory@1e81f4dc true true true true true(0.0,0.0,NaN)(2.0,0.0,NaN)(2.0,2.0,NaN)(0.0,2.0,NaN)(0.0,0.0,NaN )

此外,它的工作閾值<1.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM