簡體   English   中英

如何使用Google S2庫將地理位置作為坐標來構造多邊形

[英]How to construct polygon using geolocation as coordinate using Google S2 Library

我可以使用Google S2 Library構造矩形,但是我不能使用Google S2 Library構造多邊形,我嘗試使用其他方法創建多邊形但無法創建多邊形,請您幫我一下。

我的代碼是:

  Double point1_lat= 41.94621306986162;
    Double point1_long = -87.85629272460938;
    Double point2_lat= 41.91198644177823;
    Double point2_long = -87.84427642822266;
    Double point3_lat=  41.91173095014916;
    Double point3_long = -87.7804183959961;
    Double point4_lat= 41.94570235966688;
    Double point4_long = -87.75672912597656;
    Double point5_lat= 41.966893394601335;
    Double point5_long = -87.78900146484375;
    Double point6_lat= 41.97480631113838;
    Double point6_long = -87.84049987792969;
    Double check1 = 41.916585116228354;
    Double check2 = -87.736129760742194;

    // For point
    S2Point point1 = new S2Point(point1_lat, point1_long, 0);
    S2Point point2 = new S2Point(point2_lat, point2_long, 0);
    S2Point point3 = new S2Point(point3_lat, point3_long, 0);
    S2Point point4 = new S2Point(point4_lat, point4_long, 0);
    S2Point point5 = new S2Point(point5_lat, point5_long, 0);
    S2Point point6 = new S2Point(point6_lat, point6_long, 0);
    S2Point point7 = new S2Point(check1, check2, 0);

    List<S2Point> point = new ArrayList<S2Point>();
    point.add(point1);
    point.add(point2);
    point.add(point3);
    point.add(point4);
    point.add(point5);
    point.add(point6);

    System.out.println("***************  debug point 3 
      ****************" + point);

    S2PolygonBuilder polygonBuilder = new S2PolygonBuilder();
     S2Loop loop = new S2Loop(point);

     System.out.println("***************  debug point 4 
     ****************" );
     polygonBuilder.addLoop(loop);
     S2Polygon polygon = polygonBuilder.assemblePolygon();

    System.out.println("***************  debug point 5 
    ****************" );
    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(12);
    coverer.setMaxLevel(12);
    coverer.setMaxCells(100);

    System.out.println("***************  debug point 6 
    ****************");


    S2CellUnion union = coverer.getCovering(polygon);

    System.out.println("***************  debug point 7 
     ****************");

獲得S2Point,必須更改代碼:

S2Point point1 = S2LatLng.fromDegrees(point1_lat, point1_long).toPoint();
//new S2Point(point1_lat, point1_long, 0);

暫無
暫無

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

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