[英]How to construct polygon using geolocation as coordinate using Google S2 Library
[英]how to create polygon using Google S2 Library in Java
我可以使用Google S2库创建矩形,但无法创建多边形。 我尝试了不同的方法,但无法解决此问题。
共享我的代码和输出:
Double point1_lat= 12.9751;
Double point1_long = 77.5599;
Double point2_lat= 12.9952;
Double point2_long = 77.5954;
Double point3_lat= 12.9741;
Double point3_long = 77.6246;
Double point4_lat= 12.9495;
Double point4_long = 77.59336;
Double point5_lat= 12.9482;
Double point5_long = 77.5630;
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);
S2PolygonBuilder polygonBuilder = new S2PolygonBuilder();
polygonBuilder.addEdge(point1, point2);
polygonBuilder.addEdge(point2, point3);
polygonBuilder.addEdge(point3, point4);
polygonBuilder.addEdge(point4, point5);
polygonBuilder.addEdge(point5, point1);
S2Polygon polygon = polygonBuilder.assemblePolygon();
System.out.println("*************** debug point 1 ****************" + polygon.toString());
S2RegionCoverer coverer = new S2RegionCoverer();
coverer.setMinLevel(5);
coverer.setMaxLevel(10);
coverer.setMaxCells(100);
System.out.println("*************** debug point 2 ****************");
S2CellUnion union = coverer.getCovering(polygon);
System.out.println("*************** debug point 3 ****************");
System.out.println("cells inside the region : "+union.cellIds().size());
输出为:
*************** debug point 1 ****************Polygon: (1) loops:
loop <
(0.0, 80.52526814804811)
(0.0, 80.52256106366895)
(0.0, 80.50285721964708)
(0.0, 80.4926857166327)
(0.0, 80.51134710630562)
>
*************** debug point 2 ****************
finally checking for loop end2047
*************** debug point 3 ****************
cells inside the region : 6
您可以看到,我只能创建6个单元格,但应该超过6个单元格,因为整个区域只需要填充单元格即可。
如果您可以建议我该如何做,请感谢您的时间。
谢谢 !!!!
该库具有自己的内部Lat long表示形式。 您正在制作的形状与您认为的完全不同。 如果您返回6个单元格的级别,它会返回,我怀疑您会发现它们都非常高(0或1或2)。
您需要使用S2latlong.FromDegreees(y,x)创建一个S2latlong对象,然后可以对刚刚创建的S2LatLng对象调用.ToPoint()。
其余的您都正确。 使用这些点形成边缘,使用这些边缘构建多边形。 一旦完成latlong转换,它便会为您工作。
S2Point p = S2LatLng.FromDegrees(y, x).ToPoint();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.