For posterity,

(plot3D is in fact in the rasterVis package now)

There's an adjustment factor additional to the zfac parameter. It is
impossible to override it. The solution I've found is to comment these lines
and run the function under another name (these lines are present 2 times).

#         adj <- zlen/min(ylen,xlen)
#         X <- X * adj * zfac
#         Y <- Y * adj * zfac

If you need to keep the zfac, I'd suggest to put it directly on Z.
Z <- t((getValues(x, format='matrix'))[nrow(x):1,]) * zfac

I'd be curious to hear why is the z scaling factor is applied in that
fashion.

Etienne

2011/7/7 Etienne B. Racine <etienn...@gmail.com>

> I don't know if this will clarify or add to the confusion as I don't know
> if it's the same issue or another one with the same effect, but when using a
> projected raster, I get some weird coordinates in 3d (really large). I can't
> see how it is linked to my raster coordinates.
>
> Example :
> library(raster)
> library(rgl)
> new("RasterLayer"
>     , file = new(".RasterFile"
>     , name = ""
>     , datanotation = "FLT4S"
>     , byteorder = "little"
>     , nodatavalue = -Inf
>     , nbands = 1L
>     , bandorder = "BIL"
>     , offset = 0L
>     , toptobottom = TRUE
>     , driver = ""
> )
>     , data = new(".SingleLayerData"
>     , values = c(2.7659912109375, 2.07601928710938, 1.89999389648438,
> 1.7440185546875,
> 1.6610107421875, 2.28298950195312, 3.67398071289062, 2.23001098632812,
> 2.50997924804688, 2.92999267578125, 2.22100830078125, 2.83200073242188,
> 4.6510009765625, 3.69601440429688, 3.20401000976562, 2.7750244140625,
> 2.1190185546875, 3.20901489257812, 5.39801025390625, 4.65200805664062,
> 3.69699096679688, 3.25399780273438, 1.98800659179688, 3.38198852539062,
> 5.93698120117188, 3.697021484375, 1.60000610351562, 1.60601806640625,
> 0.739013671875, 1.7080078125, 7.50399780273438, 1.34100341796875,
> 0.93597412109375, 1.01699829101562, 1.02999877929688, 0.813995361328125
> )
>     , offset = 0
>     , gain = 1
>     , inmemory = TRUE
>     , fromdisk = FALSE
>     , isfactor = FALSE
>     , attributes = list()
>     , haveminmax = TRUE
>     , min = 0.739013671875
>     , max = 7.50399780273438
>     , band = 1L
> )
>     , legend = new(".RasterLegend"
>     , type = character(0)
>     , values = NULL
>     , color = NULL
>     , names = NULL
>     , colortable = NULL
> )
>     , history = character(0)
>     , title = character(0)
>     , extent = new("Extent"
>     , xmin = 337879.000001907
>     , xmax = 337882.000001907
>     , ymin = 5386659.00000191
>     , ymax = 5386662.00000191
> )
>     , rotated = FALSE
>     , rotation = new(".Rotation"
>     , geotrans = numeric(0)
>     , transfun = function ()
> NULL
> )
>     , ncols = 6L
>     , nrows = 6L
>     , crs = new("CRS"
>     , projargs = " +proj=tmerc +lat_0=0 +lon_0=-67.5 +k=0.9999 +x_0=304800
> +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +towgs84=0,0,0"
> )
>     , layernames = "1271"
>     , z = list()
>     , zname = ""
>     , zvalue = ""
>     , unit = ""
> )
> plot(r2)
> points(337880, 5386659.5)
>
> plot3D(r2)
> decorate3d() # the coordinates are really large
> rgl.points(337880, 5386659.5, 10, col=1) # doesn't match with the raster
>
> Etienne
>
> 2011/7/7 Etienne B. Racine <etienn...@gmail.com>
>
> Hi list,
>>
>> I'd like to plot3D() a raster layer using it's own coordinates instead of
>> the row-col system so I can easily add points.
>> Here's a demo
>>
>> library(raster)
>> library(rgl)
>>
>> r <- raster(matrix(1, nrow = 5, ncol = 5))
>> extent(r)
>> # class       : Extent
>> # xmin        : 0
>> # xmax        : 1
>> # ymin        : 0
>> # ymax        : 1
>> plot(r)
>> points(0.5, 0.5) # centre of the raster
>>
>>
>> plot3D(r)
>> decorate3d()
>> rgl.points(0.5, 0.5, 1.5, col = 2) # wrong
>> rgl.points(3.5, 3.5, 1.5, col = 1) # it's row-col coordinates
>>
>> Thanks,
>> Etienne
>>
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to