底图 - 值必须介于-90,90度之间

时间:2016-10-24 00:01:46

标签: python matplotlib-basemap

目的

  • 将GIS,shapefile(县界)上传到Basemap
  • 使用底图绘制县界
  • 确定某个位置是否属于“边界”
  • 为某个点指定权重,具体取决于它们属于哪个边界
  • 使用DBSCAN根据坐标和权重发现群集中心

APPROACH

使用this tutorial on Basemap,上传shapefile进行映射。

#First, we have to import our datasets. 
#These datasets include store locations, existing distribution locations, county borders, and real estate by county
walmartStores = pd.read_csv("data/walmart-stores.csv",header=0, encoding='latin1')
propertyValues = pd.read_csv("data/property values.csv")
shp = fiona.open('data/boundaries/Counties.shp')


#We need to create a workable array with Walmart Stores
longitude = walmartStores.longitude
latitude = walmartStores.latitude
stores = np.column_stack((longitude, latitude))

#We also need to load the shape file for county boundaries
extra = 0.1 
bds = shp.bounds 
shp.close()

#We need to assign the lower-left bound and upper-right bound
ll = (bds[0], bds[1])
ur = (bds[2], bds[3])


#concatenate the lower left and upper right into a variable called coordinates
coords = list(chain(ll, ur))
print(coords)

#define variables for the width and the height of the map
w, h = coords[2] - coords[0], coords[3] - coords[1]

print(coords) = [105571.4206781257, 4480951.235680977, 779932.0626624253, 4985476.422250552]

到目前为止一切顺利,但我遇到了以下问题:

m = Basemap(
    #set projection to 'tmerc' to minimize map distortion
    projection='tmerc',

    #set longitude as average of lower, upper longitude bounds
    lon_0 = np.average([bds[0],bds[2]]),

    #set latitude as average of lower,upper latitude bounds
    lat_0 = np.average([bds[1],bds[3]]),

    #string describing ellipsoid (‘GRS80’ or ‘WGS84’, for example). 
    #Not sure what this does...
    ellps = 'WGS84',

    #set the map boundaries. Note that we use the extra variable to provide a 10% buffer around the map
    llcrnrlon=coords[0] - extra * w,
    llcrnrlat=coords[1] - extra + 0.01 * h,
    urcrnrlon=coords[2] + extra * w,
    urcrnrlat=coords[3] + extra + 0.01 * h,

    #provide latitude of 'true scale.' 
    #check the Basemap API
    lat_ts=0,

    #resolution of boundary database to use. Can be c (crude), l (low), i (intermediate), h (high), f (full) or None.
    resolution='i',

    #don't show the axis ticks automatically
    suppress_ticks = False)


m.readshapefile(
    #provide the path to the shapefile, but leave off the .shp extension
    'data/boundaries/Counties.shp',

    #name your map something useful (I named this 'srilanka')
    'nyCounties',

    #set the default shape boundary coloring (default is black) and the zorder (layer order)
    color='none',
    zorder=2)
  

错误:lat_0必须介于-90.000000和90.000000之间

问题

  1. lat_0和lon_0不在-90和90之间。但是,lon_0不会抛出错误。为什么会这样?
  2. 我在网上看到面临类似问题的其他人,并且空手而归。我的笔记本有什么独特之处吗? (注意:conda list显示`basemap 1.0.7,所以我知道它已安装并正在运行
  3. 谢谢!

1 个答案:

答案 0 :(得分:0)

纬度只能在-90到90之间 - 其他任何事情都没有意义。北极为+90,南极为-90,赤道为0.没有其他可接受的值!

关于经度,它只能在-180和180之间.0是在Prime Meridian并且到-180(向西)和+180(向东)