如何从x y UTM值中获取光栅矩阵中正确的col和row值?

时间:2019-02-02 19:21:04

标签: r r-raster rgl

我试图呈现使用rayshader包功能的文本render_label

我的光栅在WGS84 UTM:

localtif = raster::raster("G:\\My Drive\\Dem_12m.tif")

Link to download the raster.

在仰角矩阵:

elmat = matrix(raster::extract(localtif,raster::extent(localtif),buffer=1000),
               nrow=ncol(localtif),ncol=nrow(localtif))

我RGL渲染:

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat,zscale=3,maxsearch = 300),0.5) %>%
  add_shadow(ambmat,0.5) %>%
  plot_3d(elmat,zscale=10,fov=0,theta=135,zoom=0.75,phi=45, windowsize = c(1000,800))

从x和y utm坐标获取行号和列号:

  xy<-rowColFromCell(localtif, extract(localtif,SpatialPoints(cbind( 678349.471, 9197957.733)), cellnumbers=TRUE)[1])

渲染文本:

  render_label(elmat,x=xy[2],y=xy[1], z=4000,zscale=50,
             text = "El Pico del Diablo",textsize = 10,linewidth = 5, freetype = F)

在DEM模型错误的地方的文本apeear。我得到了这些xy值:

> xy
     row col
[1,] 611 278 

使用反复试验,我发现正确的值是row = 180和col =278。我还收到此警告:

Warning message:
In rgl.texts(x = 278L, y = 103.72, z = -611L, text = "El Pico del Diablo",  :
  "bitmap" family only supports cex = 1

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并找到了解决方案。

我对您的代码进行了如下修改:

from pyspark.mllib.linalg.distributed import IndexedRow, IndexedRowMatrix

rdd = dfcon.rdd.map(tuple)
mymatrix = IndexedRowMatrix(rdd.map(lambda row: IndexedRow(row[0], row[1:]))).toBlockMatrix().transpose().toIndexedRowMatrix()
mysimilarities = mymatrix.columnSimilarities()

就我而言,我的经度位置是负数。

El_Pico_del_Diablo <- data.frame(lat= X.XX, long= -XX.XX) ###latitude and longitude in decimals.