当前位置: 首页>>代码示例>>Python>>正文


Python parser.fromstring函数代码示例

本文整理汇总了Python中pykml.parser.fromstring函数的典型用法代码示例。如果您正苦于以下问题:Python fromstring函数的具体用法?Python fromstring怎么用?Python fromstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fromstring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fromstring_kml_document

 def test_fromstring_kml_document(self):
     "Tests the parsing of an valid KML string"
     test_kml = '<kml xmlns="http://www.opengis.net/kml/2.2"/>'
     tree = fromstring(test_kml, schema=Schema("ogckml22.xsd"))
     self.assertEquals(etree.tostring(tree), test_kml)
     tree = fromstring(test_kml)
     self.assertEquals(etree.tostring(tree), test_kml)
开发者ID:giricgoyal,项目名称:CS526_UIC_Fall2013,代码行数:7,代码来源:test_parser.py

示例2: load_sat_from_net

def load_sat_from_net():
    """
    Program to load the satllite track prediction from the internet
    Checks at the avdc website
    """
    from datetime import datetime,timedelta
    from urllib2 import urlopen
    from pykml import parser
    today = datetime.now().strftime('%Y%m%d')
    site = 'http://avdc.gsfc.nasa.gov/download_2.php?site=98675770&id=25&go=download&path=%2FSubsatellite%2Fkml&file=A-Train_subsatellite_prediction_'+today+'T000000Z.kml'
    print 'Satellite tracks url: %s' %site
    try:
        response = urlopen(site)
        print 'Getting the kml prediction file from avdc.gsfc.nasa.gov'
        r = response.read()
        kml = parser.fromstring(r)
    except:
        print 'Problem with day, trying previous day...'
        try:
            yesterday = (datetime.now()-timedelta(days=1)).strftime('%Y%m%d')
            site = 'http://avdc.gsfc.nasa.gov/download_2.php?site=98675770&id=25&go=download&path=%2FSubsatellite%2Fkml&file=A-Train_subsatellite_prediction_'+yesterday+'T000000Z.kml'
            response = urlopen(site)
            print 'Getting the kml prediction file from avdc.gsfc.nasa.gov'
            r = response.read()
            kml = parser.fromstring(r)
        except:
            import tkMessageBox
            tkMessageBox.showerror('No sat','There was an error communicating with avdc.gsfc.nasa.gov')
            return None
    print 'Kml file read...'
    return kml
开发者ID:samuelleblanc,项目名称:fp,代码行数:31,代码来源:map_interactive.py

示例3: test_fromstring_kml_document

 def test_fromstring_kml_document(self):
     """Tests the parsing of an valid KML string"""
     test_kml = b'<kml xmlns="http://www.opengis.net/kml/2.2"/>'
     tree = fromstring(test_kml, schema=Schema('ogckml22.xsd'))
     self.assertEqual(etree.tostring(tree, encoding='ascii'), test_kml)
     tree = fromstring(test_kml)
     self.assertEqual(etree.tostring(tree, encoding='ascii'), test_kml)
开发者ID:recombinant,项目名称:pykml,代码行数:7,代码来源:test_parser.py

示例4: parse_bcn_metro

def parse_bcn_metro(basepath):
    files = ['TMB_EST.kml', 'TRAM_EST.kml']
    places = []
    for f in files:
        with open(basepath + f, 'rb') as x:
            xml = etree.parse(x)
        k = parser.fromstring(etree.tostring(xml))
        places.extend(k.findall('.//{http://www.opengis.net/kml/2.2}Placemark'))

    stations = []
    count = 0
    for p in places:
        station = { 'mode' : 'metro' }
        station['city'] = 'Barcelona'
        station['name'] = p.name.text

        coords = [float(c.strip()) for c in p.Point.coordinates.text.split(',')]

        # BCN inserts a trailing 0 coordinate? Why!?
        coords.pop()

        loc = { 'type' : 'Point' }
        loc['coordinates'] = coords
        station['loc'] = loc

        stations.append(station)

    return stations
开发者ID:achiang,项目名称:openmotion,代码行数:28,代码来源:metros.py

示例5: stop_read

def stop_read(filename):

    kmz = ZipFile(filename, 'r')
    files = kmz.namelist()
    # there must be just one file

    kmltext = kmz.open(files[0], 'r').read().decode('iso-8859-1')
    kmltext = kmltext.replace(' encoding="UTF-8"', '')

    k = parser.fromstring(kmltext)

    compania = k.Document.Folder[0]
    compania_nombre = compania.name

    coche = compania.Folder[0]
    coche_nombre = coche.name

    puntos = recuperar_paradas(coche)


    resultado = {
        'compania': compania_nombre,
        'coche': coche_nombre,
        'puntos': puntos
    }

    return resultado
开发者ID:nicopace,项目名称:procesado_kmz_cole,代码行数:27,代码来源:stop_reader.py

示例6: extract_tracks

def extract_tracks(f):
    from pykml import parser

    root = parser.fromstring(f.read())
    tracks = find_tracks(root.Document.Placemark)

    return tracks
开发者ID:petrabarus,项目名称:angkot,代码行数:7,代码来源:import_transportation_kml.py

示例7: loadKML

 def loadKML( self, fileName ):
     """
     return a pykml object that is saved in the kml file fileName
     """
     with open( fileName, 'rb' ) as f:
         kml_str = f.read()
     return parser.fromstring( kml_str )
开发者ID:RZachLamberty,项目名称:WorkCommute,代码行数:7,代码来源:KMLWorkCommute.py

示例8: load_grid_from_file

    def load_grid_from_file(self, kml_file):
        """ parse kml file and add grid to grid_cache """

        file = open(kml_file, "r")
        data = str.encode(file.read())

        root = parser.fromstring(data)
        pms = root.Document.Folder.Placemark

        for pm in pms:
            id = str(pm.ExtendedData.SchemaData.SimpleData[0])
            print(id)

            coords = None

            try:
                coords = pm.MultiGeometry.Polygon.outerBoundaryIs.LinearRing.coordinates
            except:
                try:
                    coords = pm.Polygon.outerBoundaryIs.LinearRing.coordinates
                except:
                    raise

            self.grid_cache[id] = Grid(id, parse_coords(str(coords)))

        print(len(self.grid_cache.keys()))
开发者ID:rivulet-zhang,项目名称:Location-Centric-Real-Time-Visual-Analytics,代码行数:26,代码来源:GridDB.py

示例9: parse_madrid_metro

def parse_madrid_metro(basepath):
    files = ['Metro.kml', 'MetroLigero.kml']
    places = []
    for f in files:
        with open(basepath + f, 'rb') as x:
            xml = etree.parse(x)
        k = parser.fromstring(etree.tostring(xml))
        places.extend(k.findall('.//{http://www.opengis.net/kml/2.2}Placemark'))

    stations = []
    count = 0
    for p in places:
        station = { 'mode' : 'metro' }
        station['city'] = 'Madrid'
        station['name'] = p.name.text

        coords = [float(c.strip()) for c in p.Point.coordinates.text.split(',')]

        loc = { 'type' : 'Point' }
        loc['coordinates'] = coords
        station['loc'] = loc

        stations.append(station)

    return stations
开发者ID:achiang,项目名称:openmotion,代码行数:25,代码来源:metros.py

示例10: parse_london_metro

def parse_london_metro(basepath):
    with open(basepath + 'stations.kml', 'rb') as x:
        xml = etree.parse(x)
    k = parser.fromstring(etree.tostring(xml))
    places = (k.findall('.//{http://www.opengis.net/kml/2.2}Placemark'))

    stations = []
    count = 0
    for p in places:
        station = { 'mode' : 'metro' }
        station['city'] = 'London'
        station['name'] = p.name.text.strip()

        coords = [float(c.strip()) for c in p.Point.coordinates.text.split(',')]

        # London inserts a trailing 0 coordinate too? Why!?
        coords.pop()

        loc = { 'type' : 'Point' }
        loc['coordinates'] = coords
        station['loc'] = loc

        stations.append(station)

    return stations
开发者ID:achiang,项目名称:openmotion,代码行数:25,代码来源:metros.py

示例11: load_kml_string

def load_kml_string(kml_string, schema_type = "kml22gx.xsd"):
    schema_gx = Schema(schema_type)
    doc = parser.fromstring(kml_string, schema_gx)
    
    if (schema_gx.validate(doc)):
        return doc
    else:
        print "Invalid kml format for string passed in"
        return None
开发者ID:wmaciel,项目名称:van-crime,代码行数:9,代码来源:utilities.py

示例12: load_sat_from_file

def load_sat_from_file(filename):
    """
    Program to load the satellite track prediction from a saved file
    """
    from pykml import parser
    f = open(filename,'r')
    r = f.read()
    kml = parser.fromstring(r)
    return kml
开发者ID:samuelleblanc,项目名称:fp,代码行数:9,代码来源:map_interactive.py

示例13: test_fromstring_invalid_kml_document

 def test_fromstring_invalid_kml_document(self):
     "Tests the parsing of an invalid KML string"
     test_kml = '<bad_element />'
     try:
         tree = fromstring(test_kml, schema=Schema("ogckml22.xsd"))
         self.assertTrue(False)
     except etree.XMLSyntaxError:
         self.assertTrue(True)
     except:
         self.assertTrue(False)
开发者ID:giricgoyal,项目名称:CS526_UIC_Fall2013,代码行数:10,代码来源:test_parser.py

示例14: openKML

    def openKML(self,kmlfile):
        if os.path.splitext(kmlfile)[1]=='.kmz':
            kmlfile     =zipfile.ZipFile(kmlfile)
            kmlfilename =kmlfile.namelist()[0]
            coordfile   =kmlfile.read(kmlfilename)
        else:
            coordfile   =open(kmlfile).read()

        self.kmlfile    =coordfile
        self.doc        =parser.fromstring(coordfile)
开发者ID:chadlillian,项目名称:geo,代码行数:10,代码来源:kmlparse.py

示例15: __get_all_coords

def __get_all_coords(data):
        doc = parser.fromstring(data) 
        coords = {}     
        for folder in doc.Document.getchildren():
            try:
               	dataPoints = folder.Placemark.LineString.coordinates.text.split(" ") 
                section_id = folder.Placemark.name.text
                coords[section_id] = [[float(i) for i in x.split(",")[:2]] for x in dataPoints]
            except (Exception):
                continue
        return coords
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:11,代码来源:util.py


注:本文中的pykml.parser.fromstring函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。