Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loop line merger #1083

Merged
merged 57 commits into from
Nov 25, 2024
Merged

Add loop line merger #1083

merged 57 commits into from
Nov 25, 2024

Conversation

wipfli
Copy link
Contributor

@wipfli wipfli commented Nov 2, 2024

This pull request adds a LoopLineMerger class which is a replacement for JTS LineMerger . The new class takes loops in the LineString graph into account. Loops that are shorter than a minLoopLength will be cut open and only the shortest edge will be kept.
Here is a bit of motivation: https://oliverwipfli.ch/improving-linestring-merging-in-planetiler-2024-10-30/
Questions from my side are:

  • How should we expose the new parameter minLoopLength? At the moment I just set it to lengthLimit from FeatureMerge.mergeLineStrings. Should we maybe add an optional loopLengthLimitCalculator?
  • LoopLineMerger is slower than JTS LineMerger. I guess it is because they are doing less (no loops taken into account) but also they are doing things more efficiently. Should I investigate in subclassing JTS LineMergeGraph instead of building my own data structure plus helper functions for the graph?

Copy link

github-actions bot commented Nov 2, 2024

This Branch d5a811d Base b59c63e
0:01:13 DEB [archive] - Tile stats:
0:01:13 DEB [archive] - Biggest tiles (gzipped)
1. 14/4942/6092 (157k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.40015 (poi:85k)
2. 9/154/190 (144k) https://onthegomap.github.io/planetiler-demo/#9.5/41.77078/-71.36719 (landcover:85k)
3. 10/308/380 (136k) https://onthegomap.github.io/planetiler-demo/#10.5/41.90214/-71.54297 (landcover:66k)
4. 10/308/381 (135k) https://onthegomap.github.io/planetiler-demo/#10.5/41.63994/-71.54297 (landcover:72k)
5. 14/4941/6092 (112k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.42212 (poi:64k)
6. 14/4941/6093 (111k) https://onthegomap.github.io/planetiler-demo/#14.5/41.81227/-71.42212 (building:62k)
7. 14/4940/6092 (100k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.44409 (building:92k)
8. 11/616/762 (99k) https://onthegomap.github.io/planetiler-demo/#11.5/41.7057/-71.63086 (landcover:71k)
9. 14/4942/6091 (96k) https://onthegomap.github.io/planetiler-demo/#14.5/41.84501/-71.40015 (building:79k)
10. 11/616/761 (95k) https://onthegomap.github.io/planetiler-demo/#11.5/41.83679/-71.63086 (landcover:72k)
0:01:13 DEB [archive] - Max tile sizes
                      z0    z1    z2    z3    z4    z5    z6    z7    z8    z9   z10   z11   z12   z13   z14   all
           boundary  151   336   409   544   872   332   437   552   802  1.6k    2k  6.9k  6.2k  5.6k  4.5k  6.9k
              water 7.7k  3.7k  8.6k  5.5k  2.6k  5.1k   15k   18k   16k   26k   15k   13k   17k   15k   12k   26k
              place    0     0   441   441   441   640   714    1k  1.6k  3.1k  5.7k  3.3k  1.7k   803   948  5.7k
            landuse    0     0     0     0   549   695  1.6k  6.7k   17k   44k   59k   50k   38k   19k   12k   59k
     transportation    0     0     0     0   311   774  1.2k    4k  5.6k   17k   13k   17k   62k   47k   33k   62k
           waterway    0     0     0     0   112   119     0     0     0    3k  2.3k    2k  2.1k  4.9k  2.4k  4.9k
               park    0     0     0     0     0     0  1.3k  4.3k  9.7k   18k   13k  8.2k  3.7k  3.4k  4.4k   18k
transportation_name    0     0     0     0     0     0   287   364  1.1k  1.9k  5.5k  4.7k  3.9k  3.4k   18k   18k
          landcover    0     0     0     0     0     0     0  9.6k   29k   85k   72k   81k   53k   30k   25k   85k
      mountain_peak    0     0     0     0     0     0     0  1.1k  1.8k  3.4k  4.3k  2.8k  1.4k  1.4k   869  4.3k
         water_name    0     0     0     0     0     0     0     0     0   486   461   433   452  1.2k  1.5k  1.5k
    aerodrome_label    0     0     0     0     0     0     0     0     0     0   666   328   273   221   221   666
            aeroway    0     0     0     0     0     0     0     0     0     0  1.6k  2.1k    3k  3.4k  2.8k  3.4k
                poi    0     0     0     0     0     0     0     0     0     0     0     0   568   565   85k   85k
           building    0     0     0     0     0     0     0     0     0     0     0     0     0   59k   92k   92k
        housenumber    0     0     0     0     0     0     0     0     0     0     0     0     0     0   35k   35k
          full tile 7.9k    4k  9.5k  6.4k  3.7k    6k   20k   40k   82k  195k  182k  135k  113k  128k  247k  247k
            gzipped 6.2k  3.5k  7.1k  5.2k  3.1k  4.8k   14k   28k   59k  144k  136k   99k   83k   92k  157k  157k
0:01:13 DEB [archive] -    Max tile: 247k (gzipped: 157k)
0:01:13 DEB [archive] -    Avg tile: 5.4k (gzipped: 4k) using weighted average based on OSM traffic
0:01:13 DEB [archive] -     # tiles: 4,115,031
0:01:13 DEB [archive] -  # features: 5,518,001
0:01:13 INF [archive] - Finished in 19s cpu:1m10s avg:3.7
0:01:13 INF [archive] -   read    1x(3% 0.5s wait:17s done:1s)
0:01:13 INF [archive] -   encode  4x(56% 11s wait:2s done:1s)
0:01:13 INF [archive] -   write   1x(23% 4s wait:13s done:1s)
0:01:13 INF [archive] - Finished in 1m14s cpu:3m39s gc:1s avg:3
0:01:13 INF [archive] - FINISHED!
0:01:13 INF [archive] - 
0:01:13 INF [archive] - ----------------------------------------
0:01:13 INF [archive] - data errors:
0:01:13 INF [archive] - 	render_snap_fix_input	16,675
0:01:13 INF [archive] - 	osm_multipolygon_missing_way	360
0:01:13 INF [archive] - 	osm_boundary_missing_way	66
0:01:13 INF [archive] - 	merge_snap_fix_input	12
0:01:13 INF [archive] - 	feature_centroid_if_convex_osm_invalid_multipolygon_empty_after_fix	2
0:01:13 INF [archive] - 	render_snap_fix_input2	1
0:01:13 INF [archive] - 	omt_fix_water_before_ne_intersect	1
0:01:13 INF [archive] - 	feature_polygon_osm_invalid_multipolygon_empty_after_fix	1
0:01:13 INF [archive] - 	feature_point_on_surface_osm_invalid_multipolygon_empty_after_fix	1
0:01:13 INF [archive] - ----------------------------------------
0:01:13 INF [archive] - 	overall          1m14s cpu:3m39s gc:1s avg:3
0:01:13 INF [archive] - 	lake_centerlines 5s cpu:6s avg:1.2
0:01:13 INF [archive] - 	  read     1x(9% 0.5s done:5s)
0:01:13 INF [archive] - 	  process  4x(0% 0s done:4s)
0:01:13 INF [archive] - 	  write    1x(0% 0s done:4s)
0:01:13 INF [archive] - 	water_polygons   15s cpu:40s avg:2.7
0:01:13 INF [archive] - 	  read     1x(41% 6s done:7s)
0:01:13 INF [archive] - 	  process  4x(26% 4s wait:4s done:5s)
0:01:13 INF [archive] - 	  write    1x(4% 0.5s wait:9s done:5s)
0:01:13 INF [archive] - 	natural_earth    12s cpu:18s avg:1.6
0:01:13 INF [archive] - 	  read     1x(52% 6s done:5s)
0:01:13 INF [archive] - 	  process  4x(7% 0.8s wait:6s done:5s)
0:01:13 INF [archive] - 	  write    1x(0% 0s wait:6s done:5s)
0:01:13 INF [archive] - 	osm_pass1        2s cpu:7s avg:3.4
0:01:13 INF [archive] - 	  read     1x(2% 0s wait:2s)
0:01:13 INF [archive] - 	  parse    4x(33% 0.7s)
0:01:13 INF [archive] - 	  process  1x(72% 2s)
0:01:13 INF [archive] - 	osm_pass2        19s cpu:1m12s avg:3.9
0:01:13 INF [archive] - 	  read     1x(0% 0s wait:11s done:8s)
0:01:13 INF [archive] - 	  process  4x(75% 14s)
0:01:13 INF [archive] - 	  write    1x(2% 0.4s wait:18s)
0:01:13 INF [archive] - 	ne_lakes         0s cpu:0s avg:0
0:01:13 INF [archive] - 	boundaries       0s cpu:0s avg:2.7
0:01:13 INF [archive] - 	agg_stop         0s cpu:0s avg:0
0:01:13 INF [archive] - 	sort             1s cpu:4s avg:2.7
0:01:13 INF [archive] - 	  worker  1x(48% 0.7s)
0:01:13 INF [archive] - 	archive          19s cpu:1m10s avg:3.7
0:01:13 INF [archive] - 	  read    1x(3% 0.5s wait:17s done:1s)
0:01:13 INF [archive] - 	  encode  4x(56% 11s wait:2s done:1s)
0:01:13 INF [archive] - 	  write   1x(23% 4s wait:13s done:1s)
0:01:13 INF [archive] - ----------------------------------------
0:01:13 INF [archive] - 	archive	108MB
0:01:13 INF [archive] - 	features	284MB
-rw-r--r-- 1 runner docker 87M Nov 25 01:49 run.jar
0:01:04 DEB [archive] - Tile stats:
0:01:04 DEB [archive] - Biggest tiles (gzipped)
1. 14/4942/6092 (159k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.40015 (poi:85k)
2. 9/154/190 (149k) https://onthegomap.github.io/planetiler-demo/#9.5/41.77078/-71.36719 (landcover:85k)
3. 10/308/380 (138k) https://onthegomap.github.io/planetiler-demo/#10.5/41.90214/-71.54297 (landcover:66k)
4. 10/308/381 (137k) https://onthegomap.github.io/planetiler-demo/#10.5/41.63994/-71.54297 (landcover:72k)
5. 14/4941/6092 (113k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.42212 (poi:64k)
6. 14/4941/6093 (112k) https://onthegomap.github.io/planetiler-demo/#14.5/41.81227/-71.42212 (building:62k)
7. 14/4940/6092 (100k) https://onthegomap.github.io/planetiler-demo/#14.5/41.82864/-71.44409 (building:92k)
8. 11/616/762 (99k) https://onthegomap.github.io/planetiler-demo/#11.5/41.7057/-71.63086 (landcover:71k)
9. 14/4942/6091 (97k) https://onthegomap.github.io/planetiler-demo/#14.5/41.84501/-71.40015 (building:79k)
10. 11/616/761 (95k) https://onthegomap.github.io/planetiler-demo/#11.5/41.83679/-71.63086 (landcover:72k)
0:01:04 DEB [archive] - Max tile sizes
                      z0    z1    z2    z3    z4    z5    z6    z7    z8    z9   z10   z11   z12   z13   z14   all
           boundary  155   375   444   584   939   371   467   587   823  1.7k  2.1k  7.2k  6.4k  5.8k  4.5k  7.2k
              water 7.7k  3.7k  8.6k  5.5k  2.6k  5.1k   15k   18k   16k   26k   15k   13k   17k   15k   12k   26k
              place    0     0   441   441   441   640   714    1k  1.6k  3.1k  5.7k  3.3k  1.7k   803   948  5.7k
            landuse    0     0     0     0   549   695  1.6k  6.7k   17k   44k   59k   50k   38k   19k   12k   59k
     transportation    0     0     0     0   370   905  1.3k    6k  8.1k   25k   17k   20k   65k   49k   36k   65k
           waterway    0     0     0     0   112   119     0     0     0  3.2k  2.3k  2.1k  2.1k  4.9k  2.4k  4.9k
               park    0     0     0     0     0     0  1.3k  4.3k  9.7k   18k   13k  8.2k  3.7k  3.4k  4.4k   18k
transportation_name    0     0     0     0     0     0   369   464  1.2k  1.8k  5.5k  4.7k  3.9k  3.4k   18k   18k
          landcover    0     0     0     0     0     0     0  9.6k   29k   85k   72k   81k   53k   30k   25k   85k
      mountain_peak    0     0     0     0     0     0     0  1.1k  1.8k  3.4k  4.3k  2.8k  1.4k  1.4k   869  4.3k
         water_name    0     0     0     0     0     0     0     0     0   486   461   433   452  1.2k  1.5k  1.5k
    aerodrome_label    0     0     0     0     0     0     0     0     0     0   666   328   273   221   221   666
            aeroway    0     0     0     0     0     0     0     0     0     0  1.6k  2.1k    3k  3.4k  2.8k  3.4k
                poi    0     0     0     0     0     0     0     0     0     0     0     0   568   565   85k   85k
           building    0     0     0     0     0     0     0     0     0     0     0     0     0   59k   92k   92k
        housenumber    0     0     0     0     0     0     0     0     0     0     0     0     0     0   35k   35k
          full tile 7.9k    4k  9.5k  6.5k  3.8k  6.2k   21k   42k   85k  203k  185k  135k  114k  129k  250k  250k
            gzipped 6.2k  3.6k  7.1k  5.2k  3.1k    5k   14k   30k   60k  149k  138k   99k   83k   92k  159k  159k
0:01:04 DEB [archive] -    Max tile: 250k (gzipped: 159k)
0:01:04 DEB [archive] -    Avg tile: 5.5k (gzipped: 4.1k) using weighted average based on OSM traffic
0:01:04 DEB [archive] -     # tiles: 4,115,031
0:01:04 DEB [archive] -  # features: 5,518,001
0:01:04 INF [archive] - Finished in 19s cpu:1m10s avg:3.7
0:01:04 INF [archive] -   read    1x(3% 0.6s wait:17s done:1s)
0:01:04 INF [archive] -   encode  4x(57% 11s wait:2s done:1s)
0:01:04 INF [archive] -   write   1x(23% 4s wait:12s)
0:01:04 INF [archive] - Finished in 1m4s cpu:3m31s gc:1s avg:3.3
0:01:04 INF [archive] - FINISHED!
0:01:04 INF [archive] - 
0:01:04 INF [archive] - ----------------------------------------
0:01:04 INF [archive] - data errors:
0:01:04 INF [archive] - 	render_snap_fix_input	16,675
0:01:04 INF [archive] - 	osm_multipolygon_missing_way	360
0:01:04 INF [archive] - 	osm_boundary_missing_way	66
0:01:04 INF [archive] - 	merge_snap_fix_input	12
0:01:04 INF [archive] - 	feature_centroid_if_convex_osm_invalid_multipolygon_empty_after_fix	2
0:01:04 INF [archive] - 	render_snap_fix_input2	1
0:01:04 INF [archive] - 	omt_fix_water_before_ne_intersect	1
0:01:04 INF [archive] - 	feature_polygon_osm_invalid_multipolygon_empty_after_fix	1
0:01:04 INF [archive] - 	feature_point_on_surface_osm_invalid_multipolygon_empty_after_fix	1
0:01:04 INF [archive] - ----------------------------------------
0:01:04 INF [archive] - 	overall          1m4s cpu:3m31s gc:1s avg:3.3
0:01:04 INF [archive] - 	lake_centerlines 2s cpu:5s avg:2.3
0:01:04 INF [archive] - 	  read     1x(22% 0.5s done:2s)
0:01:04 INF [archive] - 	  process  4x(0% 0s done:2s)
0:01:04 INF [archive] - 	  write    1x(0% 0s done:1s)
0:01:04 INF [archive] - 	water_polygons   15s cpu:41s avg:2.8
0:01:04 INF [archive] - 	  read     1x(40% 6s done:7s)
0:01:04 INF [archive] - 	  process  4x(26% 4s wait:4s done:5s)
0:01:04 INF [archive] - 	  write    1x(4% 0.5s wait:10s done:5s)
0:01:04 INF [archive] - 	natural_earth    6s cpu:13s avg:2
0:01:04 INF [archive] - 	  read     1x(95% 6s)
0:01:04 INF [archive] - 	  process  4x(13% 0.8s wait:6s)
0:01:04 INF [archive] - 	  write    1x(0% 0s wait:6s)
0:01:04 INF [archive] - 	osm_pass1        2s cpu:6s avg:3.2
0:01:04 INF [archive] - 	  read     1x(2% 0s wait:2s)
0:01:04 INF [archive] - 	  parse    4x(35% 0.7s)
0:01:04 INF [archive] - 	  process  1x(70% 1s)
0:01:04 INF [archive] - 	osm_pass2        18s cpu:1m11s avg:3.9
0:01:04 INF [archive] - 	  read     1x(0% 0s wait:10s done:8s)
0:01:04 INF [archive] - 	  process  4x(76% 14s)
0:01:04 INF [archive] - 	  write    1x(2% 0.4s wait:18s)
0:01:04 INF [archive] - 	ne_lakes         0s cpu:0s avg:0
0:01:04 INF [archive] - 	boundaries       0s cpu:0s avg:2
0:01:04 INF [archive] - 	agg_stop         0s cpu:0s avg:18.3
0:01:04 INF [archive] - 	sort             1s cpu:3s avg:2.5
0:01:04 INF [archive] - 	  worker  1x(52% 0.7s)
0:01:04 INF [archive] - 	archive          19s cpu:1m10s avg:3.7
0:01:04 INF [archive] - 	  read    1x(3% 0.6s wait:17s done:1s)
0:01:04 INF [archive] - 	  encode  4x(57% 11s wait:2s done:1s)
0:01:04 INF [archive] - 	  write   1x(23% 4s wait:12s)
0:01:04 INF [archive] - ----------------------------------------
0:01:04 INF [archive] - 	archive	108MB
0:01:04 INF [archive] - 	features	284MB
-rw-r--r-- 1 runner docker 86M Nov 25 01:51 run.jar

Full logs: https://github.com/onthegomap/planetiler/actions/runs/12001709762

@wipfli
Copy link
Contributor Author

wipfli commented Nov 2, 2024

I added some tests for the public functions. I don't really know how private functions are tested in Java. Should I for example write specific tests for the private function findAllPaths?

@msbarry
Copy link
Contributor

msbarry commented Nov 2, 2024

It really only needs tests for the public api. If there's an internal method you wanted to make sure works the way you expected you can make it package protected (no modifier) so tests can use it since they're in the same package.

@msbarry
Copy link
Contributor

msbarry commented Nov 2, 2024

How should we expose the new parameter minLoopLength? At the moment I just set it to lengthLimit from FeatureMerge.mergeLineStrings. Should we maybe add an optional loopLengthLimitCalculator?

I think something like this would make sense for an API to control those parameters:

var merger = new LoopLineMerger()
  .setMinLength(0.1)
  .setLoopMinLength(0.1)
  .setPrecision(new PrecisionModel(16)); // to control rounding
merger.add(lineStrings);
var merged = merger.getMergedLineStrings();

@msbarry
Copy link
Contributor

msbarry commented Nov 2, 2024

LoopLineMerger is slower than JTS LineMerger. I guess it is because they are doing less (no loops taken into account) but also they are doing things more efficiently.

I can help look into the performance, I think there will be some low hanging fruit to make it fast. JTS line merge also only considers full linestrings, it doesn't break them up into segments so this one will always be a little slower. The first thing that jumps out at me is creating full LineStrings and reversing/comparing them while building up the lists. I think we might want to have the intermediate code work with lists of coordinates that can be concatenated efficiently, then construct the LineStrings at the very end.

@wipfli
Copy link
Contributor Author

wipfli commented Nov 2, 2024

Great, thanks for the feedback! I added some more tests and marked the methods that I want to test separately as protected.

@msbarry
Copy link
Contributor

msbarry commented Nov 3, 2024

I added a BenchmarkLineMerge class we can use to compare performance of JTS line merge vs. this new utility.

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

Thanks for adding the benchmarks. I changed the api just now. Let me have a look at the benchmark...

@msbarry
Copy link
Contributor

msbarry commented Nov 3, 2024

Pushed a few updates to the benchmark, basically it creates between 10 and 1000 line segments in the range from (0,0) to (100, 100) with between 10 and 1000 intermediate points then uses both line merge. I disabled the 1000 lines with 1000 points because it currently does not finish with loop line merger 😬

Let me know if you can think of more realistic scenarios?

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

I had a look at what is given to line merging if one wants to render highway=primary at z6 for Switzerland. The result is that you get many short linestrings:

groupedFeatures.size  50043
0 <= points per linestring < 5 is 52.04124452970446 percent
5 <= points per linestring < 10 is 26.543172871330654 percent
10 <= points per linestring < 15 is 8.292868133405271 percent
15 <= points per linestring < 20 is 4.248346422077014 percent
20 <= points per linestring < 25 is 3.6428671342645327 percent
25 <= points per linestring < 30 is 1.6805547229382731 percent
30 <= points per linestring < 35 is 0.8912335391563256 percent
35 <= points per linestring < 40 is 0.6374517914593449 percent
40 <= points per linestring < 45 is 0.44961333253402075 percent
45 <= points per linestring < 50 is 0.30174050316727613 percent
50 <= points per linestring < 55 is 0.24978518474112263 percent
55 <= points per linestring < 60 is 0.14587454788881563 percent
60 <= points per linestring < 65 is 0.10590891833023598 percent
65 <= points per linestring < 70 is 0.08992266650680415 percent
70 <= points per linestring < 75 is 0.10191235537437802 percent
75 <= points per linestring < 80 is 0.07193813320544332 percent
80 <= points per linestring < 85 is 0.06394500729372739 percent
85 <= points per linestring < 90 is 0.055951881382011466 percent
90 <= points per linestring < 95 is 0.03397078512479268 percent

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

I guess these statistics reflect that in OpenStreetMap a typical Way has only a handful of Nodes.

Regarding the length of the linestrings, actually almost half of them are too short to occupy distinct start and end points on the 1/16 grid:

0.0 <= linestring length < 0.03125 is 45.149171712327394 percent
0.03125 <= linestring length < 0.0625 is 21.459544791479328 percent
0.0625 <= linestring length < 0.09375 is 9.12015666526787 percent
0.09375 <= linestring length < 0.125 is 5.285454509122155 percent
0.125 <= linestring length < 0.15625 is 3.6388705713086744 percent
0.15625 <= linestring length < 0.1875 is 2.5937693583518175 percent
0.1875 <= linestring length < 0.21875 is 2.036248826009632 percent
0.21875 <= linestring length < 0.25 is 1.5606578342625343 percent
0.25 <= linestring length < 0.28125 is 1.3768159382930678 percent
0.28125 <= linestring length < 0.3125 is 1.0490977759127151 percent

The bins here are 0.5 * 1/16 wide. That means that the linestrings in the first bracket will snap to the same point on the grid for start and end node.

@msbarry
Copy link
Contributor

msbarry commented Nov 3, 2024

Cool, I think we probably want to benchmark a few "average" cases (in terms of num lines/num points) and also a worst-case to make sure it doesn't hang. Feel free to update the benchmark test data generation to be more realistic!

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

That is the Swiss highway=primary network. It has 50k+ input linestrings.
image
Should I just feed those to the benchmarks?

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

Thanks for adding the benchmarks @msbarry! The numbers on my machine are currently:
image

@msbarry
Copy link
Contributor

msbarry commented Nov 3, 2024

Some stats when I run over the planet using openmaptiles profile:

  • num lines to merge: average=3.6 max=239777
  • points per line: average=6.8 max=1759
  • num points in all lines to merge: average=24.6 max=480642

so for worst case we might want a case that's on the order of 500k line segments each with 2 points, and a case that's 200 lines with 5000 points each. For average case, maybe 50x2 10x10 and 2x50?

@wipfli
Copy link
Contributor Author

wipfli commented Nov 3, 2024

These number sound perfect. Thanks for investigating

@msbarry
Copy link
Contributor

msbarry commented Nov 4, 2024

Oh actually I'll try to grab those actual largest input geometries so we can just test against the real thing.

@wipfli
Copy link
Contributor Author

wipfli commented Nov 16, 2024

Thanks for your review! I think I have the code roughly in the state I want for the highway=primary z6 data I used as a playground. As a next step I will look into the tests and also work on the remaining review comments.

@wipfli
Copy link
Contributor Author

wipfli commented Nov 22, 2024

I fixed some tests and noticed that tolerance=0 can still change lines, e.g., nodes on straight lines are removed so [0 0, 1 1, 2 2] becomes [0 0, 2 2]. Do you think we should use a default tolerance of -1 to fully turn simplification off by default?

@msbarry
Copy link
Contributor

msbarry commented Nov 23, 2024

I fixed some tests and noticed that tolerance=0 can still change lines, e.g., nodes on straight lines are removed so [0 0, 1 1, 2 2] becomes [0 0, 2 2]. Do you think we should use a default tolerance of -1 to fully turn simplification off by default?

Yes I think simplify tolerance = -1 would make sense.


if (tolerance >= 0.0) {
simplify();
removeDuplicatedEdges();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we end up with duplicate edges here? Is it possible to remove this duplicate edge removal step?

}

@Test
void testMergeCarriagewaysWithOneSplitShorterThanLoopMinLength() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the merge carriageways tests I added, I think we just need mergeStrokes=true, and tolerance=-1 (by changing the default value) for them to pass. We may also need to change the output line order.

"i90.wkb.gz,1,65",
"i90.wkb.gz,20,4",
"i90.wkb.gz,30,1",
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these, feel free to just change the expected number of lines so that we pin down the behavior to know if it changes in the future. Also, we could probably insert a boolean simplify argument so that we could test a couple of these inputs with and without line simplification.

@msbarry msbarry merged commit c470dc3 into onthegomap:main Nov 25, 2024
6 of 11 checks passed
@wipfli wipfli deleted the loop-line-merge branch November 25, 2024 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants