2

I need to convert a GeoJSON file coming from an Overpass query in a ESRI Shapefile using ogr2ogr in command line (I'm on Ubuntu 15.10 .. )

This is my query edited in Overpass Turbo

[out:json][timeout:250];
{{geocodeArea:Italia}}->.searchArea;
(
  node["amenity"="hospital"]["emergency"="yes"](area.searchArea);
);
out body;
>;
out skel qt;

and how is converted in Overpass XML (using Export functionality in Overpass Turbo .. )

<osm-script output="json" output-config="" timeout="250">
  <id-query into="searchArea" ref="3600365331" type="area"/>
  <union into="_">
    <query into="_" type="node">
      <has-kv k="amenity" modv="" v="hospital"/>
      <has-kv k="emergency" modv="" v="yes"/>
      <area-query from="searchArea" into="_" ref=""/>
    </query>
  </union>
  <print e="" from="_" geometry="skeleton" limit="" mode="body" n="" order="id" s="" w=""/>
  <recurse from="_" into="_" type="down"/>
  <print e="" from="_" geometry="skeleton" limit="" mode="skeleton" n="" order="quadtile" s="" w=""/>
</osm-script>

I put this in a file named ps-Italy-from-OSM.txt and then I'm download the data using this command:

wget -e use_proxy=yes -e http_proxy=<proxy>:port> --post-file=ps-Italy-from-OSM.txt http://overpass-api.de/api/interpreter --output-document=ps-Italy-OSM.json

Al works fine but, when I try to convert the json data in an ESRI Shapefile using this ogr2ogr command from command line

ogr2ogr -nlt POINT -skipfailures ps-Italy-OSM-WGS84.shp ps-Italy-OSM.json OGRGeoJSON

I obtain this error ...

ERROR 4: Failed to read GeoJSON data
FAILURE:
Unable to open datasource `ps-Italy-OSM.json' with the following drivers.
  -> ESRI Shapefile
  -> MapInfo File
  -> UK .NTF
  -> SDTS
  -> TIGER
  -> S57
  -> DGN
  -> VRT
  -> REC
  -> Memory
  -> BNA
  -> CSV
  -> NAS
  -> GML
  -> GPX
  -> LIBKML
  -> KML
  -> GeoJSON
  -> Interlis 1
  -> Interlis 2
  -> GMT
  -> GPKG
  -> SQLite
  -> DODS
  -> ODBC
  -> WAsP
  -> PGeo
  -> MSSQLSpatial
  -> OGDI
  -> PostgreSQL
  -> MySQL
  -> PCIDSK
  -> OpenFileGDB
  -> XPlane
  -> AVCBin
  -> AVCE00
  -> DXF
  -> Geoconcept
  -> GeoRSS
  -> GPSTrackMaker
  -> VFK
  -> PGDump
  -> OSM
  -> GPSBabel
  -> SUA
  -> OpenAir
  -> PDS
  -> WFS
  -> HTF
  -> AeronavFAA
  -> Geomedia
  -> EDIGEO
  -> GFT
  -> GME
  -> SVG
  -> CouchDB
  -> Idrisi
  -> ARCGEN
  -> SEGUKOOA
  -> SEGY
  -> XLS
  -> ODS
  -> XLSX
  -> ElasticSearch
  -> PDF
  -> Walk
  -> CartoDB
  -> SXF
2

Your result is JSON, not GeoJSON. That's why OGR cannot handle it.

  • 1
    As a workaround, try out:xml, which will deliver an .osm file that OGR can handle. See wiki.openstreetmap.org/wiki/Overpass_API/… for allowed values. – AndreJ Apr 7 '17 at 11:11
  • I've tried but when I try to convert to ESRI shapefile using ogr2ogr -nlt POINT -skipfailures ps-Italy-OSM-WGS84.shp ps-Italy-OSM.xml I obtain the same error Unable to open datasource ps-Italy-OSM.xml with the following drivers. Do you've a sample? – Cesare Apr 7 '17 at 11:48
0

I've solved in this way ... I've changed my file named ps-Italy-from-OSM.txt as follow ...

<osm-script output="xml" output-config="" timeout="250">
  <id-query into="searchArea" ref="3600365331" type="area"/>
  <union into="_">
    <query into="_" type="node">
      <has-kv k="amenity" modv="" v="hospital"/>
      <has-kv k="emergency" modv="" v="yes"/>
      <area-query from="searchArea" into="_" ref=""/>
    </query>
  </union>
  <print e="" from="_" geometry="skeleton" limit="" mode="body" n="" order="id" s="" w=""/>
  <recurse from="_" into="_" type="down"/>
  <print e="" from="_" geometry="skeleton" limit="" mode="skeleton" n="" order="quadtile" s="" w=""/>
</osm-script>

Note that I've changed the output format from json to xml .....

Then I've modified my wget command

wget -e use_proxy=yes -e http_proxy=<proxy>:port> --post-file=ps_from_OSM.txt http://overpass-api.de/api/interpreter --output-document=ps_From_OSM.osm

Then convert in ESRI shapefile ...

ogr2ogr -nlt POINT -skipfailures TMP_DIR ps_From_OSM.osm

NOTE: this command create a DIRECTORY and in this directory there are the shapefiles

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.