On Tue, 13 Jan 2009, Dylan Beaudette wrote:

On Tuesday 13 January 2009, Edzer Pebesma wrote:
This sounds very familiar; I ran into this about 6 years ago or so.

Could it be related to this ticket:

http://trac.osgeo.org/gdal/ticket/2369

Yes, exactly! I have checked with readGDAL() with GDAL 1.6.0, and the problem is resolved (in fact it defaults to int32), while the problem remains in the 1.5.* GDAL series (including 1.5.4 released last week) for the sample file in the ticket. May I add the sample file to rgdal to give an indication of this?

The next Windows binary packages will be GDAL 1.5.4, not 1.6.0 - I'm working on getting 1.6.0 to check through rgdal.

If Brian is working on something other than Windows with the CRAN binary package, upgrading GDAL will fix the problem, because rgdal will use the installed GDAL.

Roger

PS. GDAL < 1.6 can be tricked into doing the right thing by using a NODATA_value in the file that is either less than the minimum int16 or greater than the maximum int16, so with a text editor this can be a "solution". The GDAL driver is more flexible in letting you choose subscenes, etc, so this may be prefered to readAsciiGrid().


???

should be fixed in a recent GDAL build.

Cheers,

Dylan


The asciigrid driver in gdal reads the first so 100K of the file to
figure out whether the data are integer or floating point. It then
searches for a dot in any of the numbers, indicating floating point
data. If it doesn't find a floating point (g2), it assumes integer and
proceeds with that. The funny min and max values equal the min and max
value of a signed two-bytes integer, +/- 2^15. The problem is that many
images come as integer data, and what do you want gdal to do: read your
13 Mb (zipped!) first to figure out what it is, to start all over again?
This would make many other users very unhappy.

I remember filing a bug long ago.

How about putting a dot after your first value in the grid?
--
Edzer

Brian R Miranda wrote:
Roger,

Thanks for your help.  I believe you are correct that the printed summary
values have been rounded.  I couldn't quite figure out how to extract the
range specifically, but when I did a summary for the data.frame from each
grid I got what I was expecting for the one created by readAsciiGrid
(g1). However, the grid created by readGDAL (g2) still shows unexpected
min and

max values.  See results below:
d1 <- g...@data
summary(d1)

 distrail_100m.asc
 Min.   :      0
 1st Qu.:   2878
 Median :   6562
 Mean   :   7896
 3rd Qu.:  11670
 Max.   :  37082
 NA's   :6483714

d2 <- g...@data
summary(d2)

     band1
 Min.   : -32768
 1st Qu.:   2844
 Median :   6516
 Mean   :   7718
 3rd Qu.:  11600
 Max.   :  32767
 NA's   :6483714

For my own purposes, I have found that I should continue using
readAsciiGrid to bring in my grids.  But I would be happy to share my
dataset to help figure out why readGDAL has these strange results.  My
Ascii file is 13Mb zipped, probably too large to email, and I don't have
an FTP site that can be accessed outside of the Forest Service.  I can
send the file to you off list using YouSendIt.com if you would like, or
if you have an alternative suggestion for transferring the file, let me
know. Thanks again for your assistance, and if you need any additional
information from me, let me know.

Cheers,
-Brian

=======================
Brian R. Miranda
USDA Forest Service
Northern Research Station
brmira...@fs.fed.us

Institute for Applied Ecosystem Studies
5985 Highway K
Rhinelander, WI  54501
phone: 715-362-1186
fax: 715-362-1166





Roger Bivand <roger.biv...@nhh.no>
01/13/2009 02:49 PM
Please respond to
roger.biv...@nhh.no


To
Brian R Miranda <brmira...@fs.fed.us>
cc
r-sig-geo@stat.math.ethz.ch
Subject
Re: [R-sig-Geo] ESRI Ascii Grid

On Tue, 13 Jan 2009, Brian R Miranda wrote:
Hello,

I have an Ascii grid that was created using the GridAscii command in
ArcGrid.  The grid represents cell distance to railroads and has values
ranging from 0 to 37,082.  When I bring this grid into R as a
SpatialGridDataFrame, the maximum and/or the minimum values in the grid

do

not exactly match the original grid.  I have tried using both readGDAL

and

readAsciiGrid for this purpose.  I have confirmed in a text editor that
the Ascii file does contain the maximum value of 37,082.  Below are the
results I have seen.  Note the differences in the Max. value and Min.
value (from readGDAL).

First, beware of the possible difference between the printed summary
value

and the actual value - printed summaries may round. What does range() of
the variable say? The difference between the two functions is puzzling -
could you make the data available (off list for example, zipped,
preferably for download) to try to see what is going on?

Roger

g1 <- readAsciiGrid("G:/Oconto/WI_Fire/distrail_100m.asc")
summary(g1)

Object of class SpatialGridDataFrame
Coordinates:
               min      max
coords.x1 -263487.6 149512.4
coords.x2  358821.1 666821.1
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
 cellcentre.offset cellsize cells.dim
1         -263437.6      100      4130
2          358871.1      100      3080
Data attributes:
  Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
     0    2878    6562    7896   11670   37080 6483714

g2 <- readGDAL("G:/Oconto/WI_Fire/distrail_100m.asc")

G:/Oconto/WI_Fire/distrail_100m.asc has GDAL driver AAIGrid
and has 3080 rows and 4130 columns

summary(g2)

Object of class SpatialGridDataFrame
Coordinates:
       min      max
x -263487.6 149512.4
y  358821.1 666821.1
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
 cellcentre.offset cellsize cells.dim
x         -263437.6      100      4130
y          358871.1      100      3080
Data attributes:
  Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
-32770    2844    6516    7718   11600   32770 6483714

The results from readAsciiGrid are pretty close (Max = 37,080) to the
original grid, but readGDAL results in much different values.  I would
expect both functions to create an object with exactly the same values

as

the Ascii grid.  Can anyone explain why this occurs, and if there is a
different way to get my grid into R (I eventually need an 'im' to work
with)?  I am new to spatial analysis using R, so if there is something
obvious I am missing I apologize.  Thanks in advance for any help!

Cheers,
-Brian


=======================
Brian R. Miranda
USDA Forest Service
Northern Research Station
brmira...@fs.fed.us

Institute for Applied Ecosystem Studies
5985 Highway K
Rhinelander, WI  54501
phone: 715-362-1186
fax: 715-362-1166


               [[alternative HTML version deleted]]

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





--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no

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

Reply via email to