Changeset 1294

Show
Ignore:
Timestamp:
05/01/08 16:57:23 (7 months ago)
Author:
sgillies
Message:

Use pleiades.keytree to parse KML

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pleiades.workspace/trunk/pleiades/workspace/browser/kml.py

    r1289 r1294  
    55from Products.CMFCore.utils import getToolByName 
    66from elementtree import ElementTree as etree 
    7  
     7import keytree 
    88 
    99class KMLImporter(BrowserView): 
     
    2626        try: 
    2727            k = etree.fromstring(request.file.read()) 
    28             for p in k.findall('*/{http://earth.google.com/kml/2.1}Placemark'): 
    29                 n = p.find('{http://earth.google.com/kml/2.1}name') 
    30                 name = n.text 
     28            kmlns = k.tag.split('}')[0][1:] 
     29            for pm_element in k.findall('*/{%s}Placemark' % kmlns): 
     30                f = keytree.feature(pm_element) 
     31                name = f.properties['name'] 
     32                description = f.properties['description'] 
     33                where = f.geometry 
     34                lid = locations.invokeFactory( 
     35                        'Location', 
     36                        geometryType=where.type, 
     37                        spatialCoordinates='%f %f' % (where.coordinates[1], where.coordinates[0]) 
     38                        ) 
    3139                nid = names.invokeFactory( 
    3240                        'Name', 
     
    4654                a = place[aid] 
    4755                a.addReference(names[nid], 'hasName') 
     56                a.addReference(locations[lid], 'hasLocation') 
    4857        except: 
    4958            savepoint.rollback() 
  • pleiades.workspace/trunk/pleiades/workspace/tests/kml-import.txt

    r1289 r1294  
    6565    >>> 'ptolemais-barkes-limen' in ws['names'] 
    6666    True 
    67  
     67    >>> len(ws['locations']) 
     68    11