summaryrefslogtreecommitdiff
path: root/localosmfeature2geojson
blob: dfe35e545d794ac7bee96a1cee9c059bc7cd73ff (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2014 Jonas Smedegaard <dr@jones.dk>
  4. # Description: resolve GeoJSON from OSM way or relation.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Depends: gdal-bin perl-modules
  20. set -eu
  21. features=$*
  22. onlineosmxml2geojson() {
  23. set -e
  24. echo '['
  25. first=yes
  26. for feature in "$@"; do
  27. url="http://www.openstreetmap.org/api/0.6/$feature/full"
  28. [ -n "$first" ] || echo ','
  29. ogr2ogr --config OSM_USE_CUSTOM_INDEXING NO -f GeoJSON /vsistdout/ /vsicurl_streaming/"$url" multilinestrings
  30. first=
  31. done
  32. echo ']'
  33. }
  34. onlineosmxml2geojson $features \
  35. | json_pp -json_opt pretty,canonical \
  36. | perl -0 -pe 's/ /\t/g; s/},\s*{/}, {/g; s/\[\s*([\d.,]+)\s*([\d.]+)\s*\]/[$1 $2]/g'