NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum

helllo dear osm-experts

new to Ruby - i need some advices -

i plan to do some requests in osm-files. (openstreetmap)

Question - how can i store the results on a Database - eg mysql or - (if you prefer postgresql) -

note: my favorite db - at least at the moment is mysql

here the code

require 'open-uri'
require "net/http"
require 'rexml/document'

def query_overpass(object_type, left,bottom,right,top, key, value)
   base_url = ""
   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

overpass_result ="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 ", "
  if !x.elements["tag[@k='addr:city']"].nil?
    print x.elements["tag[@k='addr:city']"].attributes["v"]
    print ", "
  if !x.elements["tag[@k='addr:street']"].nil?
    print x.elements["tag[@k='addr:street']"].attributes["v"]
    print ", "
  if !x.elements["tag[@k='addr:housenumber']"].nil?
    print x.elements["tag[@k='addr:housenumber']"].attributes["v"]
  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"]
  print " | "
  if !x.elements["tag[@k='amenity']"].nil?
    print x.elements["tag[@k='amenity']"].attributes["v"]
    print " | "

look forward to hear from you

again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would takte this one.... ;-)

asked 08 Jun '14, 12:24

say_hello_to_the_world's gravatar image

accept rate: 0%

I would suggest using postgresql with the PostGIS extension - it's much better at geographical support than MySQL.

For ruby I'd recommend the RGeo suite of tools - see . I use this for my projects, usually with the activerecord-postgis-adapter and rgeo-geojson gems too.

permanent link

answered 09 Jun '14, 12:28

Andy%20Allan's gravatar image

Andy Allan
accept rate: 28%

Your answer
toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 08 Jun '14, 12:24

question was seen: 3,193 times

last updated: 09 Jun '14, 12:28

NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum