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

I have been trying to figure out, is it possible to produce KML polygons from OSM areas with the OSMLib ruby? I have already made quite a few modifications to the ruby source to fit my needs, but I still can't get this part to work..

In the osmlib-base-0.1.4/lib folder, in objects.rb, I added: ** Updated code below

        if (tags['area'] == 'yes' && is_closed?)
          polygon 
        else
          linestring
        end

Replacing what was previously just:

    def geometry
        linestring
    end

That didn't seem to do the trick (there is already some geometry polygon code in the KML output, but obviously not enough! I don't know much at all about Ruby (this project is the first time I have used ruby at all!). Anyone have some tips/want to help implement this? I am sure this could get implemented properly and would be of use to people.

asked 22 Feb '11, 06:35

wbski's gravatar image

wbski
1466914
accept rate: 50%

edited 22 Feb '11, 16:03


Firstly, your approach will mistakenly put many objects in the polygon category, e.g. a highway roundabout; these are not, as your code seems to assume, tagged "area=no". To do this right you would have to look at the specific tags (i.e. closed way tagged as forest => polygon; closed way tagged as fence => linestring etc.)

Secondly, are you sure that the areas you hope to see on output are closed ways at all - or are they maybe multipolygon relation, in which case you would need a totally different approach?

You might want to look at Osmium/Osmjs, by the same author, a program that lets you execute arbitrary Javascript code for OSM objects (you would still have to write the KML output part though). This program has good support for multipolygons.

permanent link

answered 22 Feb '11, 07:40

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

... thirdly, you need to refactor your code, since even if the if condition matches, the function will return the results of the last computation, which as written above is always linestring.

(22 Feb '11, 09:47) Andy Allan

I see what you mean Frederik about not handling all the polygons properly.. However, in my application (ski runs), determining the areas is pretty simple, I will change tagging to area==yes. Anyways, I can tweak the logic to select forests etc later. I changed my code above, but still not working..

Now getting: geo_ruby/simple_features/polygon.rb:17:in send': undefined methodpoints' for #<array:0x1022a3840> (NoMethodError)

Its a mystery to me..

(22 Feb '11, 16:05) wbski

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:

×213
×49
×6
×3

question asked: 22 Feb '11, 06:35

question was seen: 5,265 times

last updated: 23 Feb '11, 04:58

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