0

I'm using the Overpass API of OpenStreetMap. I'm pretty new to this and I'm struggling to find a solution here since hours.

I have two different sets of nodes, .a1 and .a2. I add a certain tag to each of them using convert and print them out afterwards. Here is my code:

[out:json][timeout:250];
//gather results
(

  (node["place"="city"](47.8,5.6,50.6,11.2);)->.a1;
  (node["place"="ocean"](0,-180,90,0);)->.a2;



  foreach.a1(

    convert node ::=::, ::id = id(), tileId = 0;
    out;
  );

  foreach.a2(

    convert node ::=::, ::id = id(), tileId = 1;
    out;
  );



   );

My big problem is, that the returning data from the API is suddenly missing the values for "lat" and "lon" of the nodes. So the coordinates of the nodes are missing. If I print the nodes out, without using convert before, the coordinates are still there.

I tried doing something like:

convert node ::=::, ::id = id(), ::geometry = geometry(), tileId = 0;
out;

but it failed.

1 Answer 1

1

Convert creates so called "derived" objects, which have a slightly different behavior in this case. To get geometry details, you need to replace out; by out geom;, as well as using ::geometry = geometry() like you already did in your second example.

Query would then be:

[out:json][timeout:250];

node["place"="city"](47.8,5.6,50.6,11.2)->.a1;
node["place"="ocean"](0,-180,90,0)->.a2;

foreach.a1(

  convert node ::=::, 
               ::geom = geom(),
               ::id = id(), 
               tileId = 0;
  out geom;
);

foreach.a2(

  convert node 
          ::=::,
          ::geom = geom(),
          ::id = id(), 
          tileId = 1;
  out geom;
);

Also notice, that the geometry information for derived objects differs from the format you typically see with nodes. This is a deliberate design decision to prevent people from preparing data for automated edits in OSM.

  "geometry": {
    "type": "Point",
    "coordinates": [ 6.1834097, 48.6937223 ]
  },
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.