Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(12)  |  Call(6)  |  Derive(0)  |  Import(6)
Merge multiple OSM files together

Usage:
  OsmMerge('output_filename.osm',
    ['input_file_1.osm',
     'input_file_2.osm',
     'input_file_3.osm'])

        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('\n')
    f.write('\n')

    # TODO: Write the nodes
    if (0):
        for n, data in nodes.items():
            (lat, lon) = nodes[n]
            f.write('' % (n, lat, lon))
            tags = node_tags.get(n, None)
            if (tags):
                for k, v in tags.items():
                    f.write('\n' % (quoteattr(k), quoteattr(v)))
            f.write("\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('' % id)
        for k, v in way['t'].items():
            f.write('\n' % (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" % (n['id'], lon * divisor, lat * divisor))
                countUsed = countUsed + 1
            else:
                countNotUsed = countNotUsed + 1
        f.write("\n")
        #print("Used %d, skipped %d" % (countUsed, countNotUsed))

    # TODO: Write the relations


    f.write("\n")
    f.close()
        


src/m/o/modrana-HEAD/modules/pyrender/tiledata.py   modrana(Download)
from urllib import *
import os
from OsmMerge import OsmMerge
 
 
                filenames.append(GetOsmTileData(lz, lx, ly))
            # merge them together
        OsmMerge(filename, z, filenames)
        return filename
 

src/r/a/rad-HEAD/pyrender/tiledata.py   rad(Download)
from urllib import *
import os
from OsmMerge import OsmMerge
 
def DownloadLevel():
          filenames.append(GetOsmTileData(lz,lx,ly))
      # merge them together
      OsmMerge(filename, z, filenames)
      print "Merge done (z=%s, filename=%s)" % (z, filename)
      return(filename)

src/m/o/modrana-HEAD/modules/pyrender/OsmTileData.py   modrana(Download)
from core.tilenames import *
from urllib import *
from OsmMerge import OsmMerge
import os
 
            # merge them together
        print("Merging tiles together")
        OsmMerge(filename, filenames)
        return filename
 

src/r/a/rad-HEAD/pyrender/OsmTileData.py   rad(Download)
from tilenames import *
from urllib import *
from OsmMerge import OsmMerge
import os
import os.path
    # merge them together
    print "Merging tiles together"
    OsmMerge(filename, filenames)
    return(filename)
 

src/m/o/modrana-HEAD/modules/pyrender/testmerge.py   modrana(Download)
from tiledata import GetOsmTileData
from OsmMerge import OsmMerge
 
 
def test(z, x, y):
            filenames.append(GetOsmTileData(lz, lx, ly))
        # merge them together
    OsmMerge("merged.osm", z, filenames)
 
 

src/r/a/rad-HEAD/pyrender/testmerge.py   rad(Download)
import os
from tiledata import GetOsmTileData
from OsmMerge import OsmMerge
 
 
      filenames.append(GetOsmTileData(lz,lx,ly))
  # merge them together
  OsmMerge("merged.osm", z, filenames)
 
if(__name__ == "__main__"):