creating polygons from OSM files in houdini

Posted by gui2one on 25 June 2013 in English (English)

[body] Hi, I am here to comment a little on my work. I haven't been very far for now. But it could get somewhere I think.

I don't see a way to upload an image here. So I will have trouble showing real feed back from my work. As I do mainly 3d. I can pos my python script however, even if it's very messy for now. ( the result of a lot of trial and error with xml.DOM and python itself ... )

but here it is : ////////////////////////// ////////////////////// ////////////////////////

This code is called when instances of this SOP cook.

node = hou.pwd() geo = node.geometry()

node_id_attr = geo.addAttrib(hou.attribType.Point, "node_id", 0) way_id_attr = geo.addAttrib(hou.attribType.Point, "way_id", 0) in_way_num_attr = geo.addAttrib(hou.attribType.Point, "in_way_num", 0)

point_dict = {} #create an empty dictionnary to store data

file = hou.pwd().parm('osm_file').eval() print file

Add code to modify the contents of geo.

from xml.dom import minidom

xmldoc = minidom.parse(file)

n=0 for el in xmldoc.getElementsByTagName('node') : lat = el.attributes['lat'].value lon = el.attributes['lon'].value id = el.attributes['id'].value p = geo.createPoint() p.setPosition((float(lat),0,float(lon))) p.setAttribValue('node_id',int(id)) point_dict[str(id)] = n # insert id value in the dictionnary n += 1

print point_dict.len()

num = 0 for el in xmldoc.getElementsByTagName('way') : print "--------------------" in_way_num = 0 for o in el.getElementsByTagName('nd') :
ref = o.getAttribute('ref')
print ("this is a way nd:"+ str(ref)) print ("connected to point number "+ str(point_dict[ref])) point = geo.globPoints(str(point_dict[ref]))[0] point.setAttribValue('way_id',num) point.setAttribValue('in_way_num',in_way_num)

    in_way_num += 1 

num += 1

for el in xmldoc.getElementsByTagName('relation') : relation_id = el.getAttribute('id') print ("relation id :" + str(relation_id)) for i in el.getElementsByTagName('member') : type = str(i.getAttribute('type')) if type == 'way' : print "ok"

////////////////////////// ////////////////////// ////////////////////////

It's really clear to me right now. But I have a simple but nice result for now. For the data I extracted, I have been able to connect the points pretty nicely. I will try to post an image by another mean. By the way don't try to find the "connecting points" part in the python script : I do it afterwards in houdini.

Edit :Wowww the formatting is really strange. My code is a going to be even harder to read !! Sorry [/body]

Comment from aseerel4c26 on 25 June 2013 at 13:31

Answering/commenting your questions: You can upload images elsewhere (e.g. ) and embed them here.

For posting a block of code, please use the code formatting:

You can edit this entry (need to be logged in before).

Login to leave a comment