gpt4 book ai didi

java - DouglasPeuckerSimplifier 用法

转载 作者:行者123 更新时间:2023-12-01 12:05:29 24 4
gpt4 key购买 nike

我正在尝试减少从 OSM 路径数据生成的形状文件。我正在使用 VTS 的 DouglasPeuckerSimplifier 实现。我想为特定 GTFS(通用交通提要规范)构建路线图的 geojson。我不能直接使用 map 上的集合,因为它太重了,我最终得到了数兆字节大小的 json 文件。

我的代码如下所示,我引入了循环来填充输入,只是为了让您相信我有一个有效的输入数组。我所查询的实际上只是最后 3 行,以及从 OSM 获取路径并减少其中点数的一般概念,我认为这正是 Douglas-Peucker 的全部内容。

                ArrayList<Geometry> points = new ArrayList <Geometry>();
GeometryFactory gf= new GeometryFactory();
for (Object sh : shape_points){
double thisShapeLat=((Shapes)sh).getshapePtLat();
double thisShapeLon=((Shapes)sh).getshapePtLon();
// void identical consecutive points
if (lastShapeLat == thisShapeLat && lastShapeLon == thisShapeLon) continue;
lastShapeLat = thisShapeLat;
lastShapeLon = thisShapeLon;
Coordinate coord= new Coordinate(thisShapeLon,thisShapeLat);
// System.err.println("added coord="+coord);
points.add(gf.createPoint(coord));
}

Geometry[] points_ar = (Geometry [])points.toArray(new Geometry[points.size()]);
GeometryCollection geometries = new GeometryCollection(points_ar, gf);
DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier(geometries);
simplifier.setDistanceTolerance(0.00001);
Geometry result=simplifier.getResultGeometry();

无论我为公差设置什么值,我都会得到与输出(结果)相同的点(点)。它根本没有做任何事情。我也将 simple() 称为静态函数,具有相同的结果,即什么都没有。

最佳答案

您需要使用 LineString 而不是 GeometryCollection 来简化参数。

                Coordinate list2[] = new Coordinate[coords.size()];
list2 = coords.toArray(list2);
CoordinateArraySequence cas=new CoordinateArraySequence(list2);

LineString ls = new LineString(cas,gf);
Geometry result=DouglasPeuckerSimplifier.simplify(ls,0.001);

关于java - DouglasPeuckerSimplifier 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27656264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com