[GRASS-user] Import R point dataframe as points in GRASS

Hi,

I have a R data.frame containing around 60 columns, two of them are X and Y respectively. What is the recommended way to get these "points" imported into GRASS?

Maybe the simplest way is to save the data.frame as csv and then use v.in.ascii in GRASS. I tried to do that and specified the columns for x and y and skipped the first line (header in the csv). The import works fine and all points are correctly imported but I miss the attribute names in the attribute table (header in the csv). Maybe I have just overseen this feature to use the header from the csv as attribute names... or is this just not possible?

Or is there any other resp. better way to get points from R into GRASS? E.g. I could store them as spatial.points.data.frame in R but is there a native GRASS-format I could use for exporting/saving in R?

any suggestions are welcome!

/Johannes
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

Hi,

You can do that using the library spgrass6.
First you have to start Grass into the Mapset in which you wanna put your vector map, then start R inside Grass and call the library spgrass6, convert your data frame to a spatial points data frame:

temp_spatial ← SpatialPointsDataFrame(coords,data)

Finally, move your spatial data frame to your Mapset:

writeVECT6(temp_spatial,“map_name_in_grass”,v.in.ogr_flags=c(“o”,“overwrite”))

On Fri, Jun 8, 2012 at 7:44 AM, Johannes Radinger <JRadinger@gmx.at> wrote:

Hi,

I have a R data.frame containing around 60 columns, two of them are X and Y respectively. What is the recommended way to get these “points” imported into GRASS?

Maybe the simplest way is to save the data.frame as csv and then use v.in.ascii in GRASS. I tried to do that and specified the columns for x and y and skipped the first line (header in the csv). The import works fine and all points are correctly imported but I miss the attribute names in the attribute table (header in the csv). Maybe I have just overseen this feature to use the header from the csv as attribute names… or is this just not possible?

Or is there any other resp. better way to get points from R into GRASS? E.g. I could store them as spatial.points.data.frame in R but is there a native GRASS-format I could use for exporting/saving in R?

any suggestions are welcome!

/Johannes

NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


David Montoya González
Ing. Forestal, Universidad Nacional de Colombia
Laboratorio de Sistemas Complejos, UNAL Medellin

[Sorry, I failed to keep the discussion on the list. Here we are back
again ;-)]

On 08/06/12 15:27, Johannes Radinger wrote:

-------- Original-Nachricht --------

Datum: Fri, 08 Jun 2012 14:55:13 +0200 Von: Moritz
Lennert<mlennert@club.worldonline.be> An: Johannes
Radinger<JRadinger@gmx.at> Betreff: Re: [GRASS-user] Import R point
dataframe as points in GRASS

On 08/06/12 14:44, Johannes Radinger wrote:

Hi,

I have a R data.frame containing around 60 columns, two of them
are X and Y respectively. What is the recommended way to get
these "points" imported into GRASS?

Maybe the simplest way is to save the data.frame as csv and then
use v.in.ascii in GRASS. I tried to do that and specified the
columns for x and y and skipped the first line (header in the
csv). The import works fine and all points are correctly imported
but I miss the attribute names in the attribute table (header in
the csv). Maybe I have just overseen this feature to use the
header from the csv as attribute names... or is this just not
possible?

Or is there any other resp. better way to get points from R into
GRASS? E.g. I could store them as spatial.points.data.frame in R
but is there a native GRASS-format I could use for
exporting/saving in R?

You can:

- use the columns parameter in v.in.ascii to define column names
and types

- use the foreign package in R to export to dbf and v.in.db to
import the resulting dbf file.

- use spgrass6 to create a link between GRASS and R, massage your
data into a spatial dataframe and use writeVECT6 to write the map
to GRASS.

I decided to to it with the spgrass6 library. The import/export is
working but the attribute names are truncated due to the default ESRI
Shapefile Driver: :warning: In writeOGR(SDF, dsn = RDSN, layer =
LAYER, driver = driver) : Field names abbreviated for ESRI Shapefile
driver

As I am not that familiar with all the drivers available
(ogrDrivers()) I don't know if there is any driver which is working
and uses the complete names.

SQLite ? GML ?

So far as I know also the writeDBF()
truncates column names to 11 characters....

Yes, by definition, the DBF format does not allow longer field names.

Moritz

On Fri, Jun 8, 2012 at 2:44 PM, Johannes Radinger <JRadinger@gmx.at> wrote:

Hi,

I have a R data.frame containing around 60 columns, two of them are X and Y respectively. What is the recommended way to get these "points" imported into GRASS?

Maybe the simplest way is to save the data.frame as csv and then use v.in.ascii in GRASS. I tried to do that and specified the columns for x and y and skipped the first line (header in the csv). The import works fine and all points are correctly imported but I miss the attribute names in the attribute table (header in the csv). Maybe I have just overseen this feature to use the header from the csv as attribute names... or is this just not possible?

As others mentioned already, you can define column names and types
with v.in.ascii columns=... But you could also open a ticket to
request an enhancement to v.in.ascii. The module can already
automatically determine the column type. It should not be too
difficult to add a new option to read column names from line X, e.g.
names=1 to read column names from line 1.

Markus M

Or is there any other resp. better way to get points from R into GRASS? E.g. I could store them as spatial.points.data.frame in R but is there a native GRASS-format I could use for exporting/saving in R?

any suggestions are welcome!

/Johannes
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user