NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi

what if i do not have the data on my machine - can i do a overpass-api request at the overpass-api endpoint: derived from here: http://forum.openstreetmap.org/viewtopic.php?pid=364460#p364460 _ and thanks go out to suncobald

require 'open-uri'

    require "net/http"
    require 'rexml/document'

    def query_overpass(object_type, left,bottom,right,top, key, value)
       base_url = "http://www.overpass-api.de/api/xapi?"
       query_string = "#{object_type}[bbox=#{left},#{bottom},#{right},#{top}][#{key}=#{value}]"
       url = "#{base_url}#{URI.encode(query_string)}"
       resp = Net::HTTP.get_response(URI.parse(url))
       data = resp.body
       return data
    end

    overpass_result = REXML::Document.new(query_overpass("node", 7.1,51.2,7.2,51.3,"amenity","restaurant|pub|ice_cream|food_court|fast_food|cafe|biergarten|bar|bakery|steak|pasta|pizza|sushi|asia|nightclub"))

    overpass_result.elements.each('osm/node') {|x|
      if !x.elements["tag[@k='name']"].nil?
        print x.elements["tag[@k='name']"].attributes["v"]
      end
      print " | "

      if !x.elements["tag[@k='addr:postcode']"].nil?
        print x.elements["tag[@k='addr:postcode']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:city']"].nil?
        print x.elements["tag[@k='addr:city']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:street']"].nil?
        print x.elements["tag[@k='addr:street']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:housenumber']"].nil?
        print x.elements["tag[@k='addr:housenumber']"].attributes["v"]
      end
      print " | "
      print x.attributes["lat"]
      print " | "
      print x.attributes["lon"]
      print " | "
      if !x.elements["tag[@k='website']"].nil?
        print x.elements["tag[@k='website']"].attributes["v"]
      end
      print " | "
      if !x.elements["tag[@k='amenity']"].nil?
        print x.elements["tag[@k='amenity']"].attributes["v"]
        print " | "
      end
      puts
    }

asked 12 Jun '14, 13:56

say_hello_to_the_world's gravatar image

say_hello_to...
19232427
accept rate: 0%

edited 13 Jun '14, 09:48

1

Sure, isn't that what your(?) code is already trying? It contacts http://www.overpass-api.de. So what is your actual problem?

(12 Jun '14, 14:05) scai ♦
1

Oh, well, SunCobalt created this script originally, here's the link to his forum post: http://forum.openstreetmap.org/viewtopic.php?pid=364460#p364460

Looks like the OP doesn't really know what to do with it?

(12 Jun '14, 20:03) mmd

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:

×483
×30
×21
×20

question asked: 12 Jun '14, 13:56

question was seen: 4,042 times

last updated: 13 Jun '14, 09:48

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum