简体   繁体   English

如何使用Google S2库将地理位置作为坐标来构造多边形

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

I am able to construct rectangle using Google S2 Library but I am not able to construct polygon using Google S2 Library, I have tried with different method to create polygon but not able to create ,Could you please help me on this. 我可以使用Google S2 Library构造矩形,但是我不能使用Google S2 Library构造多边形,我尝试使用其他方法创建多边形但无法创建多边形,请您帮我一下。

my code is : 我的代码是:

  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 
     ****************");

get S2Point must you change you code : 获得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.

相关问题 如何在Java中使用Google S2库创建多边形 - how to create polygon using Google S2 Library in Java 如何使用改造库构建这个网址? - How to construct this url using retrofit library? 使用Google Maps Geolocation API - Using The Google Maps Geolocation API 如何使用Google的Guava库提取Java中的泛型类型 - How to extract a generic type in Java using Google's Guava library 如何在谷歌中使用 latlng 的字符串数组绘制多边形 map - how to draw polygon using string array of latlng in google map 使用可比较或比较器接口使用String s1的顺序对String s2进行排序 - Sort String s2 using the order of String s1 using either of comparable or comparator interface 应该使用java将S1的每个备用索引中的字符替换为S2 - Character in each alternate index of S1 should be replaced with S2 using java 需要使用JTS库在坐标周围创建圆 - need to create circle around coordinate using JTS library 使用Google的Java API客户端库进行身份验证时出现IllegalArgumentException - IllegalArgumentException when authenticating using Google's Java API client library 使用JTS库检测LineString / MultiLineString是否在多边形内部或与之相交 - Detect if a LineString / MultiLineString is inside a Polygon or if it intersects it using JTS library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM