我正在与WMS连接并保存裁剪后的地图。理想情况下,我只想定义边界框(bbox
)并以像素为单位定义输出图像的高度或宽度,以获取正确的高度/宽度比。但是,如果定义高度或宽度,则会出错。当我定义输出图像的大小时,它可以正常工作
from owslib.wms import WebMapService
url = 'https://rasterdata.hunzeenaas.nl/erdas-iws/ogc/wms/Rasterdata?service=WMS&request=getmap'
wms = WebMapService(url)
img = wms.getmap( layers='Luchtfoto_2015_Ortho_25cm_RGB_voorjaarsvlucht'],
styles=['default'],
srs='EPSG:3857',
bbox=(72865, 7022456, 730231, 7023717),
size=(1000,1000),
format='image/jpeg',
transparant=True )
out = open('output.jpg', 'wb')
out.write(img.read())
out.close()
在定义边界框时如何获得正确的图像尺寸比例?
我不知道这个答案有多通用,但是看起来可以从WMS的边界框中读取正确的宽高比。如果以此比例校正尺寸,则输出图像看起来不错。
from owslib.wms import WebMapService
url = 'https://rasterdata.hunzeenaas.nl/erdas-iws/ogc/wms/Rasterdata?service=WMS&request=getmap'
wms = WebMapService(url)
# determine ratio
bbox = wms['Luchtfoto_2015_Ortho_25cm_RGB_voorjaarsvlucht'].boundingBoxWGS84
ratio = (bbox[2] - bbox[0]) / (bbox[3] - bbox[1])
img = wms.getmap( layers='Luchtfoto_2015_Ortho_25cm_RGB_voorjaarsvlucht'],
styles=['default'],
srs='EPSG:3857',
bbox=(72865, 7022456, 730231, 7023717),
size=(1000, ratio*1000),
format='image/jpeg',
transparant=True )
out = open('output.jpg', 'wb')
out.write(img.read())
out.close()