-
-
Notifications
You must be signed in to change notification settings - Fork 126
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 support for geojson #1147
Add support for geojson #1147
Conversation
I think the tests are failing due to download issue from geofabrik:
I'm not sure this is related to the changes I made... |
Full logs: https://github.com/onthegomap/planetiler/actions/runs/12809430105 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Newline-delimited geojson is also a common format supported by tools like tippecanoe, do you think there's any way for this to support that as well?
GeoJsonReader(String sourceName, Path input) { | ||
super(sourceName); | ||
store = new GeoJSONDataStore(input.toFile()); | ||
layer = input.getFileName().toString().replaceAll("\\.geojson$", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see these having a .json
extension too - could we default with just removing the file extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 24ec3ba
SimpleFeature simpleFeature = SimpleFeature.create((Geometry) feature.getDefaultGeometry(), HashMap.newHashMap(feature.getProperties().size()), | ||
sourceName, layer, id++); | ||
feature.getProperties().forEach(property -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: extract var properties = feature.getProperties();
once in case it's doing anything expensive to compute the properties map.
Also you can omit the curly braces on forEach(property -> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 636dcd1
<dependency> | ||
<groupId>org.geotools</groupId> | ||
<artifactId>gt-geojson</artifactId> | ||
<version>${geotools.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geotools</groupId> | ||
<artifactId>gt-geojson-store</artifactId> | ||
<version>${geotools.version}</version> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see JTS already has a GeoJsonReader class. Geotools has some licensing issues so I'm trying to avoid adding new dependencies on it. But the JTS reader doesn't seem to handle properties at all so this might be the best one to start with...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, JTS is only for geometries, it doesn't handle feature and feature collection...
Geotools uses it under the hood...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the geotools version automatically handle parsing/converting CRS of input geojson?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue, probably not, it is very similar to shapefile, I belive, in terms of API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to play with the Crs object of the store in various way but it seems to always return WGS84 even if the file said otherwise.
I've opened a ticket here:
https://osgeo-org.atlassian.net/browse/GEOT-7705
This can be read from the file itself, but it seems hacky...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks! The jts version handles crs but not properties, and geotools version handles properties but not crs 🤦♂️ if there's just one crs defined for the entire object it wouldn't be too bad to read it out like jts does (https://github.com/locationtech/jts/blob/master/modules/io/common/src/main/java/org/locationtech/jts/io/geojson/GeoJsonReader.java#L445-L470), but we could also merge this version then handle crs and newline-delimited in a follow-up pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I think this is a good addition as is. We can always improve in the future.
For people using newline geojson it should be an easy task to add the surrounding feature collection I hope before running planetiler. |
|
OK thanks! The main benefit of newline-delimited geojson is if the dataset is very large, it can be read line-by-line instead of loading the whole thing in memory. I could take a stab at auto-detecting which kind it is and handling newline-delimited variant in a followup PR... |
Looks good now! Thanks for adding! |
Great! Let me know when a new version with this is available. |
Implemented in onthegomap#1147
This is a very similar to #413.
It uses geotools' geojson capabilities (very similar to shapefile).
I've added some minimal tests, I think it might be enough, but I'm not sure.
I was able to run the tests I added but I'm getting an error when running
mvn clean install
on the entire project.Let me know if anything is missing.