[R-sig-Geo] problem writing GML file
Michael Denslow
michael.denslow at gmail.com
Sun Feb 21 22:28:03 CET 2010
Dear r-sig-geo,
I am having a problem writing a GML file. The file I am trying to use
is a .csv that looks like this. I apologize that I am not sure how to
efficiently post this file to the list.
> str(floras)
'data.frame': 86 obs. of 47 variables:
$ ref.num : Factor w/ 85 levels "10132","10185",..:
69 29 35 48 60 23 67 68 8 59 ...
$ Flora : Factor w/ 76 levels " LaVerne Smith
1977",..: 41 67 40 4 34 47 73 71 33 69 ...
$ Short.Name : Factor w/ 86 levels "Andrews Bald",..:
55 7 18 48 9 39 68 38 40 79 ...
$ Field.Year : int 2006 1972 1984 1987 1969 1978 2003
2003 1915 1994 ...
$ State : Factor w/ 2 levels "NC","SC": 1 1 1 1 1
1 1 1 1 1 ...
$ State2 : Factor w/ 6 levels
"","GA","NC","SC",..: 1 1 1 1 1 1 1 1 1 1 ...
$ State3 : Factor w/ 2 levels "","SC": 1 1 1 1 1 1
1 1 1 1 ...
$ County1 : Factor w/ 43 levels "","Alleghany",..:
3 3 23 4 2 39 20 16 20 15 ...
$ County2 : Factor w/ 26 levels
"","`","Alleghany",..: 1 1 1 1 1 4 1 1 1 1 ...
$ County3 : Factor w/ 13 levels "","Brunswick",..:
1 1 1 1 1 1 1 1 1 1 ...
$ County4 : Factor w/ 7 levels "","Cumberland",..:
1 1 1 1 1 1 1 1 1 1 ...
$ County5 : Factor w/ 3 levels "","Blount, TN",..:
1 1 1 1 1 1 1 1 1 1 ...
$ Families : int 108 88 97 91 71 76 101 85 95 52 ...
$ FamCalc : int NA 110 111 98 77 85 NA NA NA NA ...
$ Genera : int 381 348 327 272 197 222 305 223 336 81 ...
$ GeneraCalc : int NA 368 344 284 207 232 NA NA NA NA ...
$ species : int 695 677 596 430 328 355 519 346 659 106 ...
$ spp.Calc : int 696 693 590 426 327 353 NA NA NA NA ...
$ taxa : int 702 681 604 431 333 355 521 353 665 107 ...
$ native.sp : int 537 589 534 375 302 317 440 280 620 104 ...
$ exotic.sp : int 158 88 62 55 26 38 79 66 39 2 ...
$ exotic.taxa..if.different.: int NA NA NA NA NA NA NA NA NA NA ...
$ per.exotics.sp : num 22.73 13 10.4 12.79 7.93 ...
$ lat.cent.N : num 36.4 36.4 35.1 36 36.4 ...
$ long.cent.W : num -81.5 -81.6 -83.5 -81.8 -81.1 ...
$ min.lat.s : num 36.4 36.4 35 36 36.4 ...
$ max.lat.n : num 36.4 36.4 35.1 36.1 36.5 ...
$ max.long.e : num -81.5 -81.5 -83.4 -81.8 -81 ...
$ min.long.w : num -81.5 -81.6 -83.5 -81.9 -81.1 ...
$ min.elev : num 1067 1050 670 549 484 ...
$ max.elev : num 1427 1522 1575 1219 1227 ...
$ mid.elev : num 1247 1286 1122 884 856 ...
$ elev.range : num 361 472 905 671 743 ...
$ area.ha : num 368 2849 1626 2308 484 ...
$ physio : Factor w/ 3 levels "CP","MT","PD": 2 2
2 2 2 2 2 3 2 2 ...
$ tax.concept : Factor w/ 36 levels "","?RAB","Britton
& Brown 1896?, Chapman 1897",..: 33 21 22 30 21 21 14 14 4 34 ...
$ prim.herb : Factor w/ 21 levels "","BOON","Carl
Sandburg Home NHS",..: 2 9 20 8 10 10 3 7 4 20 ...
$ other.herbaria : Factor w/ 18 levels
"","BRP-NPS","DUKE",..: 1 15 1 1 1 1 1 1 7 1 ...
$ political : Factor w/ 7 levels
"","county","military",..: 5 6 5 5 6 6 5 5 2 5 ...
$ preserve.type : Factor w/ 18 levels "","Botanical",..:
11 1 4 5 1 1 7 7 1 8 ...
$ pub.type : Factor w/ 8 levels
"","Book","Dissertation",..: 7 5 4 7 7 5 6 6 5 5 ...
$ Vouchers : int 1167 NA NA NA NA NA NA NA NA NA ...
$ Entered. : Factor w/ 2 levels "","Y": 2 2 2 2 2 2
1 1 1 1 ...
$ Stats. : Factor w/ 2 levels "","Y": 2 2 2 2 2 2
2 2 2 2 ...
$ Bib.Checked : Factor w/ 3 levels "","N","Y": 3 3 3 3
3 3 3 3 3 3 ...
$ island : logi NA NA NA NA NA NA ...
$ Notes : Factor w/ 33 levels "","A few taxa were
excluded from counts because they were labeled as cultivated. The
Supplement (Sieren 1982b) does not include ne"| __truncated__,..: 1 24
1 1 17 19 28 1 1 20 ...
I was able to make a SpatialPointsDataFrame just fine with the
following commands.
> library(rgdal)
> coordinates(floras) = c('long.cent.W','lat.cent.N')
> class(floras)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
but when I run writeOGR, I get an error
> writeOGR(floras,paste(getwd(),'florasTEST.gml',sep='/'),'floras', driver = 'GML')
Error in writeOGR(floras, paste(getwd(), "florasTEST.gml", sep = "/"), :
unknown data type
I am not sure why this is not working. I suspect that there may be a
problem with my file since it has many rows and columns with no
values. But...
The following reproducible example does work without problems.
library(rgdal)
ex <- data.frame(fl = LETTERS[1:4],
lat = c(36.4, 36.3908, 35.055, 36.0226),
long = c(-81.4614, -81.5717, -83.455, -81.8264),
d = c('','blah','blah',''))
coordinates(ex) = c('long','lat')
class(ex)
plot(ex)
# it works!
writeOGR(ex,paste(getwd(),'flTEST.gml',sep='/'),'fl', driver = 'GML')
# and can be read back in
fl <- readOGR(dsn = paste(getwd(),'flTEST.gml',sep='/'), layer = 'fl')
plot(fl)
Any advise would be most appreciated,
Michael
> sessionInfo()
R version 2.10.1 (2009-12-14)
x86_64-apple-darwin9.8.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_0.6-20 sp_0.9-44
loaded via a namespace (and not attached):
[1] grid_2.10.1 lattice_0.17-26 tools_2.10.1
--
Michael Denslow
I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.
-- AND --
Communications Manager
Southeast Regional Network of Expertise and Collections
sernec.org
36.214177, -81.681480 +/- 3103 meters
More information about the R-sig-Geo
mailing list