我可以使用 Google S2 库构建矩形,但我无法使用 Google S2 库构建多边形,我尝试了不同的方法来创建多边形但无法创建,请你帮我解决一下。
我的代码是:
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
****************");