Skip to content

Commit

Permalink
в базовую карту добавлена выкачка океана
Browse files Browse the repository at this point in the history
  • Loading branch information
trolleway committed Feb 2, 2020
1 parent b9628f2 commit af75bc8
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 13 deletions.
92 changes: 90 additions & 2 deletions core/process_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,105 @@ def pbf2layer(dump_path, folder, name='landuse',pbf_layer='multipolygons',where=

return 0

def bbox2ogr_clipdst(bbox):
"""
convert "29.9997,59.7816,30.6396,60.1117" to "29.9997 59.7816 30.6396 60.1117"
"""
clipdst = '{x1} {y1} {x2} {y2}'
clipdst = clipdst.format(
x1 = bbox.split(',')[0],
y1 = bbox.split(',')[1],
x2 = bbox.split(',')[2],
y2 = bbox.split(',')[3],
)
return clipdst

def download_oceans(folder,bbox):
URL='https://osmdata.openstreetmap.de/download/simplified-water-polygons-split-3857.zip'
SOURCEFILE='sea_source.zip'
export_name='oceans.gpkg'
export_name='water.gpkg'


export_filepath = os.path.join(folder,export_name)
filepath = os.path.join(folder,SOURCEFILE)

if os.path.exists(filepath) == False:
cmd = '''aria2c --dir="{dir}" --out="{file}" {dump_url}
'''
cmd = cmd.format(dir=folder,
file=os.path.basename(SOURCEFILE),
dump_url=URL,
export_filepath=export_filepath,
clipdst=bbox2ogr_clipdst(bbox))
os.system(cmd)

cmd = '''
ogr2ogr -overwrite {export_filepath} -t_srs EPSG:4326 -clipdst {clipdst} /vsizip/{dir}/{file}/simplified-water-polygons-split-3857
'''

#append oceans to water layer
cmd = '''
ogr2ogr -append {export_filepath} -nln multipolygons -t_srs EPSG:4326 -clipdst {clipdst} /vsizip/{dir}/{file}/simplified-water-polygons-split-3857
'''
cmd = cmd.format(dir=folder,
file=os.path.basename(SOURCEFILE),
dump_url=URL,
export_filepath=export_filepath,
clipdst=bbox2ogr_clipdst(bbox))
print(cmd)
os.system(cmd)

def download_land(folder,bbox):
URL='https://osmdata.openstreetmap.de/download/simplified-land-polygons-complete-3857.zip'
SOURCEFILE='land_source.zip'
export_name='land.gpkg'

export_filepath = os.path.join(folder,export_name)
filepath = os.path.join(folder,SOURCEFILE)

if os.path.exists(filepath) == False:
cmd = '''aria2c --dir="{dir}" --out="{file}" {dump_url}
'''
cmd = cmd.format(dir=folder,
file=os.path.basename(SOURCEFILE),
dump_url=URL,
export_filepath=export_filepath,
clipdst=bbox2ogr_clipdst(bbox))
os.system(cmd)

cmd = '''
ogr2ogr -overwrite {export_filepath} -t_srs EPSG:4326 -clipdst {clipdst} /vsizip/{dir}/{file}/simplified-land-polygons-complete-3857
'''
# simplified-land-polygons-complete-3857/simplified_land_polygons

cmd = cmd.format(dir=folder,
file=os.path.basename(SOURCEFILE),
dump_url=URL,
export_filepath=export_filepath,
clipdst=bbox2ogr_clipdst(bbox))
print(cmd)
os.system(cmd)




'''ogrinfo /vsizip/simplified-water-polygons-split-3857.zip/simplified-water-polygons-split-3857
ogr2ogr -overwrite ocean.gpkg -t_srs EPSG:4326 -clipdst 29.9997 59.7816 30.6396 60.1117 /vsizip/simplified-water-polygons-split-3857.zip/simplified-water-polygons-split-3857
'''

if __name__ == '__main__':


FILTERED_DUMP_NAME = 'filtered_dump.osm.pbf'
FILTERED_DUMP_NAME = 'basemap.osm.pbf'
parser = argparser_prepare()
args = parser.parse_args()

logging.basicConfig(level=logging.WARNING,format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)

logger.info('Start convert pbf to basemap layers')

Expand Down Expand Up @@ -158,3 +243,6 @@ def pbf2layer(dump_path, folder, name='landuse',pbf_layer='multipolygons',where=
where="railway is not null and railway NOT IN ('construction','proposed','razed','abandoned','disused')",
select="railway,name,bridge,tunnel"
)

download_oceans(folder=args.output, bbox = args.bbox)
download_land(folder=args.output, bbox = args.bbox)
Binary file modified qgis_project_templates/highway.gpkg
Binary file not shown.
Binary file modified qgis_project_templates/landuse.gpkg
Binary file not shown.
Binary file modified qgis_project_templates/railway.gpkg
Binary file not shown.
Binary file modified qgis_project_templates/water.gpkg
Binary file not shown.
38 changes: 33 additions & 5 deletions scripts/russia-trolleybus.poly
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,32 @@ END
34.196096 61.838527
END
1
49.166604 53.640721
49.605415 53.629191
49.588468 53.401805
49.149657 53.413397
49.166604 53.640721
49.317666 53.619548
49.696396 53.600067
49.718587 53.422678
49.381172 53.419302
49.369765 53.386997
49.106398 53.375933
49.025115 53.363666
48.916968 53.432038
48.798522 53.675969
48.973199 53.887356
49.204952 53.891706
49.232265 53.863774
49.160522 53.804546
49.091334 53.817130
49.091720 53.745869
49.077300 53.690608
49.050521 53.638532
49.029235 53.596580
49.024429 53.554587
49.043321 53.527147
49.067687 53.517043
49.147338 53.510918
49.181670 53.512552
49.193343 53.567230
49.213943 53.606359
49.317666 53.619548
END
1
49.843046 53.330904
Expand Down Expand Up @@ -91,4 +112,11 @@ END
38.019560 55.934588
38.019560 55.373649
END
1
32.148740 54.741099
31.962747 54.742038
31.964123 54.832707
32.150116 54.831769
32.148740 54.741099
END
END
15 changes: 9 additions & 6 deletions scripts/russia-trolleybus.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ def process_map(name,


#-------------
cmd = 'python3 ../core/process_basemap.py --dump_path {WORKDIR}/rus-nw.osm.pbf --bbox {bbox} --output "{WORKDIR}/" '
cmd = 'python3 ../core/process_basemap.py --dump_path {WORKDIR}/rus-nw.osm.pbf --bbox {bbox} -v --output "{WORKDIR}/" '
cmd = cmd.format(WORKDIR=WORKDIR,bbox=bbox)
os.system(cmd)


cmd = 'osmconvert "{WORKDIR}/rus-nw.osm.pbf" -b={bbox} -o="{WORKDIR}/current_city.osm.pbf"'
cmd = cmd.format(WORKDIR=WORKDIR,bbox=bbox)
os.system(cmd)
Expand All @@ -106,17 +107,19 @@ def process_map(name,
#cities.append({'name':'Petrozavodsk','bbox':'34.2809,61.7473,34.4622,61.8187','layout_extent':'''<Extent xmax="3837010.00714727956801653" xmin="3814612.03897902462631464" ymin="8800347.35082474164664745" ymax="8816184.03821748681366444"/>'''})
#cities.append({'name':'Murmansk','bbox':'32.9329,68.8745,33.2941,69.0641','layout_extent':'''<Extent xmax="3722126" xmin="3646811" ymin="10710797" ymax="10764050"/>'''})
#cities.append({'name':'Vologda','bbox':'39.6604,59.1689,40.023,59.2994','layout_extent':'''<Extent xmax="4451269" xmin="4429472" ymin="8218346" ymax="8233757"/>'''})
#cities.append({'name':'Saint-Petersburg','bbox':'29.9997,59.7816,30.6396,60.1117','layout_extent':'''<Extent xmax="3415025" xmin="3331990" ymin="8356650" ymax="8415361"/>'''})
cities.append({'name':'Tolyatti','bbox':'49.192815,53.415604,49.652226,53.597258','layout_extent':'''<Extent xmax="5513789" xmin="5479632" ymin="7067270" ymax="7091421"/>'''})
#cities.append({'name':'Карта Санкт-Петербургского троллейбуса','bbox':'29.9997,59.7816,30.6396,60.1117','layout_extent':'''<Extent xmax="3415025" xmin="3331990" ymin="8356650" ymax="8415361"/>'''})
#cities.append({'name':'Tolyatti','bbox':'49.192815,53.415604,49.652226,53.597258','layout_extent':'''<Extent xmax="5513789" xmin="5479632" ymin="7067270" ymax="7091421"/>'''})
#cities.append({'name':'Kaliningrad','bbox':'20.356018,54.6532,20.61248,54.77497','layout_extent':'''<Extent xmin="2265291" ymin="7296762" xmax="2294848" ymax="7316479"/>'''})

cities.append({'name':'Карта Тверского троллейбуса','bbox_map_3857':'3981933,7721410,4010609,7740540'})
cities.append({'name':'Карта Калининградского троллейбуса','bbox_map_3857':'2271741,7301160,2294437,7316301'})
cities.append({'name':'Карта Ярославского троллейбуса','bbox_map_3857':'4408853,7876929,4456037,7907894'})
#cities.append({'name':'Карта Тверского троллейбуса','bbox_map_3857':'3981933,7721410,4010609,7740540'})
#cities.append({'name':'Карта Калининградского троллейбуса','bbox_map_3857':'2271741,7301160,2294437,7316301'})
#cities.append({'name':'Карта Ярославского троллейбуса','bbox_map_3857':'4408853,7876929,4456037,7907894'})
#cities.append({'name':'Карта Тольяттинского троллейбуса','bbox_map_3857':'5480823,7062886,5525761,7092376'})
#cities.append({'name':'Карта Московского троллейбуса','bbox_map_3857':'4136880,7473496,4237984,7540944'})

#cities.append({'name':'Tver2','bbox':'35.402756,56.731259,36.276512,56.966690','layout_extent':'''<Extent xmax="4010077" xmin="3981401" ymin="7720806" ymax="7739936"/>'''})

cities.append({'name':'Карта Санкт-Петербургского троллейбуса','bbox_map_3857':'3334792,8357382,3417827,8415750'})


# TODO: move to core
Expand Down

0 comments on commit af75bc8

Please sign in to comment.