简体   繁体   中英

WMS get optimal size ratio upon defining bounding box

I'm connecting with a WMS and saving a cropped map. Ideally I would like to just define the bounding box ( bbox ) and define either the height or width of the output image in pixels, to get the correct height/width ratio. However, I'm getting errors if I define the height or width. It's working when I define the size of the output image

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()

How do I get the correct image size ratio, while defining the bounding box?

I don't know how generic this answer is, but it looks like the correct width/height ratio can be read from the bounding box of the WMS. Correcting the size of the output image with this ratio will lead to the desired result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM