[R-sig-Geo] problem writing GML file

Michael Denslow michael.denslow at gmail.com
Sun Feb 21 23:16:55 CET 2010


Hi Barry,

>> Dear r-sig-geo,
>>
>
>> 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
>
> That's weird - writeOGR looks like it should output the type and class
> of the column when it gets this problem:
>
> else stop(paste(dfcls[i], dftof[i], "unknown data type"))
>
>  - unless you're on a different version. Try running writeOGR in debug
> mode - do:
>
> debug(writeOGR)
>
> then run your writeOGR function call. Hit return to step a line at a
> time, and inspect variables. Or how about cutting some of your
> variables out and seeing what fixes it/breaks it?
>
> your sp object only seemed to have factors, numbers, and logicals and
> so writeOGR shouldnt have any problem with it...

Thanks for the advice! debug() helped me figure it out. If I
understand correctly it was because I did have a logical. As I read it
the file can't have a logical.

...
 dfcls <- sapply(slot(obj, "data"), function(x) class(x)[1])
    known <- c("numeric", "character", "factor", "POSIXt", "integer")
    if (!all(dfcls %in% known))
        stop("unknown data type")
....

When I removed the logical column it worked just fine.
Thanks again for all of your help,

Michael

> Barry
>
> --
> blog: http://geospaced.blogspot.com/
> web: http://www.maths.lancs.ac.uk/~rowlings
> web: http://www.rowlingson.com/
> twitter: http://twitter.com/geospacedman
> pics: http://www.flickr.com/photos/spacedman
>



-- 
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