def __init__(self,output_name,mapping): driver = ogr.GetDriverByName('KML') self.files = [] self.layers = {} for t in mapping.themes: name = output_name + '_' + make_filename(t.name) if t.points: self.layers[(t.name,GeomType.POINT)] = Kml.Layer(driver,name + '_points',ogr.wkbPoint,t) self.files.append(File('kml',[name + '_points.kml'],{'theme':t.name})) if t.lines: self.layers[(t.name,GeomType.LINE)] = Kml.Layer(driver,name + '_lines',ogr.wkbLineString,t) self.files.append(File('kml',[name + '_lines.kml'],{'theme':t.name})) if t.polygons: self.layers[(t.name,GeomType.POLYGON)] = Kml.Layer(driver,name + '_polygons',ogr.wkbMultiPolygon,t) self.files.append(File('kml',[name + '_polygons.kml'],{'theme':t.name}))
def garmin(input_pbf, splitter_jar, mkgmap_jar, tempdir=None, jvm_mem=[256, 2048]): """ Converts PBF to Garmin IMG format. Splits pbf into smaller tiles, generates .img files for each split, then patches the .img files back into a single .img file suitable for deployment to a Garmin GPS unit. NOTE: disabled poly bounds: see https://github.com/hotosm/osm-export-tool2/issues/248 """ subprocess.check_call([ 'java', '-Xms{0}M'.format(jvm_mem[0]), '-Xmx{0}M'.format(jvm_mem[1]), '-jar', splitter_jar, '--output-dir=' + tempdir, input_pbf ]) # Generate the IMG file. # get the template.args file created by splitter # see: http://wiki.openstreetmap.org/wiki/Mkgmap/help/splitter subprocess.check_call([ 'java', '-Xms{0}M'.format(jvm_mem[0]), '-Xmx{0}M'.format(jvm_mem[1]), '-jar', mkgmap_jar, '--gmapsupp', '--output-dir=' + tempdir, '--description="HOT Export Garmin Map"', '--mapname=80000111', '--family-name="HOT Export Tool"', '--family-id="2"', '--series-name="HOT Export Tool"', '--index', '--route', '--generate-sea=extend-sea-sectors', '--draw-priority=100', '--unicode', '--read-config={0}/template.args'.format(tempdir) ]) return [File('garmin', [join(tempdir, 'gmapsupp.img')])]
def create_package(destination, files, boundary_geom=None, output_name='zip'): with zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED, True) as z: if boundary_geom: z.writestr("clipping_boundary.geojson", json.dumps(mapping(boundary_geom))) for file in files: for part in file.parts: z.write(part, os.path.basename(part)) return File(output_name, [destination])
def __init__(self,output_name,mapping): self.files = [] self.layers = {} for theme in mapping.themes: layer = MultiGeopackage.Layer(output_name, theme) self.files.append(File('gpkg',[output_name + '_' + make_filename(theme.name) + '.gpkg'],{'theme':theme.name})) if theme.points: self.layers[(theme.name,GeomType.POINT)] = layer if theme.lines: self.layers[(theme.name,GeomType.LINE)] = layer if theme.polygons: self.layers[(theme.name,GeomType.POLYGON)] = layer
def mwm(input_pbf, output_dir, generate_mwm_path, generator_tool_path, osmconvert_path='osmconvert'): base_name = (os.path.basename(input_pbf).split(os.extsep))[0] env = os.environ.copy() env.update(OSMCONVERT=osmconvert_path, TARGET=output_dir, GENERATOR_TOOL=generator_tool_path) subprocess.check_call([generate_mwm_path, input_pbf], env=env) return [File('mwm', [join(output_dir, base_name + '.mwm')])]
def create_posm_bundle(destination, files, title, name, description, geom): contents = {} with tarfile.open(destination, "w|gz") as bundle: for file in files: for part in file.parts: if file.output_name == 'shp': target = 'data/' + basename(part) contents[target] = {'Type': 'ESRI Shapefile'} elif file.output_name == 'kml': target = 'data/' + basename(part) contents[target] = {'Type': 'KML'} elif file.output_name == 'gpkg': target = 'data/' + basename(part) contents[target] = {'Type': 'Geopackage'} elif file.output_name == 'osmand_obf': target = 'navigation/' + basename(part) contents[target] = {'Type': 'OsmAnd'} elif file.output_name == 'garmin': target = 'navigation/' + basename(part) contents[target] = {'Type': 'Garmin IMG'} elif file.output_name == 'mwm': target = 'navigation/' + basename(part) contents[target] = {'Type': 'Maps.me'} elif file.output_name == 'osm_pbf': target = 'osm/' + basename(part) contents[target] = {'Type': 'OSM/PBF'} elif file.output_name == 'mbtiles': target = 'tiles/' + basename(part) contents[target] = { 'type': 'MBTiles', 'minzoom': file.extra['minzoom'], 'maxzoom': file.extra['maxzoom'], 'source': file.extra['source'] } bundle.add(part, target) data = json.dumps( { 'title': title, 'name': name, 'description': description, 'bbox': geom.bounds, 'contents': contents }, indent=2).encode() tarinfo = tarfile.TarInfo('manifest.json') tarinfo.size = len(data) bundle.addfile(tarinfo, io.BytesIO(data)) return File('bundle', [destination])
def __init__(self, output_name, mapping): driver = ogr.GetDriverByName('GPKG') self.ds = driver.CreateDataSource(output_name + '.gpkg') self.ds.StartTransaction() self.files = [File('gpkg', [output_name + '.gpkg'])] self.layers = {} for theme in mapping.themes: layer = Geopackage.Layer(self.ds, theme) if theme.points: self.layers[(theme.name, GeomType.POINT)] = layer if theme.lines: self.layers[(theme.name, GeomType.LINE)] = layer if theme.polygons: self.layers[(theme.name, GeomType.POLYGON)] = layer
def mbtiles(geom, filepath, tiles_url, minzoom, maxzoom): mb = landez.MBTilesBuilder( cache=False, tiles_url=tiles_url, tiles_headers={'User-Agent': 'github.com/hotosm/osm-export-tool'}, filepath=filepath) mb.add_coverage(bbox=geom.bounds, zoomlevels=[minzoom, maxzoom]) mb.run() return [ File('mbtiles', [filepath], { 'minzoom': minzoom, 'maxzoom': maxzoom, 'source': tiles_url }) ]
def osmand(input_pbf, map_creator_dir, tempdir=None, jvm_mem=[256, 2048]): BATCH_XML = """<?xml version="1.0" encoding="utf-8"?> <batch_process> <process_attributes mapZooms="" renderingTypesFile="" zoomWaySmoothness="" osmDbDialect="sqlite" mapDbDialect="sqlite"/> <!-- zoomWaySmoothness - 1-4, typical mapZooms - 11;12;13-14;15- --> <process directory_for_osm_files="{tempdir}/osmand" directory_for_index_files="{tempdir}" directory_for_generation="{tempdir}" skipExistingIndexesAt="{tempdir}" indexPOI="true" indexRouting="true" indexMap="true" indexTransport="true" indexAddress="true"> </process> </batch_process> """ CLASSPATH = "{map_creator_dir}/OsmAndMapCreator.jar:{map_creator_dir}/lib/OsmAnd-core.jar:{map_creator_dir}/lib/*.jar" pathlib.Path(join(tempdir, 'osmand')).mkdir(parents=True, exist_ok=True) try: os.link(input_pbf, join(tempdir, 'osmand', 'osmand.osm.pbf')) except: pass with open(join(tempdir, 'batch.xml'), 'w') as b: b.write(BATCH_XML.format(tempdir=tempdir)) subprocess.check_call([ 'java', '-Xms{0}M'.format(jvm_mem[0]), '-Xmx{0}M'.format(jvm_mem[1]), '-cp', CLASSPATH.format(map_creator_dir=map_creator_dir), 'net.osmand.util.IndexBatchCreator', join(tempdir, 'batch.xml') ]) return [File('osmand_obf', [join(tempdir, 'Osmand_2.obf')])]