本文整理汇总了Python中imposm.parser.OSMParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python OSMParser.parse方法的具体用法?Python OSMParser.parse怎么用?Python OSMParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imposm.parser.OSMParser
的用法示例。
在下文中一共展示了OSMParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extractCities
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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"
示例2: __init__
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例3: load_osm
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
def load_osm(self, filename):
# Reinitialize if we have a new file
ways = []
coords = {}
num_coords = 0
num_ways = 0
# status output
if self.verbose:
sys.stderr.write("loading ways, each '-' is 100 ways, each row is 10,000 ways\n")
posm = OSMParser(ways_callback=self.ways_callback)
posm.parse(filename)
#print {}
# status output
if self.verbose:
sys.stderr.write("\n{} ways matched in {}, {} coordinates will be loaded, each '.' is 1% complete\n".format(len(self.ways), filename, len(self.coords)))
total = len(self.coords)
if total < 100:
self.coords_marker = 1
else:
self.coords_marker = round(total/100)
posm = OSMParser(coords_callback=self.coords_callback)
posm.parse(filename)
# status output
if self.verbose:
sys.stderr.write("\ncoordinates loaded. calculating curvature, each '.' is 1% complete\n")
sys.stderr.flush()
示例4: retrieve_highway
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
def retrieve_highway(osm_file, selected_zone, tolerance, Ncore = 1):
# Parses the OSM file.
point = Point(selected_zone, tolerance)
p = OSMParser(concurrency = Ncore, coords_callback = point.select)
p.parse(osm_file)
highway = Highway(point)
p = OSMParser(concurrency = Ncore, ways_callback = highway.select)
p.parse(osm_file)
highway.point_set = set([item for refs in highway.point for item in refs])
# Getting all coordinates.
point_coordinate = []
for way in highway.point_set:
try:
point_coordinate.append(point.coordinate[way])
except:
pass
# Defining the set of OSM way id and coordinates.
highway_coordinate = []
highway_osmid = []
for refs, osmid in zip(highway.point, highway.osmid):
try:
highway_coordinate.append([point.coordinate[n] for n in refs])
highway_osmid.append(osmid)
except:
pass
return highway_coordinate, highway_osmid
示例5: remove_tags
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例6: __init__
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例7: __init__
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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]
示例8: fetch_and_parse_pbf
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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'
示例9: load_file
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
def load_file(self, filename):
# Reinitialize if we have a new file
ways = []
coords = {}
num_coords = 0
num_ways = 0
# status output
if self.verbose:
sys.stderr.write("loading ways, each '-' is 100 ways, each row is 10,000 ways\n")
p = OSMParser(ways_callback=self.ways_callback)
p.parse(filename)
# status output
if self.verbose:
sys.stderr.write(
"\n{} ways matched in {} {mem:.1f}MB memory used, {} coordinates will be loaded, each '.' is 1% complete\n".format(
len(self.ways),
filename,
len(self.coords),
mem=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1048576,
)
)
total = len(self.coords)
if total < 100:
self.coords_marker = 1
else:
self.coords_marker = round(total / 100)
p = OSMParser(coords_callback=self.coords_callback)
p.parse(filename)
# Filter out ways that are missing coordinates (because they are
# status output
if self.verbose:
sys.stderr.write(
"\ncoordinates loaded {mem:.1f}MB memory used, calculating curvature, each '.' is 1% complete\n".format(
mem=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1048576
)
)
sys.stderr.flush()
# Loop through the ways and calculate their curvature
self.calculate()
# status output
if self.verbose:
sys.stderr.write(
"calculation complete, {mem:.1f}MB memory used\n".format(
mem=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1048576
)
)
sys.stderr.flush()
示例10: __init__
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例11: parseOSMfile
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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
示例12: __init__
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例13: calc_all_ways
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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)
示例14: add_churches
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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
示例15: load_osm_features
# 需要导入模块: from imposm.parser import OSMParser [as 别名]
# 或者: from imposm.parser.OSMParser import parse [as 别名]
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]