dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: problems with parsing CityGML in Python

Hybrid View

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    problems with parsing CityGML in Python

    Hi guys,

    I need to parse CityGML (which is in this case a normal xml) in Python. For this I use ElementTree.
    This is perfectly working for normal XML-Files. I can change content, print Tag-attributes etc. But whenever I try to start to take the CityGML-FIle nothing happens...


    In this example I just want to try to get a list of the child Tags with the name "creationDate":
    Code:
    import xml.etree.ElementTree as ET 
    tree = ET.parse('Gasometer.xml')
    root = tree.getroot()
    def child_list(child):                                  
        list_child = list(tree.iter(child))
        return list_child
    date = child_list('creationDate')
    print (date)
    This is a part of the XML-File (The file is full of such ObjectMembers and I want to have the creationDates of them; CityModel ist the Root-Tag of the file)

    HTML Code:
    <CityModel xmlns="http://www.opengis.net/citygml/1.0" xmlns:tran="http://www.opengis.net/citygml/transportation/1.0" xmlns:wtr="http://www.opengis.net/citygml/waterbody/1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:grp="http://www.opengis.net/citygml/cityobjectgroup/1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:luse="http://www.opengis.net/citygml/landuse/1.0" xmlns:frn="http://www.opengis.net/citygml/cityfurniture/1.0" xmlns:app="http://www.opengis.net/citygml/appearance/1.0" xmlns:tex="http://www.opengis.net/citygml/texturedsurface/1.0" xmlns:bldg="http://www.opengis.net/citygml/building/1.0" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:dem="http://www.opengis.net/citygml/relief/1.0" xmlns:veg="http://www.opengis.net/citygml/vegetation/1.0" xmlns:gen="http://www.opengis.net/citygml/generics/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/citygml/landuse/1.0 http://schemas.opengis.net/citygml/landuse/1.0/landUse.xsd http://www.opengis.net/citygml/cityfurniture/1.0 http://schemas.opengis.net/citygml/cityfurniture/1.0/cityFurniture.xsd http://www.opengis.net/citygml/appearance/1.0 http://schemas.opengis.net/citygml/appearance/1.0/appearance.xsd http://www.opengis.net/citygml/texturedsurface/1.0 http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd http://www.opengis.net/citygml/transportation/1.0 http://schemas.opengis.net/citygml/transportation/1.0/transportation.xsd http://www.opengis.net/citygml/waterbody/1.0 http://schemas.opengis.net/citygml/waterbody/1.0/waterBody.xsd http://www.opengis.net/citygml/building/1.0 http://schemas.opengis.net/citygml/building/1.0/building.xsd http://www.opengis.net/citygml/relief/1.0 http://schemas.opengis.net/citygml/relief/1.0/relief.xsd http://www.opengis.net/citygml/vegetation/1.0 http://schemas.opengis.net/citygml/vegetation/1.0/vegetation.xsd http://www.opengis.net/citygml/generics/1.0 http://schemas.opengis.net/citygml/generics/1.0/generics.xsd http://www.opengis.net/citygml/cityobjectgroup/1.0 http://schemas.opengis.net/citygml/cityobjectgroup/1.0/cityObjectGroup.xsd">
      <cityObjectMember>
        <bldg:Building gml:id="UUID_899cac3f-e0b6-41e6-ae30-a91ce51d6d95">
          <gml:description>Wohnblock in geschlossener Bauweise</gml:description>
          <gml:boundedBy>
            <gml:Envelope srsName="urn:ogc:def:crs,crs:EPSG::3068,crs:EPSG::5783" srsDimension="3">
              <gml:lowerCorner>21549.6537889055 17204.3479916992 38.939998626709</gml:lowerCorner>
              <gml:upperCorner>21570.6420902953 17225.660050148 60.6840192923434</gml:upperCorner>
            </gml:Envelope>
          </gml:boundedBy>
          <creationDate>2014-03-28</creationDate>
          <externalReference>
            <informationSystem>LOCATION</informationSystem>
            <externalObject>
              <name>0003000a000af91c</name>
            </externalObject>
          </externalReference>

    The only thing I get is an empty list []

    What should I do? Hope somebody can help me

  2. #2
    Join Date
    Apr 2015
    Posts
    1

    example's for parsing CityGML with ElementTree

    Hi Toto2806
    Since this is an old post I'll just leave this here in case someone else might need it.
    To parse CityGML try the following code, it should help getting a general idea how to fetch the information.

    Code:
    import xml.etree.ElementTree as ET
    def loadfile():
        tree = ET.parse('filename')
        root = tree.getroot()
    
        for envelope in root.iter('{http://www.opengis.net/gml}Envelope'):
            print "ENV tag", envelope.tag
            print "ENV attrib", envelope.attrib
            print "ENV text", envelope.text
            
            lCorner = envelope.find('{http://www.opengis.net/gml}lowerCorner').text
            uCorner = envelope.find('{http://www.opengis.net/gml}upperCorner').text
            
            print "lC",lCorner 
            print "uC",uCorner
    
    if __name__== "__main__":
        loadfile()
    To get the srsName try following.

    Code:
    import xml.etree.ElementTree as ET
    
    def loadfile():
        tree = ET.parse('filename')
        root = tree.getroot()
        for envelope in root.iter('{http://www.opengis.net/gml}Envelope'):
            key = envelope.attrib
            srsName = key.get('srsName')
            print "SRS Name: ", srsName
    
    if __name__== "__main__":
        loadfile()
    I hope this helps you or anyone else who might try parsing CityGML with ElementTree

    Regards
    A.Simons

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles