将地块坐标转换为地理坐标 [英] Convert plot co-ords to geographic co-ords
问题描述
我能够根据纬度和经度绘制数据点图,如下所示:
,使用代码:
m =底图( projection ='merc',llcrnrlat = -0.5,urcrnrlat = 0.5,\
llcrnrlon = 9,urcrnrlon = 10,lat_ts = 0.25,resolution ='i')
m.drawcoastlines()
m.drawcountries()
#绘制平行线和子午线。
parallels = np.arange(-9。,10.,0.5)
#标记子午线和平行线
m.drawparallels(parallels,labels = [False,True,True,False] )
#绘制子午线和标签
子午线= np.arange(-1。,1.,0.5)
m.drawmeridians(子午线,标签= [True,False,False,True] )
m.drawmapboundary(fill_color ='white')
x,y = m(X,Y)#这是将数据转换为地图投影的步骤
scatter = plt.scatter (x,y)
m.scatter(x,y)
其中X和Y是numpy数组。
我想获取单击点的X和Y坐标。
我可以使用以下方法获得坐标:
coords = []
def onclick(event):
if plt.get_current_fig_manager()。toolbar.mode!='':
返回
全局坐标
ix,iy = event.x,event.y
打印('x =%d,y =%d'%(ix,iy))
全局坐标
coords.append((ix,iy))
返回坐标
cid = fig.canvas.mpl_connect('button_press_event',onclick)
plt.show()
但这似乎返回了图形坐标。有没有办法将它们转换成各自的经纬度坐标?
然后我计划使用它们在原始X和Y数组中找到我单击的位置最近的点
首先,您想使用数据坐标
ix,iy = event.xdata,event.ydata
然后要获得lon / lat坐标,您需要应用反函数地图变换
lon,lat = m(event.xdata,event.ydata,inverse = True)
I am able to make a plot of data points based on their Lat and Long, which looks like:
whereby the orange is made up of points like:
using the code:
m = Basemap(projection='merc',llcrnrlat=-0.5,urcrnrlat=0.5,\
llcrnrlon=9,urcrnrlon=10,lat_ts=0.25,resolution='i')
m.drawcoastlines()
m.drawcountries()
# draw parallels and meridians.
parallels = np.arange(-9.,10.,0.5)
# Label the meridians and parallels
m.drawparallels(parallels,labels=[False,True,True,False])
# Draw Meridians and Labels
meridians = np.arange(-1.,1.,0.5)
m.drawmeridians(meridians,labels=[True,False,False,True])
m.drawmapboundary(fill_color='white')
x,y = m(X, Y) # This is the step that transforms the data into the map's projection
scatter = plt.scatter(x,y)
m.scatter(x,y)
where X and Y are numpy arrays.
I want to get the X and Y co-ordinate of a point that I click on.
I can get the co-ord using:
coords = []
def onclick(event):
if plt.get_current_fig_manager().toolbar.mode != '':
return
global coords
ix, iy = event.x, event.y
print('x = %d, y = %d'%(ix, iy))
global coords
coords.append((ix, iy))
return coords
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
but this seems to return the figure co-ordinates. Is there a way to convert these to their respective lat and long co-ordinates?
I then plan to use these to find the nearest point in the original X and Y arrays to where I click
First of all you would want to use the data coordinates
ix, iy = event.xdata, event.ydata
Then to get lon/lat coordinates you need to apply the inverse map transform
lon, lat = m(event.xdata, event.ydata, inverse=True)
这篇关于将地块坐标转换为地理坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!