[GRASS-user] Import R point dataframe as points in GRASS
Moritz Lennert
mlennert at club.worldonline.be
Fri Jun 8 07:28:22 PDT 2012
[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 at club.worldonline.be> An: Johannes
>> Radinger<JRadinger at 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
More information about the grass-user
mailing list