Beispiel #1
0
 def Render(self, im,filename,tx,ty,tz,layer):
   """Render an OSM tile
   im - an image to render onto
   filename - location of OSM data for the tile
   tx,ty,tz - the tile number
   layer - which map style to use
   """
   
   #self.osm = LoadOsm(filename)  # get OSM data into memory
   self.osm = parseOsm(filename)  # get OSM data into memory
   self.proj = proj(tx,ty,tz,im.size)  # create a projection for this tile
   self.drawContext = ImageDraw.Draw(im)  # create a drawing context
   
   # Call the draw function
   self.draw()
   
   del self.drawContext # cleanup  
Beispiel #2
0
  def Render(self, filename,tx,ty,tz,layer):
    """Render an OSM tile
    im - an image to render onto
    filename - location of OSM data for the tile
    tx,ty,tz - the tile number
    layer - which map style to use
    """

    #set context variables that should be available during drawing
    self.z = tz
    self.mapLayer = layer

    if(filename):
      self.osm = parseOsm(filename)  # get OSM data into memory
    self.proj = proj(tx,ty,tz,(256,256))  # create a projection for this tile

    # Call the draw function
    self.draw()
Beispiel #3
0
def OsmMerge(dest, z, sources):
  """Merge multiple OSM files together
  
  Usage: 
    OsmMerge('output_filename.osm', 
      ['input_file_1.osm', 
       'input_file_2.osm',
       'input_file_3.osm'])
  """
  
  ways = {}
  poi = []
  node_tags = {}
  nodes = {}
  
  divisor = float(2 ** 31)
  
  # Trawl through the source files, putting everything into memory
  for source in sources:
    osm = parseOsm(source)
    
    for p in osm.poi:
      node_tags[p['id']] = p['t']

    for id,n in osm.nodes.items():
      nodes[id] = n
    for id,w in osm.ways.items():
      ways[id] = w

  # Store the result as an OSM XML file
  f=codecs.open(dest, mode='w', encoding='utf-8')
  f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
  f.write('<osm version="0.5" generator="OsmMerge">\n')
  
  # TODO: Write the nodes
  if(0):
	  for n,data in nodes.items():
	    (lat,lon) = nodes[n]
	    f.write('<node id="%d" lat="%f" lon="%f">' % (n,lat,lon))
	    tags = node_tags.get(n, None)
	    if(tags):
	      for k,v in tags.items():
	        f.write('\n<tag k=%s v=%s/>' % (quoteattr(k),quoteattr(v)))
	    f.write("</node>\n")

  limit = pixelSize(z) * 2.0
  limitSq = limit * limit
  #print "Using limit %e" % limitSq
  
  # Detect 'junction' ways
  usage = {}
  junctions = {}
  countNodes = 0
  for wid,way in ways.items():
    for n in way['n']:
      nid = n['id']
      if(usage.get(nid,0) != 0):
        junctions[nid] = 1
      else:
        usage[nid] = 1
      countNodes = countNodes + 1

  #print "%d nodes, %d junctions" % (countNodes, len(junctions.keys()))

  countUsed = countNotUsed = 0
  # Write the ways
  for id,way in ways.items():
    f.write('<way id="%d">' % id)
    for k,v in way['t'].items():
      f.write('\n<tag k=%s v=%s/>' % (quoteattr(k),quoteattr(v)))

    (lastx,lasty,count) = (0,0,False)
    for n in way['n']:
      lat = n['lat']
      lon = n['lon']
      
      storeThisNode = False
      if(count == 0):
        storeThisNode = True  # Store 1st node
      elif(junctions.get(n['id'], 0) == 1):
        storeThisNode = True  # Store junction nodes
      else:
        dx = lon - lastx
        dy = lat - lasty
        dd = dx * dx + dy * dy
        if(dd > limitSq):
          storeThisNode = True  # Store ever x pixels
          
        #print "Dist2 = %f" % dd
        
      if(storeThisNode):
        (lastx,lasty,count) = (lon,lat,count+1)
      
        f.write("\n<nd id='%d' x='%1.0f' y='%1.0f'/>" % (n['id'], lon * divisor, lat * divisor))
        countUsed = countUsed + 1
      else:
        countNotUsed = countNotUsed + 1
    f.write("</way>\n")
  #print "Used %d, skipped %d" % (countUsed, countNotUsed)
  
  # TODO: Write the relations

  
  f.write("</osm>\n")
  f.close()