On Thu, 1 Apr 2010, Barry Rowlingson wrote:
On Thu, Apr 1, 2010 at 10:19 PM, James Stegen <ste...@email.unc.edu> wrote:
I am trying to read-in a .csv file that has two columns, one for longitude
and one for latitude to then overlay on a raster map that I am reading in
with readGDAL.
I read in the raster as:
test = readGDAL("tmean1.bil")
This seems to work fine.
I then try to read in the csv file as:
coord = readOGR("Lat_Long_105.csv",layer="Lat_Long_105")
, but I get this out
Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding =
input_field_name_encoding) :
Multiple # dimensions:
It's unclear to me if I am totally missing the boat when I try to read in
the csv file. In particular, dsn is also the layer (i.e. there is only one
file).
Do I need something else for the layer?
Read it into a non-spatial, ordinary, common-or-garden dataframe with
'read.csv'. Then give it coordinates, something like:
While this is the standard answer, you can also create a *.vrt file to
accompany your csv file, as described in:
http://www.gdal.org/ogr/drv_csv.html
For larger projects, this means that the OGR driver will read the data
successfully. With just the *.csv file, however, go though read.csv() or
read.csv2(); in some cases in some locales, read.csv2() may be the only
option, as explained on the CSV driver help page.
Roger
thing = read.csv("thing.csv")
coordinates(thing)=~long+lat
then by magic you'll have a spatial points data frame
that's assuming your column names in 'thing' are long and lat for X
and Y coords. You might also want to set a CRS too, so it knows what
coordinate system it is (probably WGS 84...)
Barry
_______________________________________________
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