[R-sig-Geo] SpatialPointsDataFrame into GRASS problems

stephen sefick ssefick at gmail.com
Tue Aug 3 14:19:11 CEST 2010


I am new to sp objects and this seems more convienint than qgis ->
shapefile -> import into GRASS.  I am having a problem getting the
data from a spatial points dataframe into grass.  Below is the code.
Any help would be appreciated.

z <- (dput(ftbr_UTM)
structure(list(site = c("Jennie_Creek_Main_Stem", "Jennie_Creek_Main_Stem",
"Wolf_Pit_Creek_Main_Stem", "Wolf_Pit_Creek_Main_Stem",
"Little_Rockfish_Main_Stem_North",
"Little_Rockfish_Main_Stem_North", "Big_Muddy_Creek_Main_Stem",
"Big_Muddy_Creek_Main_Stem", "Flat_Creek_Main_Stem", "Flat_Creek_Main_Stem",
"little_river_tributary", "little_river_tributary", "Hector_Creek_Main_Stem",
"Hector_Creek_Main_Stem", "Juniper_Creek_Main_Stem", "Juniper_Creek_Main_Stem",
"Field_Branch_Main_Stem", "Field_Branch_Main_Stem", "Gum_Branch_Main_Stem",
"Gum_Branch_Main_Stem"), base = c("ftbr", "ftbr", "ftbr", "ftbr",
"ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr",
"ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr", "ftbr"
), creek = c("jcms", "jcms", "wpms", "wpms", "lrf1", "lrf1",
"bmcm", "bmcm", "fcms", "fcms", "lrtb", "lrtb", "hcms", "hcms",
"jpms", "jpms", "fbms", "fbms", "gbms", "gbms"), date = c("06/20/2010",
"06/20/2010", "06/20/2010", "06/20/2010", "06/18/2010", "06/18/2010",
"06/18/2010", "06/18/2010", "06/21/2010", "06/21/2010", "06/22/2010",
"06/22/2010", "06/22/2010", "06/22/2010", "06/21/2010", "06/21/2010",
"06/19/2010", "06/19/2010", "06/19/2010", "06/19/2010"), elevation_m = c(101,
101, 81, 81, 59, 59, 75, 75, 73, 73, 55, 55, 55, 55, 88, 88,
77, 77, 87, 87), x = c(652159, 652040, 651646, 651533, 674147,
674116, 635466, 635326, 665726, 665676, 675295, 675362, 673098,
673159, 658917, 658918, 655613, 655464, 651748, 651553), y = c(3887647,
3887758, 3886986, 3886870, 3893724, 3893581, 3876272, 3876145,
3893886, 3893742, 3895529, 3895663, 3895076, 3895261, 3882474,
3882663, 3881587, 3881591, 3884249, 3884280), station = c(1,
6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6), notes_ = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA)), .Names = c("site", "base", "creek", "date", "elevation_m",
"x", "y", "station", "notes_"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20")))


utm2points <- function(data, x_coord="x", y_coord="y", coord_string=NULL){

#utm 17
#+proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs

#utm 16
#+proj=utm +zone=16 +ellps=GRS80 +units=m +no_defs

require(rgdal)

#get x y
coord <- c(x_coord, y_coord)
x_y <- data[,charmatch(coord, colnames(data))]

#get everything else
dater <- data[,-charmatch(coord, colnames(data))]

#make Spatial Data Frame
Point_vector <- SpatialPointsDataFrame(x_y, dater, proj4string =
CRS(coord_string))
return(Point_vector)
}


z <- utm2points(ftbr_UTM, coord_string="+proj=utm +zone=17
+ellps=GRS80 +units=m +no_defs")


#and then I try to import this into GRASS with

writeVECT6(z, "ftbr_2010_sampling_points")

#and get the following error

Error in writeOGR(SDF, dsn = rtmpfl1, layer = shname, driver = "ESRI
Shapefile") :

	GDAL Error 1: Invalid index : -1
In addition: Warning message:
In writeOGR(SDF, dsn = rtmpfl1, layer = shname, driver = "ESRI Shapefile") :

	Non-fatal GDAL Error 6: Normalized/laundered field name:
'elevation_m' to 'elevation_'




-- 
Stephen Sefick
____________________________________
| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___________________________________|
| sas0025 at auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___________________________________|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis



More information about the R-sig-Geo mailing list