[R-sig-Geo] warning at creating SpatialPolygonsDataFrame and error at saving through rgdal

Agustin Lobo alobolistas at gmail.com
Tue Nov 30 11:36:22 CET 2010


The error in wirteOGR() was caused by the long names of the variables
in the table
of the SPDF object that were listed in the warnings. Fixed by renaming
some columns in the data slot to shorter names.

The error was not related to the warnings issued at creating the SPDF
object by my function,
those were easily fixed and are of no general interest (and of particular shame)

I wonder if the error  message in writeOGR() could be more
informative. Actually, I initially discarded the long names
as the cause of the error because, according to the warning messages,
those names had been automatically truncated.

Thanks!

Agus

2010/11/29 Agustin Lobo <alobolistas at gmail.com>:
> Roger,
>
> Please find enclosed the function and 3 files such as the ones that
> are processed. Please extract the zip
> into a folder named GLIS_scenes and indicate the path in the call to the
> function.
>
> The function is run just by:
>
> source("meta2sppol.R")
> HypAr <- meta2sppol(midir="../GLIS_scenes")
>
> What I try to do is read each file, extract the 4 pairs of coordinates
> and make a SPDF with the polygons and the data
> from the files.
>
> Thanks
>
> Agus
>
> 2010/11/29 Roger Bivand <Roger.Bivand at nhh.no>:
>> On Mon, 29 Nov 2010, Agustin Lobo wrote:
>>
>>> Hi!
>>>
>>> I create a SPDF with a function
>>> HypNAr = meta2sppol()
>>>
>>> that ends up with:
>>>
>>> sitios <- 1:length(noms)
>>> row.names(datos) <- sitios
>>> SpatialPolygonsDataFrame(dummy, data=datos, match.ID = T)
>>>
>>> but get:
>>>
>>> Warning message:
>>> In data.row.names(row.names, rowsi, i) :
>>>  some row.names duplicated: 2 --> row.names NOT used
>>
>> The message is coming from data.frame() in base package. Do
>>
>> debug(meta2sppol)
>> debug(data.frame)
>> HypNAr = meta2sppol()
>>
>> and see what happens inside the data.frame() call that creates datos, which
>> is where the warning is issued (it may be inside a coercion method call,
>> such as as.data.frame()); open:
>>
>> https://svn.r-project.org/R/trunk/src/library/base/R/dataframe.R
>>
>> and search for "some row.names duplicated".
>>
>> That is, the problem is in your own function. Please also note that
>> providing a reproducible example is crucial to getting precise assistance,
>> and usually the exercise of writing such an example reveals the cause, thus
>> solving the problem more quickly.
>>
>> Roger
>>
>>>
>>> I do not understand, as I define the row names as a sequence of
>>> integers, how can they be duplicated?
>>> I can plot the SPDF and the data slot is correct, but when I try to
>>> save as shapefile:
>>>
>>>> writeOGR(HypNAr,dsn="HypNAr",layer="HypNAr",driver="ESRI
>>>> Shapefile",verbose=T)
>>>
>>> Error in writeOGR(HypNAr, dsn = "HypNAr", layer = "HypNAr", driver =
>>> "ESRI Shapefile",  :
>>>
>>>        GDAL Error 1: Invalid index : -1
>>> Calls: writeOGR -> .Call
>>> In addition: There were 11 warnings (use warnings() to see them)
>>>
>>> Is this error related to the previous warning?
>>>
>>> Thanks!
>>>
>>> Agus
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> --
>> Roger Bivand
>> Economic Geography Section, Department of Economics, Norwegian School of
>> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list