使用Python按特定形状文件剪切图像

2024-09-27 18:07:46 发布

您现在位置:Python中文网/ 问答频道 /正文

背景

我尝试过用Python语言从DEMIS服务器下载地形图。在

我写的代码如下:

## Downloding terrain image of Northeastern Asia
llx,lly, urx,ury = [102,25,147,57]    
target = 'http://www2.demis.nl/wms/wms.asp?Service=WMS&WMS=worldmap&Version=1.1.0&Request=GetMap&BBox=%s,%s,%s,%s'%(llx,lly, urx,ury) +\
         '&SRS=EPSG:4326&Width=1600&Height=1200&Layers=Bathymetry,Countries,Topography,Ocean%20features,Hillshading,Borders,Waterbodies,Coastlines&Format=image/gif'
path_name = './INPUT/Northeastern_Asia.gif'
urllib.urlretrieve(target, path_name)      

然后我可以用Matplotlib.Basemap enter image description here

想法

上面的代码提供了一种简单的方法来获得特定正方形空间的地形图,并预先确定了拐角位置。在

如果我想用一个shapefile来剪切原始图形(用红色勾勒),用Python可以实现吗?在

enter image description here

我已经上传了原始图像和目标区域的形状文件。如果你有兴趣,任何建议都将不胜感激。在


Tags: path代码nameimagetargetgifurxwms

热门问题