[R-sig-Geo] read in a csv with readOGR

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Apr 1 23:24:36 CEST 2010


On Thu, Apr 1, 2010 at 10:19 PM, James Stegen <stegen at 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:

 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



More information about the R-sig-Geo mailing list