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


Python parser.OSMParser类代码示例

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


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

示例1: __init__

	def __init__(self, osmfile):
		# parse the input file and save its contents in memory
		# road ids and node refs as returned from imposm
		self.roads = dict()

		p = OSMParser(ways_callback = self.ways_callback)
		p.parse(osmfile)
开发者ID:mseln,项目名称:yolo-octo-wallhack,代码行数:7,代码来源:store.py

示例2: extractCities

def extractCities( countries_dir, output_dir ):
	print "extracting cities"
	global CC
	global citiesFile

	if os.path.exists( cities_path ):
		os.remove( cities_path )

	citiesFile = codecs.open( cities_path, encoding='utf-8', mode='wb' ) 

	prepare_CC_map( )

	p = OSMParser( concurrency=4, nodes_callback = handle_nodes )

	for dirname, dirnames, filenames in os.walk( countries_dir ):
	#    for subdirname in dirnames:
		baseDirName = os.path.basename( dirname )
		basePath = os.path.dirname( dirname )

		for country_file in filenames:
			if country_file != ".DS_Store":
				country = os.path.splitext( os.path.basename( country_file ) )[0]
				CC = map_to_CC( country )
	#			print country + " " + CC
				inputFile = dirname + "/" + country_file
				print inputFile
				p.parse( inputFile )

	citiesFile.close()

	print "done"
开发者ID:volkerv,项目名称:MobileCitySearch,代码行数:31,代码来源:createCityDB.py

示例3: remove_tags

def remove_tags(input_filename, output_fp, tags_to_keep, close_output_fp=True):

    output_writer = OSMWriter(fp=output_fp)
    remover = TagRemover(output_writer, tags_to_keep)
    parser = OSMParser(ways_callback=remover.ways, nodes_callback=remover.nodes, concurrency=1)
    parser.parse(input_filename)

    output_writer.close(close_file=close_output_fp)
开发者ID:rory,项目名称:openstreetmap-remove-tags,代码行数:8,代码来源:__init__.py

示例4: __init__

    def __init__(self, osmfile):
        # parse the input file and save its contents in memory

        # initialize street network
        self.street_network = StreetNetwork()

        # coord pairs as returned from imposm
        self.coords = dict()

        # max and min latitude and longitude
        self.bounds = dict()
        self.bounds["min_lat"] = 9999
        self.bounds["max_lat"] = -9999
        self.bounds["min_lon"] = 9999
        self.bounds["max_lon"] = -9999

        # active copy of OSM data indexed by OSM id
        self.all_osm_relations = dict()
        self.all_osm_ways = dict()
        self.all_osm_nodes = dict()

        # nodes with specific landuse tags
        self.residential_nodes = set()
        self.industrial_nodes = set()
        self.commercial_nodes = set()

        # subset that is also connected to the street network
        self.connected_residential_nodes = set()
        self.connected_industrial_nodes = set()
        self.connected_commercial_nodes = set()

        # mapping from highway types to max speeds
        # we do this so there"s always a speed limit for every edge, even if
        # none is in the OSM data
        self.max_speed_map = dict()
        self.max_speed_map["motorway"] = 140
        self.max_speed_map["trunk"] = 120
        self.max_speed_map["primary"] = 100
        self.max_speed_map["secondary"] = 80
        self.max_speed_map["tertiary"] = 70
        self.max_speed_map["road"] = 50
        self.max_speed_map["minor"] = 50
        self.max_speed_map["unclassified"] = 50
        self.max_speed_map["residential"] = 30
        self.max_speed_map["track"] = 30
        self.max_speed_map["service"] = 20
        self.max_speed_map["path"] = 10
        self.max_speed_map["cycleway"] = 1   # >0 to prevent infinite weights
        self.max_speed_map["bridleway"] = 1  # >0 to prevent infinite weights
        self.max_speed_map["pedestrian"] = 1 # >0 to prevent infinite weights
        self.max_speed_map["footway"] = 1    # >0 to prevent infinite weights

        p = OSMParser(concurrency = 1,
                      coords_callback = self.coords_callback,
                      nodes_callback = self.nodes_callback,
                      ways_callback = self.ways_callback,
                      relations_callback = self.relations_callback)
        p.parse(osmfile)
开发者ID:NeziheSozen,项目名称:Streets4MPI,代码行数:58,代码来源:osmdata.py

示例5: __init__

class p:
	def __init__(self):
		server = Server()
		self.db=server.get_or_create_db("b")
		self.i=0
		self.parser=OSMParser(nodes_callback=self.coord, ways_callback=self.way, relations_callback=self.rel, coords_callback=self.coord)
	def parse(self,x):
		self.parser.parse(x)
	def coord(self,c):
		out=dict()
		for osm_id,lat,lng in c:
			out["type"]="coord"
			out["_id"]=str(osm_id)
			out["geometry"]={"type":"Point","coordinates":lng}
			self.db["c"+str(osm_id)]=out
		self.i=self.i+1
		print "cached a coord totoal now "+str(self.i)
	def node(self,n):
		out=dict()
		for osm_id,tags,coord in n:
			c=[coord[0],coord[1]]
			out["type"]="node"
			out["_id"]=str(osm_id)
			out["geometry"]={"type":"Point","coordinates":c}
			for k in tags:
				if k !="type" and k!="_id"and k!="geometry":
					out[k]=tags[k]
			self.db[str(osm_id)]=out
		self.i=self.i+1
		print "cached a node totoal now "+str(self.i)
	def way(self,w):
		out=dict()
		for osm_id,tags,mem in w:
			out["type"]="way"
			out["_id"]=str(osm_id)
			out["members"]=mem
			for k in tags:
				if k !="type" and k!="_id"and k!="members":
					out[k]=tags[k]
			self.db[str(osm_id)]=out
		self.i=self.i+1
		print "cached a way totoal now "+str(self.i)
	def rel(self,r):
		out=dict()
		for osm_id,tags,mem in r:
			out["type"]="relation"
			out["_id"]=str(osm_id)
			out["members"]=mem
			for k in tags:
				if k !="type" and k!="_id"and k!="members":
					out[k]=tags[k]
			self.db[str(osm_id)]=out
		self.i=self.i+1
		print "cached a rel totoal now "+str(self.i)
	def clean(self):
		for k in self.nodes:
			if self.coords.has_key(k):
				del self.coords[k]
开发者ID:calvinmetcalf,项目名称:impar,代码行数:58,代码来源:impar.py

示例6: fetch_and_parse_pbf

def fetch_and_parse_pbf():
    print 'Fetching', PBF_URL
    pbf_file = 'brandenburg-latest.osm.pbf'
    urllib.urlretrieve(PBF_URL, pbf_file)
    np = NodesParser()
    p = OSMParser(concurrency=2, nodes_callback=np.nodes)
    p.parse(pbf_file)
    np.close()
    print 'Dataset', DATASET_PATH, 'with', np.count, 'nodes parsed from OSM xml'
开发者ID:tondzus,项目名称:berlin-geo,代码行数:9,代码来源:berlin_geo.py

示例7: main

def main():

    file_name = sys.argv[1]
    filter = AmenityFilter()
    nodes = NodesCoords()
    p = OSMParser(nodes_callback=nodes.nodes_callback,
                  nodes_tag_filter=filter.amenity_filter)
    p.parse_pbf_file(file_name)
    print yaml.dump(nodes.points)
开发者ID:camelia-groza,项目名称:OsmPoint,代码行数:9,代码来源:pbf_parser.py

示例8: __init__

    def __init__(self, osm_file, coords, nodes, config):

        self.tmp_dir = tempfile.mkdtemp()
        
        self.config = config
        self.osm_file = osm_file
        self.coords = dict(coords.items() + nodes.items())
        
        osm_parser = OSMParser(concurrency=1, ways_callback=self._ways_callback)
        osm_parser.parse(osm_file)
开发者ID:Rollmops,项目名称:OSM2P3D,代码行数:10,代码来源:roads.py

示例9: parseOSMfile

def parseOSMfile(filename,waysConf,areasConf,bridgesConf,tunnelsConf,srtm):	
	""" Parse OSM file """
	clas = classifier(waysConf,areasConf,bridgesConf,tunnelsConf,srtm)
	p = OSMParser(concurrency=4, ways_callback=clas.ways_cb, nodes_callback=clas.nodes_cb, relations_callback=clas.relations_cb, coords_callback=clas.coords_cb)
	p.parse(filename)
	clas.Map.nodes.sort(key=lambda node: node.id)
	clas.Map.ways.sort(key=lambda way: way.id)
	for i in range(len(clas.Map.nodes)):
		clas.Map.nodesIdx[clas.Map.nodes[i].id]=i
	return clas.Map
开发者ID:xtompok,项目名称:osmawalk,代码行数:10,代码来源:parse.py

示例10: __init__

  def __init__(self, osmfile):
    self.nodes = dict()
    self.bounds = dict()
    self.bounds["min_lat"] =-9999 # 58.3773000
    self.bounds["max_lat"] = 9999 # 58.4236000
    self.bounds["min_lng"] =-9999 # 15.5207000
    self.bounds["max_lng"] = 9999 # 15.6248000

    p=OSMParser(coords_callback = self.coords_callback)
    p.parse(osmfile)
开发者ID:vlad-sensei,项目名称:lmap,代码行数:10,代码来源:nodes.py

示例11: extract

 def extract(self,osm_filename):
     self.p = OSMParser(ways_callback=self.find_highway_nodes)
     self.p.parse(osm_filename)
     print "Highway nodes found"
     self.p =  OSMParser(coords_callback=self.count_nodes)
     self.p.parse(osm_filename)
     print "Created graph nodes"
     self.p = OSMParser(ways_callback=self.connect_nodes)
     self.p.parse(osm_filename)
     print len(self.edge_endpts)
开发者ID:vshekar,项目名称:MapExtractionPython,代码行数:10,代码来源:map_extract_template.py

示例12: add_churches

def add_churches(filename):
    # get churches
    churches = GetChurches()
    p = OSMParser(concurrency=4,
                  nodes_callback=churches.nodes,
                  ways_callback=churches.ways)
    p.parse(filename)
    
    update_refs.apply_async(args=[filename])
    return True
开发者ID:pombredanne,项目名称:kirchenreich,代码行数:10,代码来源:tasks.py

示例13: calc_all_ways

	def calc_all_ways(self):
		p = OSMParser(concurrency=4, coords_callback=self._read_coords,
			ways_callback=self._read_ways)
		if not self.silent:
			print("Reading file")
		p.parse(self.filepath)
		if not self.silent:
			print("Summing")
		self._calc_ways()
		return sum(self.way_distances)
开发者ID:lyrk,项目名称:OSMMesser,代码行数:10,代码来源:osmmesser.py

示例14: process_file

def process_file(filename, baseurl = 'http://download.geofabrik.de/osm/europe/', parentCountry = ""):
    print "retrieving file " + filename + "..."
    urllib.urlretrieve(baseurl+filename, '/tmp/'+filename)

    global country
    refsSet = set()
    nodesLookup = dict()

    if parentCountry == "":
        country = filename[0:-8].replace('_',' ').title()
        if country in countriesLookup:
            country = countriesLookup[country]
    
    print "parsing for refs..."
    parser = OSMParser(ways_callback=refs_handler)
    parser.parse('/tmp/'+filename)

    print "parsing for coords..."
    parser = OSMParser(coords_callback=coords_handler)
    parser.parse('/tmp/'+filename)
    
    print "parsing for ways..."
    parser = OSMParser(ways_callback=ways_handler)
    parser.parse('/tmp/'+filename)

    scraperwiki.sqlite.save_var(filename, 1)
开发者ID:carriercomm,项目名称:scraperwiki-scraper-vault,代码行数:26,代码来源:power_grid_1.py

示例15: load_osm_features

    def load_osm_features(self, pbf_path , families):
        logger.info("    Adding feature from OSM.")
        pbf_path, pbf_name = os.path.split(pbf_path)
        categories = {}
        for family in families:
            locations = {}

            class FamilyParser(object):
                ways_objects = {}
                nodes_objects = {}
                all_nodes = {}

                def ways(self, ways):
                    for osmid, tags, refs in ways:
                        for key in families[family].keys():
                            if key in tags.keys():
                                if families[family][key] == "*" or tags[key] in families[family][key]:
                                    self.ways_objects[int(osmid)] = {"nd" : refs, "tag" : tags[key]}

                def nodes(self, nodes):
                    for osmid, tags, coords in nodes:
                        for key in families[family].keys():
                            if key in tags.keys():
                                if families[family][key] == "*" or tags[key] in families[family][key]:
                                    self.nodes_objects[int(osmid)] = {"lon" : coords[0], "lat" : coords[1], "tag" : tags[key]}

                def coords(self, coords):
                    for coords in coords:
                        self.all_nodes[int(coords[0])] = (coords[1], coords[2])

            parser = FamilyParser()
            p = OSMParser(concurrency = 2, ways_callback = parser.ways, nodes_callback = parser.nodes, coords_callback = parser.coords)
            p.parse("%s/%s.osm.pbf" % (pbf_path, self.name))

            for k in parser.nodes_objects.keys():
                locations[k] = (parser.nodes_objects[k]["lon"], parser.nodes_objects[k]["lat"], parser.nodes_objects[k]["tag"])
            for k in parser.ways_objects.keys():
                # compute mean postion
                m_lon, m_lat = 0, 0
                for nd in parser.ways_objects[k]["nd"]:
                    node = parser.all_nodes[int(nd)]
                    m_lon += node[0]
                    m_lat += node[1]
                m_lon /= float(len(parser.ways_objects[k]["nd"]))
                m_lat /= float(len(parser.ways_objects[k]["nd"]))
                locations[nd] = (m_lon, m_lat, parser.ways_objects[k]["tag"]) #a way can have the same id as a node so we take the id of the last node

            logger.info("Number of elements in family %s : %s" % (family, str(len(locations.keys()))))

            categories[family] = locations

        for category in categories.keys():
            for id in categories[category].keys():
                building = Building(int(id), categories[category][id][0], categories[category][id][1], category, None)
                self.features += [building]
开发者ID:vallettea,项目名称:epml,代码行数:55,代码来源:NYenergy.py


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