Commit be5eae2f authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

enabling tiles from wms geoserver

parent 6fd4ebc1
from typing import Dict
import pandas as pd
import os
from osmaug.osm.map import make_bbox, load_map, map2png, png2jpg
from osmaug.osm.map import map_wms_source, make_bbox, load_map, map2png, png2jpg
def getosm_function(params: Dict):
driver_bin = params['driver_bin']
workdir = os.path.join(params['workdir'])
zoom = params['zoom']
source = params['source']
if source['type'] == "wms":
wms_source = map_wms_source(source['url'],source['layers'],source['fmt'],source['transparent'],source['cql_filter'])
else:
wms_source = None
resdir = os.path.join(params['resdir'])
if not os.path.exists(resdir):
os.mkdir(resdir)
zoom = params['zoom']
points = pd.DataFrame.from_dict(params['points'], orient='columns')
for index, row in points.iterrows():
print("-> "+row['ID'])
tmp = make_bbox(row['coords'],row['conv_crs'],row['delta_meters'])
file = os.path.join(resdir,row['ID']+'_zoom_'+str(zoom)+'.html')
load_map(tmp,zoom,file)
file = os.path.join(resdir,str(row['ID'])+'_'+str(source['name'])+'_zoom_'+str(zoom)+'.html')
load_map(tmp,wms_source,zoom,file)
tmp_png = map2png(file, 5, driver_bin)
tmp_jpg = png2jpg(tmp_png)
os.remove(file)
......
from pyproj import Proj
import time
from folium import Map
from folium import Map, WmsTileLayer
from selenium import webdriver
from PIL import Image
import pandas as pd
# [59.92773,10.84633]
def make_bbox(coords,crs,delta_meters):
......@@ -20,15 +21,29 @@ def make_bbox(coords,crs,delta_meters):
return(res)
# bbox=[59.8,10.7, 60.0, 10.8]
def load_map(bbox,zoom,file):
def map_wms_source(url,layers,fmt,transparent,cql_filter):
res = pd.DataFrame(columns=['url','layers','fmt','transparent','cql_filter'])
res = res.append({'url': url, 'layers': layers, 'fmt':fmt,'transparent':transparent,'cql_filter':cql_filter},ignore_index=True)
return(res)
def load_map(bbox,wms_source,zoom,file):
"""
Load OSM leaflet and save it.
Load tiles and save it.
"""
# lat/long
center=[bbox[0]+(bbox[2]-bbox[0])/2,bbox[1]+(bbox[3]-bbox[1])/2]
bounds=[[bbox[0],bbox[1]],[bbox[2],bbox[3]]]
# get map
m = Map(center, control_scale=True, zoom_start=zoom)
if wms_source is not None:
tv_adtLayer = WmsTileLayer(
url = wms_source['url'][0],
layers = wms_source['layers'][0],
fmt = wms_source['fmt'][0],
transparent = wms_source['transparent'][0],
cql_filter = wms_source['cql_filter'][0])
tv_adtLayer.add_to(m)
m.fit_bounds(bounds, max_zoom=zoom)
m.save(file)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment