【问题标题】:How can I buffer a polygon using SimplePolygon2D correctly?如何正确使用 SimplePolygon2D 缓冲多边形?
【发布时间】:2016-05-04 22:57:21
【问题描述】:

我使用以下 Java 在谷歌地图上绘制多边形:

public List<LatLng> create(List<LatLng> footprint)
{
    SimplePolygon2D polygon = createPolygon(footprint);
    if (polygon.isBounded())
    {
        polygon = createPolygon(Lists.reverse(footprint));
    }

    Collection<Point2D> bufferPoints = polygon.buffer(-.00003).boundary().vertices();

    List<LatLng> footprintOfBuffer = new ArrayList<LatLng>();
    for (Point2D point2D : bufferPoints)
    {
        footprintOfBuffer.add(new LatLng(point2D.x(), point2D.y()));
    }

    return footprintOfBuffer;
}

private SimplePolygon2D createPolygon(List<LatLng> footprint)
{
    SimplePolygon2D polygon = new SimplePolygon2D();
    for (LatLng latLng : footprint)
    {
        polygon.addVertex(new Point2D(latLng.getLat(), latLng.getLng()));
    }
    return polygon;
}

这对正方形产生了很好的结果,但对其他多边形却没有。请参阅以下结果:

1、2、3、5 和 6 对我的用例来说已经足够了,但我不确定为什么 4 和 7 似乎有额外的顶点会导致缓冲区关闭。

在我开始检查 isBounded() 方法并在需要时颠倒顶点顺序之前,我最初遇到了一些问题。我注意到的另一件有趣的事情是,在我创建的第一个和最后一个顶点之间添加了额外的顶点。

我可能遗漏了一些简单的东西,但我似乎无法弄清楚为什么会发生这种情况。

有人对此有什么想法或方向吗?

【问题讨论】:

    标签: java google-maps-api-3 polygon


    【解决方案1】:

    看起来这只是 JavaGeom 库中的一个错误。我只是尝试使用 JTS 库来做同样的事情,结果要好得多。我试过用疯狂的多边形来打破它,但它对所有的多边形都有效(非常令人印象深刻)。查看以下结果:

    更新:JTS 库非常棒!自从我写这篇文章以来,我已经用它做了很多事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-17
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多