[R-sig-Geo] problem in writing shapefiles with writePointsShape() - SKUMT!

Jeff Ranara jeff at ecology.su.se
Tue Aug 9 07:39:00 CEST 2011


Thanks Roger


-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Monday, August 08, 2011 8:45 PM
To: Jeff Ranara
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] problem in writing shapefiles with
writePointsShape() - SKUMT!

On Mon, 8 Aug 2011, Jeff Ranara wrote:

> HI again,
>
> An update:
>
> Found two workarounds:
>
> 1. Dividing MVALTARX6C and MVALTARX3C by 10000 so they're around the same
> order or magnitude as MVALTARX6 and MVALTARX3 respectively (both of which
> got written fine). Works for me since I am working with relative rankings
> and the division maintains the relative order.
>
> 2. Tried writing with writeOGR instead and it also worked!
>
> writeOGR(BRANK02_ACC, ".", "OGR_Sociotope_noBU_2003_BRNK02_AXC",
> driver="ESRI Shapefile")
>
>
> But still, the original problem is "skumt" (Swedish word meaning strange,
> odd, queer)

No, just read ?write.dbf (in foreign). You find there that the 
representation "maxes" out at 19 characters, as in DBF specs. In this 
case, a negative scale is generated, which should not happen, but the 
limitation is documented.

So your heuristics are correct, either divide the too large variable by 
some orders of magnitude to allow it to be represented within 19 digits, 
including sign and decimal point, or use the OGR implementation, which 
permits a non-standard larger precision than 19. I'll add a link to 
?write.dbf on ?writeSpatialShape.

Roger

>
> Jeff
>
> Jeff Ranara, Ph.D. candidate
> Natural Resource Management
> Dept of Systems Ecology, and
> Stockholm Resilience Center
> Stockholm University
> SE-106 91 Stockholm, Sweden
> Visiting/delivery address: Kräftriket 9A
> Tel: +46 (0)8 164252, +46 (0)73 7078874
> www.stockholmresilience.org/ranara
>
>
>
>
>
> -----Original Message-----
> From: Jeff Ranara [mailto:jeff.ranara at stockholmresilience.su.se]
> Sent: Monday, August 08, 2011 12:21 PM
> To: 'r-sig-geo at r-project.org'
> Subject: problem in writing shapefiles with writePointsShape()
>
> Hi folks,
>
> What am I missing here?  Am I using old routines? Missing some parameter?
> Mixing up object types?
>
> Am under the gun and my time-limited attempts at troubleshooting have
given
> nada.  Am testing some workarounds in the meantime.
>
> Perhaps someone knows a quick answer?
>
> ###The data of interest
>
> #> typeof(MVALTARX6C)
> #[1] "double"
> #> str(MVALTARX6C)
> # num [1:380000] NA NA NA NA NA NA NA NA NA NA ...
> #> summary(MVALTARX6C)
> #       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
> #1.38000e+07 5.33000e+12 2.68300e+13 3.65000e+14 1.42700e+14 2.37200e+16
> #       NA's
> #2.79119e+05
>
> #> typeof(MVALTARX6)
> #[1] "double"
> #> str(MVALTARX6)
> # num [1:380000] NA NA NA NA NA NA NA NA NA NA ...
> #> summary(MVALTARX6)
> #       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
> #3.69600e+03 5.95600e+08 2.41200e+09 3.65300e+10 1.74800e+10 2.08200e+12
> #       NA's
> #2.79119e+05
> #>
>
> #> typeof(MVALTARX3C)
> #[1] "double"
> #> str(MVALTARX3C)
> # num [1:380000] NA NA NA NA NA NA NA NA NA NA ...
> #> summary(MVALTARX3C)
> #       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
> #1.29500e+07 5.33900e+11 1.90900e+12 1.14200e+13 9.17500e+12 4.88700e+15
> #       NA's
> #2.79119e+05
>
> #> typeof(MVALTARX3)
> #[1] "double"
> #> str(MVALTARX3)
> # num [1:380000] NA NA NA NA NA NA NA NA NA NA ...
> #> summary(MVALTARX3)
> #       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
> #3.69600e+03 6.80000e+07 2.56900e+08 1.09700e+09 1.14600e+09 4.28400e+11
> #       NA's
> #2.79119e+05
>
> ###WRITTEN TO A SHAPEFILE WITH THE FOLLOWING
>
> new_df = cbind(BRNK01[1:13],
> MRVALTARX6,MRVALTAX6C,MRVALTARX3,MRVALTAX3C,
> RVALTARX6,RVALTARX6C,RVALTARX3,RVALTARX3C,
> BRNK01[14:16], X1000M_6AX,TX1000M_6AX,GånGAVSTån,
> MVALTARX6,MVALTARX6C,VALTARX6,VALTARX6C,
> X300M_3AX,TX300M_3AX,
> MVALTARX3,MVALTARX3C,VALTARX3,VALTARX3C,
> BRNK01[17:66])
>
> Typeof(BRNK01_SMPL25)
>
> BRANK02_ACC = BRNK01_SMPL25
> BRANK02_ACC at data = new_df
>
> writePointsShape(BRANK02_ACC, "Sociotope_noBU_2003_BRNK02_AXC",
factor2char
> = TRUE, max_nchar=254)
>
> ### VALTARX6C and MVALTARX3C end up getting written to the shapefile
> completely differently (see below). Both from inspection in ArcGIS and
> reading
> #in the shapefile again.  VALTARX6 and MVALTARX3 get written fine.
> VALTARX6C and MVALTARX3C are certainly larger values
> ##but well within the range of doubles
>
> READ_BRANK02_ACC = readShapePoints("Sociotope_noBU_2003_BRNK02_AXC")
>
>
>> BRANK02_ACC$MVALTARX6C[45:60]
> [1]           NA           NA           NA 2.005397e+12 1.513941e+12
> [6] 1.489291e+12 1.492141e+12 2.759250e+12 2.967822e+12 3.095638e+12
> [11] 4.357538e+14 4.325040e+14 4.203615e+14 3.984211e+14 3.957644e+14
> [16] 2.598429e+12
>
>> READ_BRANK02_ACC$MVALTARX6C[45:60]
> [1] NA NA NA -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
>
>> BRANK02_ACC$MVALTARX6[45:60]
> [1]          NA          NA          NA   203110878   153213098
150521517
> [7]   150521517   286549903   309324823   323817954 45747933230
45442762056
> [13] 44138848859 41808450805 41503279631   277428340
>
>> READ_BRANK02_ACC$MVALTARX6[45:60]
> [1]          NA          NA          NA   203110878   153213098
150521517
> [7]   150521517   286549903   309324823   323817954 45747933230
45442762056
> [13] 44138848859 41808450805 41503279631   277428340
>
>> BRANK02_ACC$MVALTARX3C[45:60]
> [1]           NA           NA           NA 3.475204e+10 3.477973e+10
> [6] 2.867960e+10 2.052463e+10 1.993678e+10 1.986494e+10 1.979308e+10
> [11] 2.642534e+12 2.640440e+12 2.642121e+12 2.643803e+12 2.645484e+12
> [16] 2.598429e+12'
>
>> READ_BRANK02_ACC$MVALTARX3C[45:60]
> [1]          NA          NA          NA -2147483648 -2147483648
-2147483648
> [7] -2147483648 -2147483648 -2147483648 -2147483648 -2147483648
-2147483648
> [13] -2147483648 -2147483648 -2147483648 -2147483648
>
>> BRANK02_ACC$MVALTARX3[45:60]
> [1]        NA        NA        NA   3519760   3519760   2898626   2070447
> [8]   2070447   2070447   2070447 277428340 277428340 277428340 277428340
> [15] 277428340 277428340
>>
>
>> READ_BRANK02_ACC$MVALTARX3[45:60]
> [1]        NA        NA        NA   3519760   3519760   2898626   2070447
> [8]   2070447   2070447   2070447 277428340 277428340 277428340 277428340
> [15] 277428340 277428340
>
> Ideas anyone?
>
> Thanks!
>
> Jeff
>
>
> Jeff Ranara, Ph.D. candidate
> Natural Resource Management
> Dept of Systems Ecology, and
> Stockholm Resilience Center
> Stockholm University
> SE-106 91 Stockholm, Sweden
> Visiting/delivery address: Kräftriket 9A
> Tel: +46 (0)8 164252, +46 (0)73 7078874
> www.stockholmresilience.org/ranara
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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



More information about the R-sig-Geo mailing list