1

I have Java List of Objects where each object represent road + some attributes:

public class Road {
    public String ID;
    public int direction;
    public int type;
    public double startLatitude;
    public double startLongitude;
    public double endLatitude;
    public double endLongitude;
}

I want to write this data into OSM file format, how can I do it?

One option I thought about was to write it to Shapefile using known libraries for it, and then convert Shapefile->OSM. However must a direct way too.

  • 1
    Here is a documentation of the OSM XML file format. Do you mind telling us your ultimate goal? – scai May 18 '17 at 11:19
  • @scai You are suggesting writing the XML by adding for each road 2 nodes and single way. I'm looking for library doing that + optimizing by removing duplicate nodes. – michael May 18 '17 at 11:58
  • 3
    I don't think such a library exists. This is not a typical use-case for OSM data. That's why I asked for your ultimate goal, i.e. what are you trying to achieve with the resulting XML file. – scai May 18 '17 at 12:01
  • 3
    It may seem fairly obvious, but why don't you determine a list of all distinct lat/lon pairs (based on start/end Lat/Lon) to represent your nodes, assign each a distinct node id number, and let your way reference those nodes? And of course output the whole thing as XML. That's basically how the OSM data model works, and it should be easy to implement this on your own. – mmd May 18 '17 at 16:18
  • 3
    By the way: if you're thinking about uploading this stuff to OSM, this policy is a mandatory read! – mmd May 18 '17 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.