4

指定された半径のステップに従って、ルートの周りに複雑なポリゴンをプロットしようとしています。そのために、ルートの各ステップ (座標) の周りに 50 辺の均一なポリゴン (実際には円) を描きました。今、ルートの周りにプロットされたすべての円の座標のセットを取得し、地図上でそれらを見ることができますが、それらは重なっていて見栄えがよくありません.地図。

ここに画像の説明を入力

だから私が今しなければならないことは、私が今持っているすべてのポリゴンを1つのポリゴンにマージし、それをマップにプロットすることです.

2 つのポリゴンごとに交点を削除し (ポリゴン 1 のポイントがポリゴン 2 の内側にあるかどうかをテストし、その逆かどうかをテストします)、残りのすべての座標を 1 つの配列にマージしてから、新しいポリゴンを構築しようとしましたが、うまくいきませんでした。これが私がこれをどのように行っているかのコードスニペットです:

public ArrayList<PolygonOptions> polygons = new ArrayList<>();

// lineOptions is the set of route coordinates
    for (int i = 0; i < lineOptions.getPoints().size() - 1; i++) {
        // Draw a circle around each point of the route
        PolygonOptions circle1 = drawCircle(lineOptions.getPoints().get(i), 0.1);
        PolygonOptions circle2 = drawCircle(lineOptions.getPoints().get(i + 1), 0.1);
        // Draw a convex hull between every two successive circles
        PolygonOptions convexHull = convexHull(circle1, circle2);

        convexHull.strokeWidth(0);
        convexHull.fillColor(0x7F729E47);
        activity.range.add(activity.mMap.addPolygon(convexHull));
        polygons.add(convexHull);
    }


if (polygons.size() == 1) {
        pts.addAll(polygons.get(0).getPoints());
    } else {
        for (int i = 0; i < polygons.size() - 1; i++) {
            ArrayList<LatLng> pts1 = new ArrayList<>();
            ArrayList<LatLng> pts2 = new ArrayList<>();
            pts1.addAll(polygons.get(i).getPoints());
            pts2.addAll(polygons.get(i + 1).getPoints());

            for (int j = 0; j < pts1.size(); j++) {
                if (pointInPolygon(pts1.get(j), pts2)) {
                    pts1.remove(j);
                }
            }

            for (int j = 0; j < pts2.size(); j++) {
                if (pointInPolygon(pts2.get(j), pts1)) {
                    pts2.remove(j);
                }
            }

            pts.addAll(pts1);
            pts.addAll(pts2);
        }
    }

// This part didn't work
// PolygonOptions range = new PolygonOptions();
// range.addAll(pts);
// range.strokeWidth(0);
// range.fillColor(0x7F729E47);
// activity.range.add(activity.mMap.addPolygon(range));
4

2 に答える 2

2

@antonio の指示に従い、JTS Topology Suit を使用して、定義された半径でルートの周りにポリゴンをプロットする (ルートをバッファリングする) ことができました。JTSライブラリでバッファ関数を使用したとき、ルートのバッファを取得しましたが、キャップは楕円形でした。それについて読んだところ、計算された座標が平らではない地球の地図に投影され、キャップがより楕円形になるために発生しますルートが地球の極に近いほど、赤道線 (緯度 0°) に近いほど丸くなります。とにかく、ライブラリの別の機能を使用して、質問で既に持っていたすべてのポリゴンを結合しました。結果は次のとおりです。

ここに画像の説明を入力

    public ArrayList<Polygon> polys = new ArrayList<>();

    //lineOptions is the set of route coordinates
    for (int i = 0; i < lineOptions.getPoints().size() - 1; i++) {
        // Draw a circle around each point of the route
        PolygonOptions circle1 = drawCircle(lineOptions.getPoints().get(i), 0.1);
        PolygonOptions circle2 = drawCircle(lineOptions.getPoints().get(i + 1), 0.1);


        // Draw a convex hull between every two successive circles
        PolygonOptions convexHull = convexHull(circle1, circle2);



        List<LatLng> latLngs = convexHull.getPoints();
        List<Coordinate> coords = new ArrayList<>();

        for (int j=0; j<latLngs.size(); j++) {
            coords.add(new Coordinate(latLngs.get(j).latitude, latLngs.get(j).longitude));
            if(j==latLngs.size()-1)
                coords.add(new Coordinate(latLngs.get(0).latitude, latLngs.get(0).longitude));
        }

        Coordinate[] coordinates = coords.toArray(new Coordinate[coords.size()]);

        GeometryFactory fact = new GeometryFactory();
        LinearRing linear = new GeometryFactory().createLinearRing(coordinates);
        Polygon poly = new Polygon(linear, null, fact);

        polys.add(poly);

    }


    PolygonOptions combine = combineIntoOnePolygon(polys);
    combine.strokeWidth(0);
    combine.fillColor(0x7F729E47);
    activity.range = activity.mMap.addPolygon(combine);

結合を行う関数:

static PolygonOptions combineIntoOnePolygon(Collection<Polygon> geometries ){
    Geometry all = null;
    PolygonOptions allPolygon = new PolygonOptions();

    for(Iterator<Polygon> i = geometries.iterator(); i.hasNext(); ){
        Polygon geometry = i.next();
        if( geometry == null ) continue;
        if( all == null ){
            all = geometry;
        }
        else {
            all = all.union( geometry );
        }
    }

    List<Coordinate> bufferCoordinates = Arrays.asList(all.getCoordinates());

    for (Coordinate c : bufferCoordinates) {
        allPolygon.add(new LatLng(c.x, c.y));
    }

    return allPolygon;
}
于 2016-06-20T18:09:03.293 に答える
1

行のバッファを計算する必要があります。ウィキペディアによると:

バッファは、オブジェクトのセグメントに沿ってすべてのノードから指定された最大距離にあるポイントのセットによって決定される境界領域によって定義される領域です。

ジオメトリのバッファは、ミンコフスキーの合計を使用して計算されます。ミンコフスキーの合計は 2 つの多角形 (1 つはポリラインで、もう 1 つは丸いキャップが必要な場合は円) を取り、2 番目の多角形を最初の多角形のパスに沿って移動します。

研究できるミンコフスキー和の具体的な実装をいくつか見つけることができます。例https://github.com/perelo/computational-geometry/blob/master/src/computational_geometry/model/algorithms/Minkowski.java

于 2016-06-18T10:01:08.723 に答える