• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python parser.fromstring函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: validate_kml

def validate_kml(filepath, schema = "https://developers.google.com/kml/schema/kml21.xsd"):
        """
        Validates kml located at filepath.
        TODO: Even imported kml files do not validate against default xml
        """
        schema_gomaps = Schema(schema)
	data = ""
	with open(filepath, "r") as temp:
		data = temp.read()
	assert(data != "")
	doc = parser.fromstring(data)
        return schema_ogc.assertValid(doc)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:12,代码来源:util.py


示例17: retrieve_sites_info_awac_kml

def retrieve_sites_info_awac_kml(kml_url=AWAC_KML_URL):
    """
    downloads a kml from dept_of_transport WA. retrieve informations to create a dictionary of site info(lat, lon, data url ...
    :param kml_url: string url kml to parse
    :return: dictionary
    """

    logger.info('Parsing {url}'.format(url=kml_url))
    try:
        fileobject = requests.get(kml_url).content
    except:
        logger.error('{url} not reachable. Retry'.format(url=kml_url))
        raise requests.ConnectionError

    root = kml_parser.fromstring(fileobject)
    doc = root.Document.Folder

    sites_info = dict()
    for pm in doc.Placemark:

        coordinates = pm.Point.coordinates.pyval
        latitude = float(coordinates.split(',')[1])
        longitude = float(coordinates.split(',')[0])
        water_depth = float(coordinates.split(',')[2])

        description = pm.description.text

        snippet = pm.snippet.pyval
        time_start = snippet.split(' - ')[0]
        time_end = snippet.split(' - ')[1]
        time_start = datetime.datetime.strptime(time_start, '%Y-%m-%d')
        time_end = datetime.datetime.strptime(time_end, '%Y-%m-%d')

        name = pm.name.text
        soup = BeautifulSoup(description)
        text_zip_url = soup.findAll('a', attrs={'href': re.compile("^http(s|)://.*_Text.zip")})[0].attrMap['href']

        m = re.search('<b>AWAC LOCATION ID:</b>(.*)<br>', description)
        site_code = m.group(1).lstrip()
        logger.info('{site} available for download'.format(site=site_code))
        site_info = {'site_name': name,
                     'lat_lon': [latitude, longitude],
                     'timezone': 8,
                     'latitude': latitude,
                     'longitude': longitude,
                     'water_depth': water_depth,
                     'time_start': time_start,
                     'time_end': time_end,
                     'text_zip_url': text_zip_url,
                     'site_code': site_code}
        sites_info[site_code] = site_info

    return sites_info
开发者ID:aodn,项目名称:data-services,代码行数:53,代码来源:common_awac.py


示例18: handle_uploaded_kmlfile

def handle_uploaded_kmlfile(filename,objectid):
    from pykml import parser
    from pykml.util import to_wkt_list
    
    # check if the file is too large
    if filename.size >= filename.DEFAULT_CHUNK_SIZE:
        raise IOError
    # parse the incoming file
    doc = parser.fromstring(filename.read())
    # look for geometries
    wkt_list = [{'geom':wkt} for wkt in to_wkt_list(doc)]
    
    return(wkt_list)
开发者ID:LeadsPlus,项目名称:OpenClimateGIS,代码行数:13,代码来源:views.py


示例19: load_route

def load_route():
    try:
        data = json.loads(request.data)
        url = data['url']
    except Exception as e:
        logging.error(0)
        abort(400)

    obj = urllib2.urlopen(url)
    str = obj.read()
    kml_str = ""
    for line in iter(str.splitlines()):
        if not 'atom:link' in line:
            kml_str += line
            kml_str += '\n'

    Point.objects(type='route').delete()

    root = parser.fromstring(kml_str)

    pointid = 1000
    for placemark in root.Document.Folder.Placemark:
        coordinates = placemark.MultiGeometry.Point.coordinates.text.split(',')
        try:
            point = Point(
                title=placemark.name.text,
                type='route',
                latitude=float(coordinates[1]),
                longitude=float(coordinates[0]),
                pointid=pointid,
                timestamp=datetime.now()
            )
        except TypeError:
            abort(500)
        except Exception as e:
            logging.error(0)
            abort(500)
        try:
            point.save()
        except TypeError:
            abort(400)
        except BadRequest as e:
            logging.error(e)
            abort(400)
        except Exception as e:
            logging.error(e)
            abort(500)

        pointid += 1

    return Response(json.dumps({'status': 'ok'}), status=200, mimetype='application/json')
开发者ID:yakinaround,项目名称:myadventure-api,代码行数:51,代码来源:controllers.py


示例20: parse_map_user

def parse_map_user(user):

    kml = os.path.join(os.getcwd(), 'data.kml')
    with open(kml) as f:
        doc = parser.fromstring(f.read())
        coords = doc.Document.Folder.Placemark.LineString.coordinates[0].text.strip().split()
        points = [(x.split(',')[0], x.split(',')[1]) for x in coords]

    for p in points:
        d = Data(0, 0, 0, p[1], p[0], datetime.now(), user)
        db.session.add(d)


    db.session.commit()
开发者ID:jvd33,项目名称:DriverTag,代码行数:14,代码来源:seeds.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python parser.parse函数代码示例发布时间:2022-05-25
下一篇:
Python factory.KML_ElementMaker类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap