Skip to content

Instantly share code, notes, and snippets.

@devdattaT
Created October 21, 2021 10:21
Show Gist options
  • Save devdattaT/83c16228223066feb570c2e7f264f413 to your computer and use it in GitHub Desktop.
Save devdattaT/83c16228223066feb570c2e7f264f413 to your computer and use it in GitHub Desktop.
Merging OSM files
import os
#get List of files
def getFiles(fldr):
files = os.listdir(fldr)
return [os.path.join(fldr, f) for f in files]
def getFileContents(file):
lines = []
with open(file, 'r') as inpFile:
for l in inpFile:
if(not l.startswith("<?xml") and not l.startswith("<osm") and not l.startswith('</osm')):
lines.append(l)
return lines
#output file
outPut_path = 'merged.osm'
inputFiles = getFiles('osm_parts')
idx = 0
with open(outPut_path, 'w') as outFile:
outFile.write('<?xml version="1.0" encoding="UTF-8"?> <osm version="0.5" generator="shp-to-osm 0.7">')
for f in inputFiles:
idx +=1
lines = getFileContents(f)
outFile.writelines(lines)
print(idx)
outFile.write('</osm>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment