Using curl to upload data

From OpenStreetMap Wiki
Jump to: navigation, search

CURL is a command-line Unix utility, available from http://curl.haxx.se/download.html that can be used to upload data to OSM without the overhead of JOSM, Potlatch and other tools.

It's useful when you want to upload public domain data that wasn't obtained via GPS or similar method. There's nothing super-special about curl, of course. Any other command-line tool that supports authentication and the HTTP PUT and DELETE protocols will also work.

This page describes how to upload a node using curl for API v0.5. Uploading a way is similar.

  • Create a text file with the XML for the node (only a single node can be uploaded at a time):
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.5' generator='wiki-example-CHANGEME'>
<node lat='0' lon='0'>
<tag k='example' v='yes' />
</node>
</osm>

Of course, you'll want to change "wiki-example-CHANGEME" to something useful, and add whatever tags are appropriate.

If you're using a script or batch uploading, try to use a 'generator' value and tags that identify the script exactly, including revision number (eg, "my-osm-upload-script-v2.3.rb"), and identify the data source (eg, a tag with k='source' and v='http://cabq.gov/gisshapes/README'). If you discover an error with your script (or a specific version of your script), or later learn the data is copyrighted, tags will allow you to easily identify and delete the bad data.

Note that there is no need to provide a node id: OSM will supply this for you.

Save the file above as /tmp/example.txt

  • Use this curl command to upload the data:
curl -u username:password -i -o /tmp/output.txt -T /tmp/example.txt 'http://api.openstreetmap.org/api/0.5/node/create'   

Substitute your own username and password for "username:password" above. Remember to use your www.openstreetmap.org username/password, not your wiki.openstreet.org username/password.

If you get 'Expectation Failed', check out this post: http://curl.haxx.se/mail/archive-2005-11/0127.html

Remember that wiki and website accounts are different. You may have one without the other. You website username (the one you want to use above) is probably your email address.

  • The file /tmp/output.txt will contain something like this:
Content-Type: text/plain; charset=utf-8 
Cache-Control: no-cache 
Content-Length: 9 
Date: Sun, 30 Dec 2007 21:34:35 GMT 
Server: lighttpd/1.4.13 
 
198139632 

The number at the end (198139632 in this case) is the id of the node you just created.

  • The node you've added will start appearing in queries right away: there is no delay or review process. You can see your node by making this query:
curl -o node.txt 'http://api.openstreetmap.org/api/0.5/node/198139632' 

and looking at node.txt.

Note that no authentication is required to view nodes, only to add them. Of course, you'll want to replace 198139632 with you own node's id.

  • You can also see your node by downloading data for a bounding box that contains it:
curl -o confirm.txt 'http://api.openstreetmap.org/api/0.5/map?bbox=-0.001,-0.001,0.002,0.002'

Again, no authentication is required. If you put your node somewhere other than 0,0, you'll of course use a different bounding box.

confirm.txt will contain both your node, and any other existing nodes/ways in the bounding box.

  • If you're just testing, you can now delete the node you created:
curl -u username:password -X DELETE 'http://api.openstreetmap.org/api/0.5/node/198139632' 

Again, replace 198139632 with the id of the node you created.