topobyte / osm4j

Library and tools for working with OpenStreetMap data and APIs
https://jaryard.com/projects/osm4j/
47 stars 7 forks source link

Changing value of the tag #4

Open mpele opened 3 years ago

mpele commented 3 years ago

Sorry, I understand that this is not an issue but I need some help.

Is it possible to change the value of the tag in the entity during iterating? I would like to redefine tag name but I couldn't find the way to do it. If it is not possible, is it possible to get the raw data for the entity?

sebkur commented 3 years ago

Hi, no problem, creating an issue is fine for this purpose.

The interfaces are designed for read access only and are not mutable. You can create a copy of the entity your dealing with and pass that on to the consumer of your data after changing whatever you need to change.

You can look at https://github.com/topobyte/osm4j/blob/master/core/core/src/main/java/de/topobyte/osm4j/core/model/util/ImplUtil.java for some inspiration. Depending on what it is you're doing, you can potentially use one of the methods provided there and then work with the implementation-specific subclass of https://github.com/topobyte/osm4j/blob/master/core/core/src/main/java/de/topobyte/osm4j/core/model/impl/Entity.java which allows you to get the tags as a list. Then you should be able to remove or replace some of the tags.

mpele commented 3 years ago

Thank you for your quick response - I managed to do tag manipulation :)

May I suggest to make example how tag manipulation could be done for other potential users.

sebkur commented 3 years ago

yes, good idea. May I ask what your use case is? Maybe it can be inspiration for an example...

mpele commented 3 years ago

Uh, it is very complicate to explain... Let's say it very simple - I am preparing data for import in tile server, but I do not want (I am not able) to change carto style because it depends on the country, so I am adjusting data before import.

ps. Is your library able to load the poly files and check if some point is in the polygon?

akamuza commented 2 years ago

I have the same task. Use case: augmenting pbf files with some custom extra tags before importing this pbf into graphhopper. E.g. I'd like to mark roads with custom tag that they belong to big cities polygons. This allows to lower priority of these roads for intercity logistics.