From cce51668f296745dea264cd1a3f4caea1ccc27b7 Mon Sep 17 00:00:00 2001 From: Michael Barry Date: Tue, 8 Mar 2022 21:08:03 -0500 Subject: [PATCH] Migrate to eclipse formatter to support multiple IDEs (#122) --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + .github/ISSUE_TEMPLATE/feature_request.md | 1 + .github/dependabot.yml | 3 +- .../planetiler-examples-dependabot/pom.xml | 22 + .github/workflows/maven.yml | 8 +- .gitignore | 8 + .idea/codeStyles/Project.xml | 3 +- .idea/eclipseCodeFormatter.xml | 13 + .mvn/jvm.config | 5 + .vscode/settings.json | 11 + ARCHITECTURE.md | 1 + CONTRIBUTING.md | 71 +- NOTICE.md | 3 +- PLANET.md | 2 + README.md | 2 +- eclipse-formatter.xml | 480 ++++ .../planetiler/basemap/BasemapProfile.java | 42 +- .../planetiler/basemap/Generate.java | 246 +- .../basemap/generated/OpenMapTilesSchema.java | 550 ++--- .../planetiler/basemap/generated/Tables.java | 625 ++--- .../basemap/layers/AerodromeLabel.java | 3 +- .../planetiler/basemap/layers/Aeroway.java | 7 +- .../planetiler/basemap/layers/Boundary.java | 35 +- .../planetiler/basemap/layers/Building.java | 11 +- .../basemap/layers/Housenumber.java | 8 +- .../planetiler/basemap/layers/Landcover.java | 5 +- .../planetiler/basemap/layers/Landuse.java | 7 +- .../basemap/layers/MountainPeak.java | 5 +- .../planetiler/basemap/layers/Park.java | 4 +- .../planetiler/basemap/layers/Place.java | 18 +- .../planetiler/basemap/layers/Poi.java | 19 +- .../basemap/layers/Transportation.java | 13 +- .../basemap/layers/TransportationName.java | 11 +- .../planetiler/basemap/layers/Water.java | 4 +- .../planetiler/basemap/layers/WaterName.java | 5 +- .../planetiler/basemap/layers/Waterway.java | 5 +- .../basemap/util/LanguageUtils.java | 19 +- .../basemap/layers/AbstractLayerTest.java | 4 +- .../basemap/layers/BoundaryTest.java | 84 +- .../basemap/layers/LandcoverTest.java | 2 +- .../basemap/layers/LanduseTest.java | 10 +- .../planetiler/basemap/layers/ParkTest.java | 2 +- .../planetiler/basemap/layers/WaterTest.java | 4 +- .../planetiler/benchmarks/BasemapMapping.java | 2 +- .../planetiler/FeatureCollector.java | 64 +- .../onthegomap/planetiler/FeatureMerge.java | 19 +- .../planetiler/ForwardingProfile.java | 22 +- .../com/onthegomap/planetiler/Planetiler.java | 50 +- .../com/onthegomap/planetiler/Profile.java | 42 +- .../com/onthegomap/planetiler/VectorTile.java | 23 +- .../planetiler/collection/FeatureGroup.java | 6 +- .../planetiler/collection/Hppc.java | 1 - .../planetiler/collection/LongLongMap.java | 6 +- .../planetiler/config/Arguments.java | 12 +- .../planetiler/expression/Expression.java | 19 +- .../expression/MultiExpression.java | 12 +- .../geo/DouglasPeuckerSimplifier.java | 4 +- .../onthegomap/planetiler/geo/GeoUtils.java | 15 +- .../planetiler/geo/GeometryType.java | 6 +- .../onthegomap/planetiler/geo/PointIndex.java | 5 +- .../planetiler/geo/PolygonIndex.java | 7 +- .../planetiler/mbtiles/Mbtiles.java | 36 +- .../onthegomap/planetiler/mbtiles/Verify.java | 8 +- .../planetiler/reader/ShapefileReader.java | 12 +- .../planetiler/reader/SimpleFeature.java | 15 +- .../planetiler/reader/SourceFeature.java | 23 +- .../planetiler/reader/osm/OsmBlockSource.java | 7 +- .../planetiler/reader/osm/OsmElement.java | 8 +- .../planetiler/reader/osm/OsmReader.java | 10 +- .../reader/osm/PbfFieldDecoder.java | 2 +- .../planetiler/render/FeatureRenderer.java | 4 +- .../render/GeometryCoordinateSequences.java | 11 +- .../planetiler/render/TiledGeometry.java | 17 +- .../onthegomap/planetiler/stats/Counter.java | 6 +- .../planetiler/stats/ProcessInfo.java | 2 +- .../planetiler/stats/ProcessTime.java | 7 +- .../planetiler/stats/ProgressLoggers.java | 13 +- .../planetiler/stats/PrometheusStats.java | 4 +- .../onthegomap/planetiler/stats/Stats.java | 39 +- .../onthegomap/planetiler/stats/Timers.java | 2 +- .../onthegomap/planetiler/util/AwsOsm.java | 6 +- .../planetiler/util/Downloader.java | 37 +- .../onthegomap/planetiler/util/FileUtils.java | 3 +- .../onthegomap/planetiler/util/Geofabrik.java | 8 +- .../planetiler/util/Imposm3Parsers.java | 6 +- .../onthegomap/planetiler/util/LogUtil.java | 3 +- .../com/onthegomap/planetiler/util/Parse.java | 3 +- .../onthegomap/planetiler/util/SortKey.java | 20 +- .../onthegomap/planetiler/util/Wikidata.java | 7 +- .../planetiler/util/ZoomFunction.java | 5 +- .../planetiler/worker/Distributor.java | 14 +- .../worker/WeightedHandoffQueue.java | 1 - .../planetiler/worker/WorkQueue.java | 15 +- .../planetiler/worker/WorkerPipeline.java | 11 +- .../java/vector_tile/VectorTileProto.java | 2068 ++++++++++------- .../planetiler/PlanetilerTests.java | 42 +- .../com/onthegomap/planetiler/TestUtils.java | 24 +- .../onthegomap/planetiler/VectorTileTest.java | 102 +- .../collection/FeatureGroupTest.java | 5 +- .../reader/osm/OsmInputFileTest.java | 18 +- .../reader/osm/OsmMultipolygonTest.java | 2 +- .../planetiler/reader/osm/OsmReaderTest.java | 12 +- .../render/FeatureRendererTest.java | 8 +- .../planetiler/util/GeofabrikTest.java | 50 +- .../planetiler/util/SortKeyTest.java | 53 +- planetiler-examples/README.md | 13 +- planetiler-examples/child.pom.xml | 50 - planetiler-examples/pom.xml | 104 +- .../planetiler/examples/BikeRouteOverlay.java | 21 +- .../planetiler/examples/ToiletsOverlay.java | 11 +- .../examples/ToiletsOverlayLowLevelApi.java | 15 +- .../examples/BikeRouteOverlayTest.java | 6 +- planetiler-examples/standalone.pom.xml | 128 + pom.xml | 38 +- scripts/format.sh | 5 + scripts/regenerate-openmaptiles.sh | 3 + scripts/regenerate-protobuf.sh | 4 + scripts/set-versions.sh | 2 +- scripts/test-release.sh | 2 +- 119 files changed, 3330 insertions(+), 2518 deletions(-) create mode 100644 .github/planetiler-examples-dependabot/pom.xml create mode 100644 .idea/eclipseCodeFormatter.xml create mode 100644 .mvn/jvm.config create mode 100644 .vscode/settings.json create mode 100644 eclipse-formatter.xml delete mode 100644 planetiler-examples/child.pom.xml create mode 100644 planetiler-examples/standalone.pom.xml create mode 100755 scripts/format.sh diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7171afd0..75904a89 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,4 +1,5 @@ --- + name: Bug report about: Create a report to help improve Planetiler title: "[BUG] " diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 6996cad1..8cc917ee 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,4 +1,5 @@ --- + name: Feature request about: Suggest an idea for Planetiler title: "[FEATURE] " diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c27d02a1..5513565b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,7 +15,8 @@ updates: ignore: - dependency-name: "com.graphhopper:graphhopper-reader-osm" - package-ecosystem: maven - directory: "/planetiler-examples" + # workaround for https://github.com/dependabot/dependabot-core/issues/4425 + directory: "/.github/planetiler-examples-dependabot" open-pull-requests-limit: 1 schedule: interval: daily diff --git a/.github/planetiler-examples-dependabot/pom.xml b/.github/planetiler-examples-dependabot/pom.xml new file mode 100644 index 00000000..56372ed0 --- /dev/null +++ b/.github/planetiler-examples-dependabot/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + com.onthegomap.planetiler + planetiler-examples-parent-for-dependabot + HEAD + pom + + + ../../planetiler-examples/pom.xml + + diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index eaef7312..f78b53ba 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -34,10 +34,10 @@ jobs: cache: 'maven' - name: Build with mvnw (linux/mac) if: ${{ !contains(matrix.os, 'windows') }} - run: ./mvnw ${{matrix.args}} --batch-mode -no-transfer-progress package jib:buildTar --file pom.xml + run: ./mvnw ${{matrix.args}} --batch-mode -no-transfer-progress package verify jib:buildTar --file pom.xml - name: Build with mvnw.cmd (windows) if: ${{ contains(matrix.os, 'windows') }} - run: mvnw.cmd ${{matrix.args}} --batch-mode -no-transfer-progress package jib:buildTar --file pom.xml + run: mvnw.cmd ${{matrix.args}} --batch-mode -no-transfer-progress package verify jib:buildTar --file pom.xml shell: cmd regenerate: @@ -54,7 +54,7 @@ jobs: cache: 'maven' - run: ./scripts/regenerate-openmaptiles.sh - run: ./mvnw -DskipTests --batch-mode -no-transfer-progress clean install -pl planetiler-basemap -am - - run: ./mvnw --batch-mode -no-transfer-progress test -pl planetiler-basemap + - run: ./mvnw --batch-mode -no-transfer-progress verify -pl planetiler-basemap examples: name: Example project @@ -69,7 +69,7 @@ jobs: java-version: 17 distribution: 'temurin' - name: Build and test - run: mvn --batch-mode -no-transfer-progress package --file pom.xml + run: mvn --batch-mode -no-transfer-progress package --file standalone.pom.xml working-directory: planetiler-examples - name: Find jar run: mv target/*with-deps.jar ./run.jar diff --git a/.gitignore b/.gitignore index 54d56544..8e140a38 100644 --- a/.gitignore +++ b/.gitignore @@ -5,11 +5,19 @@ target/ !.mvn/wrapper/*.jar *.log +# idea */.idea .idea/* *.iml !.idea/codeStyles !.idea/vcs.xml +!.idea/eclipseCodeFormatter.xml + +# eclipse +.classpath +.project +.settings +bin/ TODO diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index b92b5ecb..16a51e04 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -265,6 +265,7 @@ + - \ No newline at end of file + diff --git a/.idea/eclipseCodeFormatter.xml b/.idea/eclipseCodeFormatter.xml new file mode 100644 index 00000000..02d0ec31 --- /dev/null +++ b/.idea/eclipseCodeFormatter.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 00000000..813a7d48 --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1,5 @@ +--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6012034f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "java.format.settings.url": "eclipse-formatter.xml", + "java.format.settings.profile": "Planetiler", + "java.completion.importOrder": [ + "#", + "" + ], + "java.sources.organizeImports.staticStarThreshold": 5, + "java.sources.organizeImports.starThreshold": 999, + "java.saveActions.organizeImports": true +} diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 669d6263..37dd9d97 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -121,3 +121,4 @@ Finally, a single-threaded writer writes encoded vector tiles to the output MBTi - Create the largest prepared statement supported by SQLite (999 parameters) - Iterate through finished vector tile batches until the prepared statement is full, flush to disk, then repeat - Then flush any remaining tiles at the end + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6343fa8f..57e9514c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,14 @@ # Contributing to Planetiler -Pull requests are welcome! To set up your development environment: +Pull requests are welcome! Any pull request should: + +- Include at least one unit test to verify the change in behavior +- Include an end-to-end test + in [PlanetilerTests.java](planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java) + to verify any major new user-facing features work +- Format the change `./mvnw spotless:apply` and test with `./mvnw verify` before pushing + +To set up your local development environment: - Fork the repo - Install Java 16 or later. You can download Java manually from [Adoptium](https://adoptium.net/installation.html) or @@ -15,30 +23,57 @@ Pull requests are welcome! To set up your development environment: - on windows: `mvnw.cmd clean test` - or if you already have maven installed globally on your machine: `mvn clean test` -To edit the code: +GitHub Workflows will run regression tests on any pull request. -- [Install IntelliJ IDE](https://www.jetbrains.com/help/idea/installation-guide.html) +## IDE Setup + +You can use any text editor as long as you format the code and test before pushing. A good IDE will make things a lot +easier though. + +### IntelliJ IDEA (recommended) + +- [Install IntelliJ IDEA](https://www.jetbrains.com/help/idea/installation-guide.html) +- Install + the [Adapter for Eclipse Code Formatter plugin](https://plugins.jetbrains.com/plugin/6546-adapter-for-eclipse-code-formatter) - In IntelliJ, click `Open`, navigate to the the `pom.xml` file in the local copy of this repo, and `Open` then `Open as Project` - If IntelliJ asks (and you trust the code) then click `Trust Project` - - If any java source files show "Cannot resolve symbol..." errors for Planetiler classes, you might need to - select: `File -> Invalidate Caches... -> Just Restart`. - - If you see a "Project JDK is not defined" error, then choose `Setup SDK` and point IntelliJ at the Java 16 or later - installed on your system -- Recommended: Under `Preferences -> Tools -> Actions on Save` (or `File -> Settings -> Tools -> Actions on Save` on Linux) select `Reformat code` and `Optimize imports` to - automatically format code on save. +- Under `Preferences -> Tools -> Actions on Save` (or `File -> Settings -> Tools -> Actions on Save` on Linux) + select `Reformat code` and `Optimize imports` to automatically format code on save. - To verify everything works correctly, right click on `planetiler-core/src/test/java` folder and click `Run 'All Tests'` -Any pull request should: +Troubleshooting: -- Include at least one unit test to verify the change in behavior -- Include an end-to-end test - in [PlanetilerTests.java](planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java) - to verify any major new user-facing features work -- Use IntelliJ's auto-formatting for modified files (this should get enabled automatically) -- Be free of IntelliJ warnings for modified files +- If any java source files show "Cannot resolve symbol..." errors for Planetiler classes, you might need to + select: `File -> Invalidate Caches... -> Just Restart`. +- If you see a "Project JDK is not defined" error, then choose `Setup SDK` and point IntelliJ at the Java 16 or later + installed on your system -GitHub Workflows will run regression tests on any pull request. +### Visual Studio Code -TODO: Set up checkstyle and an auto-formatter to enforce standards, so you can use any IDE. +- Install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) +- In VSCode, click `File -> Open` and navigate to Planetiler directory + - If VSCode asks (and you trust the code) then click `Yes I trust the authors` +- To verify everything works correctly, go to the `Testing` tab and click `Run Tests` + +Learn more about using VSCode with Java [here](https://code.visualstudio.com/docs/languages/java). + +### Eclipse + +- In [Eclipse for Java Developers](https://www.eclipse.org/downloads/packages/), click `File -> Import ...` + then `Maven -> Existing Maven Projects`, navigate to Planetiler directory, and click `Finish` +- Under `Eclipse -> Preferences...`: + - Under `Java -> Code Style -> Formatter` and choose `Import...` + choose [`eclipse-formatter.xml`](eclipse-formatter.xml) from the root of this project. Then choose `Planetiler` as + the Active profile. + - Under `Java -> Editor -> Save Actions` check `Perform selected actions on save`, `Format source code` + , `Format all lines` and `Organize imports` + - Under `Java -> Code Style -> Organize Imports` change the `number of static imports needed for .*` to 5, then remove + the groups and add 2 new groups: + - `New Static...` and `*` + - `New...` and `*` +- To verify everything works correctly, right click on `planetiler-core/src/test/java` folder and + click `Run As -> JUnit Test` + +TODO: Set up checkstyle diff --git a/NOTICE.md b/NOTICE.md index cad9af51..30127679 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -50,10 +50,11 @@ Additionally, the `planetiler-basemap` module is based on [OpenMapTiles](https:/ ## Data -| source | license | used as default | included in repo | +| source | license | used as default | included in repo | |----------------------------|--------------------------------------------------------------------------------------------------------------------------------------|-----------------|------------------| | OpenStreetMap (OSM) data | [ODBL](https://www.openstreetmap.org/copyright) | yes | yes | | Natural Earth | [public domain](https://www.naturalearthdata.com/about/terms-of-use/) | yes | yes | | OSM Lakelines | [MIT](https://github.com/lukasmartinelli/osm-lakelines), data from OSM [ODBL](https://www.openstreetmap.org/copyright) | yes | no | | OSM Water Polygons | [acknowledgement](https://osmdata.openstreetmap.de/info/license.html), data from OSM [ODBL](https://www.openstreetmap.org/copyright) | yes | yes | | Wikidata name translations | [CCO](https://www.wikidata.org/wiki/Wikidata:Licensing) | no | no | + diff --git a/PLANET.md b/PLANET.md index 15f94459..a8896ec7 100644 --- a/PLANET.md +++ b/PLANET.md @@ -15,10 +15,12 @@ First decide where to get the `planet.osm.pbf` file: - Or a [Daylight Distribution](https://daylightmap.org/) snapshot from Facebook that includes extra quality/consistency checks, and add-ons like ML-detected roads and buildings. Combine add-ons and re-number using [osmium-tool](https://osmcode.org/osmium-tool/): + ```bash osmium apply-changes daylight.osm.pbf admin.osc.bz2 -o everything.osm.pbf osmium renumber everything.osm.pbf -o planet.osm.pbf ``` + NOTE: you need at least `admin.osc.bz2` for the `boundary` layer to show. This takes about 2.5 hours and needs as much RAM as the `planet.osm.pbf` size. diff --git a/README.md b/README.md index 45a8f8ea..494fd024 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ See the [planetiler-examples](planetiler-examples) project. Some example runtimes (excluding downloading resources): -| Input | Profile | Machine | Time | mbtiles size | Logs | +| Input | Profile | Machine | Time | mbtiles size | Logs | |-------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|----------------------------------------------------------|---------------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------| | s3://osm-pds/2021/planet-211011.osm.pbf (65GB) | Basemap | DO 16cpu 128GB | 3h9m cpu:42h1m avg:13.3 | 99GB | [logs](planet-logs/v0.1.0-planet-do-16cpu-128gb.txt), [VisualVM Profile](planet-logs/v0.1.0-planet-do-16cpu-128gb.nps) | | [Daylight Distribution v1.6](https://daylightmap.org/2021/09/29/daylight-v16-released.html) with ML buildings and admin boundaries (67GB) | Basemap | DO 16cpu 128GB | 3h13m cpu:43h40m avg:13.5 | 101GB | [logs](planet-logs/v0.1.0-daylight-do-16cpu-128gb.txt) | diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml new file mode 100644 index 00000000..5fa6d159 --- /dev/null +++ b/eclipse-formatter.xml @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/BasemapProfile.java b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/BasemapProfile.java index bcf1107d..ada8a34a 100644 --- a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/BasemapProfile.java +++ b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/BasemapProfile.java @@ -27,15 +27,15 @@ import java.util.List; *

* Layer implementations extend these interfaces to subscribe to elements from different sources: *

* Layers can also subscribe to notifications when we finished processing an input source by implementing * {@link FinishHandler} or post-process features in that layer before rendering the output tile by implementing @@ -118,9 +118,8 @@ public class BasemapProfile extends ForwardingProfile { return new RowDispatch(constructor.create(), handlers); }).simplify().index(); wikidataMappings = Tables.MAPPINGS - .mapResults(constructor -> - handlerMap.getOrDefault(constructor.rowClass(), List.of()).stream() - .anyMatch(handler -> !IgnoreWikidata.class.isAssignableFrom(handler.handlerClass())) + .mapResults(constructor -> handlerMap.getOrDefault(constructor.rowClass(), List.of()).stream() + .anyMatch(handler -> !IgnoreWikidata.class.isAssignableFrom(handler.handlerClass())) ).filterResults(b -> b).simplify().index(); // register a handler for all OSM elements that forwards to imposm3 "table row" handler methods @@ -149,8 +148,8 @@ public class BasemapProfile extends ForwardingProfile { if (elem instanceof OsmElement.Node) { return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POINT, tags), false); } else if (elem instanceof OsmElement.Way) { - return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false) - || wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_LINE, tags), false); + return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false) || + wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_LINE, tags), false); } else if (elem instanceof OsmElement.Relation) { return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false); } else { @@ -201,14 +200,13 @@ public class BasemapProfile extends ForwardingProfile { } /** - * Layers should implement this interface to subscribe to elements from natural - * earth. + * Layers should implement this interface to subscribe to elements from + * natural earth. */ public interface NaturalEarthProcessor { /** - * Process an element from {@code table} in thenatural earth - * source. + * Process an element from {@code table} in thenatural earth source. * * @see Profile#processFeature(SourceFeature, FeatureCollector) */ @@ -216,8 +214,8 @@ public class BasemapProfile extends ForwardingProfile { } /** - * Layers should implement this interface to subscribe to elements from OSM - * lake centerlines source. + * Layers should implement this interface to subscribe to elements from + * OSM lake centerlines source. */ public interface LakeCenterlineProcessor { @@ -231,8 +229,8 @@ public class BasemapProfile extends ForwardingProfile { } /** - * Layers should implement this interface to subscribe to elements from OSM - * water polygons source. + * Layers should implement this interface to subscribe to elements from + * OSM water polygons source. */ public interface OsmWaterPolygonProcessor { diff --git a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/Generate.java b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/Generate.java index c019158a..1ab032a6 100644 --- a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/Generate.java +++ b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/Generate.java @@ -38,14 +38,14 @@ import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; /** - * Generates code in the {@code generated} package from the OpenMapTiles schema crawled from a tag or branch in the OpenMapTiles GitHub repo. + * Generates code in the {@code generated} package from the OpenMapTiles schema crawled from a tag or branch in the + * OpenMapTiles GitHub repo. *

* {@code OpenMapTilesSchema.java} contains the output layer definitions (i.e. attributes and allowed values) so that * layer implementations in {@code layers} package can reference them instead of hard-coding. *

* {@code Tables.java} contains the imposm3 table definitions from - * mapping.yaml files in the OpenMapTiles repo. Layers in the {@code layer} package can extend the {@code Handler} + * mapping.yaml files in the OpenMapTiles repo. Layers in the {@code layer} package can extend the {@code Handler} * nested class for a table definition to "subscribe" to OSM elements that imposm3 would put in that table. *

* To run use {@code ./scripts/regenerate-openmaptiles.sh} @@ -169,8 +169,7 @@ public class Generate { emitLayerSchemaDefinitions(config.tileset, layers, packageName, output, tag); emitTableDefinitions(tables, packageName, output, tag); - LOGGER.info( - "Done generating code in 'generated' package, now run IntelliJ 'Reformat Code' operation with 'Optimize imports' and 'Cleanup code' options selected."); + LOGGER.info("Done!"); } /** Generates {@code OpenMapTilesSchema.java} */ @@ -178,56 +177,57 @@ public class Generate { Path output, String tag) throws IOException { StringBuilder schemaClass = new StringBuilder(); - schemaClass.append(""" - %s - package %s; - - import static com.onthegomap.planetiler.expression.Expression.*; - import com.onthegomap.planetiler.config.PlanetilerConfig; - import com.onthegomap.planetiler.stats.Stats; - import com.onthegomap.planetiler.expression.MultiExpression; - import com.onthegomap.planetiler.basemap.Layer; - import com.onthegomap.planetiler.util.Translations; - import java.util.List; - import java.util.Map; - import java.util.Set; - - /** - * All vector tile layer definitions, attributes, and allowed values generated from the - * OpenMapTiles vector tile schema %s. - */ - @SuppressWarnings("unused") - public class OpenMapTilesSchema { - public static final String NAME = %s; - public static final String DESCRIPTION = %s; - public static final String VERSION = %s; - public static final String ATTRIBUTION = %s; - public static final List LANGUAGES = List.of(%s); - - /** Returns a list of expected layer implementation instances from the {@code layers} package. */ - public static List createInstances(Translations translations, PlanetilerConfig config, Stats stats) { - return List.of( - %s - ); - } + schemaClass.append( """ - .formatted( - GENERATED_FILE_HEADER, - packageName, - escapeJavadoc(tag), - escapeJavadoc(tag), - Format.quote(info.name), - Format.quote(info.description), - Format.quote(info.version), - Format.quote(info.attribution), - info.languages.stream().map(Format::quote).collect(joining(", ")), - layers.stream() - .map( - l -> "new com.onthegomap.planetiler.basemap.layers.%s(translations, config, stats)" - .formatted(lowerUnderscoreToUpperCamel(l.layer.id))) - .collect(joining("," + LINE_SEPARATOR)) - .indent(6).trim() - )); + %s + package %s; + + import static com.onthegomap.planetiler.expression.Expression.*; + import com.onthegomap.planetiler.config.PlanetilerConfig; + import com.onthegomap.planetiler.stats.Stats; + import com.onthegomap.planetiler.expression.MultiExpression; + import com.onthegomap.planetiler.basemap.Layer; + import com.onthegomap.planetiler.util.Translations; + import java.util.List; + import java.util.Map; + import java.util.Set; + + /** + * All vector tile layer definitions, attributes, and allowed values generated from the + * OpenMapTiles vector tile schema %s. + */ + @SuppressWarnings("unused") + public class OpenMapTilesSchema { + public static final String NAME = %s; + public static final String DESCRIPTION = %s; + public static final String VERSION = %s; + public static final String ATTRIBUTION = %s; + public static final List LANGUAGES = List.of(%s); + + /** Returns a list of expected layer implementation instances from the {@code layers} package. */ + public static List createInstances(Translations translations, PlanetilerConfig config, Stats stats) { + return List.of( + %s + ); + } + """ + .formatted( + GENERATED_FILE_HEADER, + packageName, + escapeJavadoc(tag), + escapeJavadoc(tag), + Format.quote(info.name), + Format.quote(info.description), + Format.quote(info.version), + Format.quote(info.attribution), + info.languages.stream().map(Format::quote).collect(joining(", ")), + layers.stream() + .map( + l -> "new com.onthegomap.planetiler.basemap.layers.%s(translations, config, stats)" + .formatted(lowerUnderscoreToUpperCamel(l.layer.id))) + .collect(joining("," + LINE_SEPARATOR)) + .indent(6).trim() + )); for (var layer : layers) { String layerCode = generateCodeForLayer(tag, layer); schemaClass.append(layerCode); @@ -344,68 +344,70 @@ public class Generate { String tag) throws IOException { StringBuilder tablesClass = new StringBuilder(); - tablesClass.append(""" - %s - package %s; + tablesClass.append( + """ + %s + package %s; - import static com.onthegomap.planetiler.expression.Expression.*; + import static com.onthegomap.planetiler.expression.Expression.*; - import com.onthegomap.planetiler.expression.Expression; - import com.onthegomap.planetiler.expression.MultiExpression; - import com.onthegomap.planetiler.FeatureCollector; - import com.onthegomap.planetiler.reader.SourceFeature; - import java.util.ArrayList; - import java.util.HashMap; - import java.util.HashSet; - import java.util.List; - import java.util.Map; - import java.util.Set; + import com.onthegomap.planetiler.expression.Expression; + import com.onthegomap.planetiler.expression.MultiExpression; + import com.onthegomap.planetiler.FeatureCollector; + import com.onthegomap.planetiler.reader.SourceFeature; + import java.util.ArrayList; + import java.util.HashMap; + import java.util.HashSet; + import java.util.List; + import java.util.Map; + import java.util.Set; - /** - * OSM element parsers generated from the imposm3 table definitions - * in the OpenMapTiles vector tile schema. - * - * These filter and parse the raw OSM key/value attribute pairs on tags into records with fields that match the - * columns in the tables that imposm3 would generate. Layer implementations can "subscribe" to elements from each - * "table" but implementing the table's {@code Handler} interface and use the element's typed API to access - * attributes. - */ - @SuppressWarnings("unused") - public class Tables { - /** A parsed OSM element that would appear in a "row" of the imposm3 table. */ - public interface Row { + /** + * OSM element parsers generated from the imposm3 table definitions + * in the OpenMapTiles vector tile schema. + * + * These filter and parse the raw OSM key/value attribute pairs on tags into records with fields that match the + * columns in the tables that imposm3 would generate. Layer implementations can "subscribe" to elements from each + * "table" but implementing the table's {@code Handler} interface and use the element's typed API to access + * attributes. + */ + @SuppressWarnings("unused") + public class Tables { + /** A parsed OSM element that would appear in a "row" of the imposm3 table. */ + public interface Row { - /** Returns the original OSM element. */ - SourceFeature source(); - } + /** Returns the original OSM element. */ + SourceFeature source(); + } - /** A functional interface that the constructor of a new table row can be coerced to. */ - @FunctionalInterface - public interface Constructor { + /** A functional interface that the constructor of a new table row can be coerced to. */ + @FunctionalInterface + public interface Constructor { - Row create(SourceFeature source, String mappingKey); - } + Row create(SourceFeature source, String mappingKey); + } - /** The {@code rowClass} of an imposm3 table row and its constructor coerced to a {@link Constructor}. */ - public record RowClassAndConstructor( - Class rowClass, - Constructor create - ) {} + /** The {@code rowClass} of an imposm3 table row and its constructor coerced to a {@link Constructor}. */ + public record RowClassAndConstructor( + Class rowClass, + Constructor create + ) {} - /** A functional interface that the typed handler method that a layer implementation can be coerced to. */ - @FunctionalInterface - public interface RowHandler { + /** A functional interface that the typed handler method that a layer implementation can be coerced to. */ + @FunctionalInterface + public interface RowHandler { - /** Process a typed element according to the profile. */ - void process(T element, FeatureCollector features); - } + /** Process a typed element according to the profile. */ + void process(T element, FeatureCollector features); + } - /** The {@code handlerClass} of a layer handler and it's {@code process} method coerced to a {@link RowHandler}. */ - public record RowHandlerAndClass( - Class handlerClass, - RowHandler handler - ) {} - """.formatted(GENERATED_FILE_HEADER, packageName, escapeJavadoc(tag))); + /** The {@code handlerClass} of a layer handler and it's {@code process} method coerced to a {@link RowHandler}. */ + public record RowHandlerAndClass( + Class handlerClass, + RowHandler handler + ) {} + """ + .formatted(GENERATED_FILE_HEADER, packageName, escapeJavadoc(tag))); List classNames = new ArrayList<>(); Map fieldNameToType = new TreeMap<>(); @@ -489,17 +491,19 @@ public class Generate { )); """.formatted( classNames.stream().map( - className -> "MultiExpression.entry(new RowClassAndConstructor(%s.class, %s::new), %s.MAPPING)".formatted( - className, className, className)) + className -> "MultiExpression.entry(new RowClassAndConstructor(%s.class, %s::new), %s.MAPPING)".formatted( + className, className, className)) .collect(joining("," + LINE_SEPARATOR)).indent(2).strip() ).indent(2)); - String handlerCondition = classNames.stream().map(className -> - """ - if (handler instanceof %s.Handler typedHandler) { - result.computeIfAbsent(%s.class, cls -> new ArrayList<>()).add(new RowHandlerAndClass<>(typedHandler.getClass(), typedHandler::process)); - }""".formatted(className, className) - ).collect(joining(LINE_SEPARATOR)); + String handlerCondition = classNames.stream() + .map( + className -> """ + if (handler instanceof %s.Handler typedHandler) { + result.computeIfAbsent(%s.class, cls -> new ArrayList<>()).add(new RowHandlerAndClass<>(typedHandler.getClass(), typedHandler::process)); + }""" + .formatted(className, className) + ).collect(joining(LINE_SEPARATOR)); tablesClass.append(""" /** * Returns a map from imposm3 "table row" class to the layers that have a handler for it from a list of layer @@ -518,15 +522,15 @@ public class Generate { } /** - * Returns an {@link Expression} that implements the same logic as the Imposm3 - * Data Mapping definition for a table. + * Returns an {@link Expression} that implements the same logic as the + * Imposm3 Data Mapping definition for a table. */ static Expression parseImposm3MappingExpression(Imposm3Table table) { if (table.type_mappings != null) { return or( - table.type_mappings.entrySet().stream().map(entry -> - parseImposm3MappingExpression(entry.getKey(), entry.getValue(), table.filters) - ).toList() + table.type_mappings.entrySet().stream() + .map(entry -> parseImposm3MappingExpression(entry.getKey(), entry.getValue(), table.filters) + ).toList() ).simplify(); } else { return parseImposm3MappingExpression(table.type, table.mapping, table.filters); @@ -534,8 +538,8 @@ public class Generate { } /** - * Returns an {@link Expression} that implements the same logic as the Imposm3 - * Data Mapping filters for a table. + * Returns an {@link Expression} that implements the same logic as the + * Imposm3 Data Mapping filters for a table. */ static Expression parseImposm3MappingExpression(String type, JsonNode mapping, Imposm3Filters filters) { return and( diff --git a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/generated/OpenMapTilesSchema.java b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/generated/OpenMapTilesSchema.java index 30a69e02..f366f7e4 100644 --- a/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/generated/OpenMapTilesSchema.java +++ b/planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/generated/OpenMapTilesSchema.java @@ -37,10 +37,7 @@ See https://github.com/openmaptiles/openmaptiles/blob/master/LICENSE.md for deta package com.onthegomap.planetiler.basemap.generated; -import static com.onthegomap.planetiler.expression.Expression.FALSE; -import static com.onthegomap.planetiler.expression.Expression.and; -import static com.onthegomap.planetiler.expression.Expression.matchAny; -import static com.onthegomap.planetiler.expression.Expression.or; +import static com.onthegomap.planetiler.expression.Expression.*; import com.onthegomap.planetiler.basemap.Layer; import com.onthegomap.planetiler.config.PlanetilerConfig; @@ -57,11 +54,11 @@ import java.util.Set; */ @SuppressWarnings("unused") public class OpenMapTilesSchema { - public static final String NAME = "OpenMapTiles"; public static final String DESCRIPTION = "A tileset showcasing all layers in OpenMapTiles. https://openmaptiles.org"; public static final String VERSION = "3.13.0"; - public static final String ATTRIBUTION = "© OpenMapTiles © OpenStreetMap contributors"; + public static final String ATTRIBUTION = + "© OpenMapTiles © OpenStreetMap contributors"; public static final List LANGUAGES = List.of("am", "ar", "az", "be", "bg", "br", "bs", "ca", "co", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fi", "fr", "fy", "ga", "gd", "he", "hi", "hr", "hu", "hy", "id", "is", "it", "ja", "ja_kana", "ja_rm", "ja-Latn", "ja-Hira", "ka", "kk", "kn", "ko", "ko-Latn", "ku", "la", "lb", @@ -93,15 +90,15 @@ public class OpenMapTilesSchema { /** * Water polygons representing oceans and lakes. Covered watered areas are excluded (covered=yes). On low * zoom levels all water originates from Natural Earth. To get a more correct display of the south pole you should - * also style the covering ice shelves over the water. On higher zoom levels water polygons from OpenStreetMapData are used. The polygons are split into many smaller + * also style the covering ice shelves over the water. On higher zoom levels water polygons from + * OpenStreetMapData are used. The polygons are split into many smaller * polygons to improve rendering performance. This however can lead to less rendering options in clients since these * boundaries show up. So you might not be able to use border styling for ocean water features. - *

- * Generated from water.yaml + * + * Generated from + * water.yaml */ public interface Water extends Layer { - double BUFFER_SIZE = 4.0; String LAYER_NAME = "water"; @@ -112,13 +109,14 @@ public class OpenMapTilesSchema { /** Attribute names for map elements in the water layer. */ final class Fields { - /** * All water polygons from OpenStreetMapData have the class - * ocean. Water bodies with the waterway=riverbank - * or water=river tag are classified - * as river. Wet and dry docks tagged waterway=dock - * are classified as a dock. All other water bodies are classified as lake. + * ocean. Water bodies with the + * waterway=riverbank or + * water=river tag are classified as + * river. Wet and dry docks tagged + * waterway=dock are classified as + * a dock. All other water bodies are classified as lake. *

* allowed values: *