Python基础地图坐标

2024-04-29 07:14:43 发布

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

我正在使用python3.6在basemap上打开Amazon河的shapefile。但是我对python中坐标的工作方式感到困惑。我查了一下亚马逊河的坐标,发现它是lon,纬度=-55.126648,-2.163106。但要打开我的地图,我需要角点的纬度/经度值,我不知道如何得到。在

以下是我目前为止的代码:

from mpl_toolkits.basemap import Basemap

import matplotlib.pyplot as plt

map= Basemap(projection='tmerc',
            lon_0=180,
            lat_0=0,
            resolution='l')
map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='#ddaa66',lake_color='aqua')
map.drawcoastlines()

map.readshapefile('filename','Amazon')
plt.show()

以下是我尝试运行它时收到的错误消息: 值错误:必须指定角点的纬度/经度值 (llcrnrlon、llcrnrlat、ucrnrlon、urcrnlat)单位为度或宽度和高度,单位为米


Tags: importmapamazon错误单位pltcolorlon
2条回答

这种类型点打印的最佳方法是通过从点“缩小”来创建自己的角点。这意味着您需要指定llcrnrlat(左下角纬度)等,如下所示:

my_coords = [38.9719980,-76.9219820]

# How much to zoom from coordinates (in degrees)
zoom_scale = 1

# Setup the bounding box for the zoom and bounds of the map
bbox = [my_coords[0]-zoom_scale,my_coords[0]+zoom_scale,\
        my_coords[1]-zoom_scale,my_coords[1]+zoom_scale]

plt.figure(figsize=(12,6))
# Define the projection, scale, the corners of the map, and the resolution.
m = Basemap(projection='merc',llcrnrlat=bbox[0],urcrnrlat=bbox[1],\
llcrnrlon=bbox[2],urcrnrlon=bbox[3],lat_ts=10,resolution='i')

如果您想查看有关从.csv文件中绘制纬度/经度点的完整教程,请查看我的教程,其中介绍了整个过程并包括完整代码:

Geographic Mapping from a CSV File Using Python and Basemap

最终得到的结果如下所示:

enter image description here

创建映射(map = Basemap(...))时,需要指定这些值。它们是左下角经度、左下角纬度、右上角经度和右上角纬度。这些定义了地图的范围。你可以画出整个地球,然后看看你想要的区域,然后从中挑选出新的角点。在

相关问题 更多 >