[R-sig-Geo] Problem with writeOGR()

Michael Sumner mdsumner at gmail.com
Thu Nov 5 00:07:00 CET 2009


My guess is that it's the logical column.

Try

gpsori1$UTM.Ch <- as.character(gpsori1$UTM.Ch)
writeOGR(gpsori1, dsn="MATA20090729",
layer="MATA20090729gps1",driver="ESRI Shapefile")


On Thu, Nov 5, 2009 at 9:35 AM, Agustin Lobo <aloboaleu at gmail.com> wrote:
> Thanks,
> No POSIXct fields:
>> summary(gpsori1)
> Object of class SpatialPointsDataFrame
> Coordinates:
>              min     max
> coords.x1  453020  457145
> coords.x2 4623500 4625866
> Is projected: NA
> proj4string : [NA]
> Number of points: 2096
> Data attributes:
>       No            UTM.Zone   UTM.Ch           UTM.East
>  Min.   :   1.0   Min.   :31   Mode:logical   Min.   :453020
>  1st Qu.: 524.8   1st Qu.:31   TRUE:2096      1st Qu.:453601
>  Median :1048.5   Median :31   NA's:0         Median :454140
>  Mean   :1048.5   Mean   :31                  Mean   :454418
>  3rd Qu.:1572.2   3rd Qu.:31                  3rd Qu.:455120
>  Max.   :2096.0   Max.   :31                  Max.   :457145
>
>   UTM.North          Altitude            Date            Time
>  Min.   :4623500   Min.   :1648   2009/07/29:2095   08:49:04:   3
>  1st Qu.:4624886   1st Qu.:1795   2009/07/30:   1   08:49:05:   2
>  Median :4625170   Median :1821                     08:49:06:   2
>  Mean   :4625068   Mean   :1835                     08:49:07:   2
>  3rd Qu.:4625338   3rd Qu.:1885                     08:49:08:   2
>  Max.   :4625866   Max.   :1952                     08:49:09:   2
>                                                    (Other) :2083
>> str(gpsori1)
> Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
>  ..@ data       :'data.frame': 2096 obs. of  8 variables:
>  .. ..$ No       : int [1:2096] 1 2 3 4 5 6 7 8 9 10 ...
>  .. ..$ UTM.Zone : int [1:2096] 31 31 31 31 31 31 31 31 31 31 ...
>  .. ..$ UTM.Ch   : logi [1:2096] TRUE TRUE TRUE TRUE TRUE TRUE ...
>  .. ..$ UTM.East : int [1:2096] 453245 453245 453245 453245 453245 453245
> 453245 453245 453245 453245 ...
>  .. ..$ UTM.North: int [1:2096] 4625338 4625338 4625338 4625338 4625338
> 4625338 4625338 4625338 4625338 4625338 ...
>  .. ..$ Altitude : num [1:2096] 1648 1648 1648 1648 1648 ...
>  .. ..$ Date     : Factor w/ 2 levels "2009/07/29","2009/07/30": 1 1 1 1 1 1
> 1 1 1 1 ...
>  .. ..$ Time     : Factor w/ 1452 levels "08:23:05","08:23:07",..: 1 2 3 4 5
> 6 7 8 9 10 ...
>  ..@ coords.nrs : num(0)
>  ..@ coords     : num [1:2096, 1:2] 453245 453245 453245 453245 453245 ...
>  .. ..- attr(*, "dimnames")=List of 2
>  .. .. ..$ : NULL
>  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
>  ..@ bbox       : num [1:2, 1:2] 453020 4623500 457145 4625866
>  .. ..- attr(*, "dimnames")=List of 2
>  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
>  .. .. ..$ : chr [1:2] "min" "max"
>  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
>  .. .. ..@ projargs: chr NA
>> class(gpsori1$Date)
> [1] "factor"
>> class(gpsori1$Time)
> [1] "factor"
>
> After your message I thought it could be because of the factors, but the
> following does not work either:
>
>> gpsori1  <-
>> read.table("MATA20090729/MATA20090729_1.csv",sep=",",header=T,stringsAsFactors
>> =F)> coordinates(gpsori1) <- cbind(gpsori1$UTM.East, gpsori1$UTM.North)
>> writeOGR(gpsori1, dsn="MATA20090729",
>> layer="MATA20090729gps1",driver="ESRI Shapefile")
> Error in writeOGR(gpsori1, dsn = "MATA20090729", layer = "MATA20090729gps1",
>  :
>  unknown data type
>
>> summary(gpsori1)
> Object of class SpatialPointsDataFrame
> Coordinates:
>              min     max
> coords.x1  453020  457145
> coords.x2 4623500 4625866
> Is projected: NA
> proj4string : [NA]
> Number of points: 2096
> Data attributes:
>       No            UTM.Zone   UTM.Ch           UTM.East
>  Min.   :   1.0   Min.   :31   Mode:logical   Min.   :453020
>  1st Qu.: 524.8   1st Qu.:31   TRUE:2096      1st Qu.:453601
>  Median :1048.5   Median :31   NA's:0         Median :454140
>  Mean   :1048.5   Mean   :31                  Mean   :454418
>  3rd Qu.:1572.2   3rd Qu.:31                  3rd Qu.:455120
>  Max.   :2096.0   Max.   :31                  Max.   :457145
>   UTM.North          Altitude        Date               Time
>  Min.   :4623500   Min.   :1648   Length:2096        Length:2096
>  1st Qu.:4624886   1st Qu.:1795   Class :character   Class :character
>  Median :4625170   Median :1821   Mode  :character   Mode  :character
>  Mean   :4625068   Mean   :1835
>  3rd Qu.:4625338   3rd Qu.:1885
>  Max.   :4625866   Max.   :1952
>
> Perhaps the NA for proj4string ?
>
> Agus
>
>
> Michael Sumner wrote:
>>
>> Hi Agustin, you will need to determine which columns in the data frame
>> are causing problems.
>>
>> Can you run this and let us know what you see?
>>
>> summary(gpsori1)
>>
>> For example, you cannot write POSIXct columns to SHP and would need to
>> convert to text, or numeri:
>>
>> library(rgdal)
>> d <- data.frame(x = 1:10, y = 1:10, z = 1:10)
>> coordinates(d) <- ~x+y
>>
>> ## OK
>> writeOGR(d, ".", "test", "ESRI Shapefile")
>> unlink("test.shp")
>>
>> d$z <- Sys.time() + 1:10
>> ## not OK
>> writeOGR(d, ".", "test", "ESRI Shapefile")
>>
>>
>> Regards, Mike.
>>
>>
>>
>> On Thu, Nov 5, 2009 at 7:11 AM, Agustin Lobo <alobolistas at gmail.com>
>> wrote:
>>>
>>> I'm puzzled with this:
>>>
>>>> class(gpsori1)
>>>
>>> [1] "SpatialPointsDataFrame"
>>> attr(,"package")
>>> [1] "sp"
>>>>
>>>> writeOGR(gpsori1, dsn="CAST20090907",
>>>> layer="CAST20090907gps1",driver="ESRI Shapefile")
>>>
>>> Error in writeOGR(gpsori1, dsn = "CAST20090907", layer =
>>> "CAST20090907gps1",
>>>  :
>>>  unknown data type
>>>
>>> Am I doing something wrong or is there a recent change that I'm not aware
>>> of?
>>>
>>> Thanks
>>>
>>> Agus
>>>
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>
>
> --
> Dr. Agustin Lobo
> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
> LLuis Sole Sabaris s/n
> 08028 Barcelona
> Spain
> Tel. 34 934095410
> Fax. 34 934110012
> email: Agustin.Lobo at ija.csic.es
> http://www.ija.csic.es/gt/obster
>



More information about the R-sig-Geo mailing list