I'm developing some Android software using openstreetmap, and I've got a question:

I'd like to submit XML data to the server to create a way, but it always sends back the response "Precondition Failed". I understand the error message - it means when the way has nodes that do not exist yet.

But surely, the nodes of way do not already exist when i create a way? So I don't know how to solve the problem. I've read the API documentation many times and am trying to do the same as it shows in the examples.

Can you help me to solve the problem, or tell me the right way to send a request to server to create a way with nodes that do not yet exist?

Thank you very much!

asked 04 Sep '12, 03:47

lovepanmei's gravatar image

lovepanmei
1222
accept rate: 0%

edited 04 Sep '12, 10:08

SomeoneElse's gravatar image

SomeoneElse ♦
32.0k63327747

Can you explain a bit more about the purpose of your application?

(04 Sep '12, 07:02) mmehl
1

I'd also mention the "if you want to test your software" section of this page. There's a copy of the API at http://api06.dev.openstreetmap.org/ which you can use for testing, which avoids filling the live database with rubbish.

(04 Sep '12, 10:17) SomeoneElse ♦

I know it ,but the request i submit probably has something wrong,but i don't know where.Can you help me to check the xml file as following: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?><osm><node id="-1" lat="34.23294236166552" lon="108.91146183013916" changeset="13030131"/><node id="-2" lat="34.232294838724385" lon="108.9129638671875" changeset="13030131"/><way changeset="13030131"><tag k="name" v="hrllo"/><tag k="RAILWAY" v="railway_platform"/><nd ref="-1"/><nd ref="-2"/></way></osm>

(08 Sep '12, 06:46) lovepanmei

If you've not tried Wireshark you might find it of use. I just used JOSM to upload a hedge I traced from Bing and captured what was happening. The XML was:

<osmChange version="0.6" generator="JOSM">
<create>
  <node id='-7352' action='modify' visible='true' changeset='13030870' lat='51.798472312219666' lon='1.0875406870349713' />
  <node id='-7351' action='modify' visible='true' changeset='13030870' lat='51.79929719724354' lon='1.0872364754165609' />
  <way id='-7353' action='modify' visible='true' changeset='13030870'>
    <nd ref='-7351' />
    <nd ref='-7352' />
    <tag k='barrier' v='hedge' />
    <tag k='source' v='bing' />
  </way>
</create>
</osmChange>

So it looks like you create the nodes and then the ways in the same changeset.

permanent link

answered 08 Sep '12, 08:58

EdLoach's gravatar image

EdLoach ♦
17.7k14145256
accept rate: 23%

edited 08 Sep '12, 08:59

Is the action that create the nodes and ways in the same chageset wrong?

(08 Sep '12, 09:14) lovepanmei

No, if you look at EdLoach's osmChange XML above you'll see that's exactly what JOSM is doing. If you compare that XML with the XML that you're sending you may be able to see what you're doing wrong.

(08 Sep '12, 12:06) SomeoneElse ♦

You can not create a way with nodes that does not exist, or delete nodes when a way refers to it. This is to prevent the data from becoming inconsistant. You have to create the nodes before you create the way, or prefrebly at the same time.

permanent link

answered 04 Sep '12, 07:13

Gnonthgol's gravatar image

Gnonthgol ♦
13.6k15101198
accept rate: 16%

how can i create them at the same time?The data i submit include the way data and the node data also ,it remains wrong ,can you tell me the right xml format.I read the api many times.The time of my project is tight ,so please help.

(04 Sep '12, 07:40) lovepanmei

Would you show us a small XML with a way and only a few nodes that doesn't work?

(04 Sep '12, 07:42) scai ♦

<osmchange version="0.6" generator="Osmosis"> <create> <node id="-1" timestamp="2007-01-02T00:00:00.0+11:00" lat="-33.9133118622908" lon="151.117335519304" changeset="1234" version="12"/> <node id="-2" timestamp="2007-01-02T00:00:00.0+11:00" lat="-33.9133118622911" lon="151.117335519312" changeset="1234" version="12"/>

   <way id="-3" timestamp="2007-01-02T00:00:00.0+11:00" changeset="1234" version="32">
       <nd ref="-1"/>
       <nd ref="-2"/>
   </way>

</create> </osmchange> what i submit is like above,is there something wrong with it?

(04 Sep '12, 08:00) lovepanmei
2

If you are creating a node (using <create> and specifying a negative id), you don't need the version or timestamp just the lon, lat and changeset.

If you are trying to include an existing node (which is what version 12 suggests), don't try to create it just refer to its existing node id.

(04 Sep '12, 17:00) ChrisH

if i want to create a way including not existing node ,how can i do? Is the following xml right? <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <osm> <node id="-1" lat="34.23294236166552" lon="108.91146183013916" changeset="13030131"/> <node id="-2" lat="34.232294838724385" lon="108.9129638671875" changeset="13030131"/> <way changeset="13030131"> <tag k="name" v="hrllo"/> <tag k="RAILWAY" v="railway_platform"/> <nd ref="-1"/> <nd ref="-2"/> </way> </osm>

(08 Sep '12, 06:43) lovepanmei
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×237
×82
×3

question asked: 04 Sep '12, 03:47

question was seen: 4,180 times

last updated: 08 Sep '12, 12:08

powered by OSQA