<div dir="ltr">Roger, with GRASS version 7.0.1 and rgrass7_0.1-3, readVECT now doesn't ask for the driver to use but gives the same error as before:<div><br></div><div><div>writeVECT(SDF = mz.pol, vname = zm.pol, v.in.ogr_flags = "o")</div><div>Over-riding projection check</div><div>Check if OGR layer <q7468fb> contains polygons...</div><div><br></div><div>Importing 205 features (OGR layer <q7468fb>)...</div><div><br></div><div>-----------------------------------------------------</div><div>Registering primitives...</div><div>3924 primitives registered</div><div>12866 vertices registered</div><div>Number of nodes: 2884</div><div>Number of primitives: 3924</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 3924</div><div>Number of centroids: 0</div><div>Number of areas: -</div><div>Number of isles: -</div><div>-----------------------------------------------------</div><div>Cleaning polygons</div><div>-----------------------------------------------------</div><div>Breaking polygons...</div><div>Breaking polygons (pass 1: select break points)...</div><div><br></div><div>Breaking polygons (pass 2: break at selected points)...</div><div><br></div><div>-----------------------------------------------------</div><div>Removing duplicates...</div><div><br></div><div>-----------------------------------------------------</div><div>Breaking boundaries...</div><div><br></div><div>-----------------------------------------------------</div><div>Removing duplicates...</div><div><br></div><div>-----------------------------------------------------</div><div>Cleaning boundaries at nodes...</div><div><br></div><div>-----------------------------------------------------</div><div>Merging boundaries...</div><div><br></div><div>-----------------------------------------------------</div><div>Removing dangles...</div><div><br></div><div>-----------------------------------------------------</div><div>Building areas...</div><div><br></div><div>205 areas built</div><div>13 isles built</div><div>Number of nodes: 2929</div><div>Number of primitives: 7268</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 7268</div><div>Number of centroids: 0</div><div>Number of areas: 205</div><div>Number of isles: 13</div><div>-----------------------------------------------------</div><div>Removing bridges...</div><div><br></div><div>-----------------------------------------------------</div><div>Registering primitives...</div><div>498 primitives registered</div><div>5828 vertices registered</div><div>Building areas...</div><div><br></div><div>205 areas built</div><div>13 isles built</div><div>Attaching islands...</div><div><br></div><div>Number of nodes: 306</div><div>Number of primitives: 498</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 498</div><div>Number of centroids: 0</div><div>Number of areas: 205</div><div>Number of isles: 13</div><div>-----------------------------------------------------</div><div>Finding centroids for OGR layer <q7468fb>...</div><div><br></div><div>-----------------------------------------------------</div><div>Writing centroids...</div><div><br></div><div>-----------------------------------------------------</div><div>205 input polygons</div><div>Total area: 1.25187E+006 (205 areas)</div><div>-----------------------------------------------------</div><div>Copying features...</div><div><br></div><div>WARNING: Unable to delete file</div><div>         'C:/Users/ediez1/AppData/Local/Temp/Rtmpqkeay4/file480c1e5e16a7/file480c11cc233b/.tmp/unknown/vector/tmp_8308/coor'</div><div>Building topology for vector map <q7468fb@file480c11cc233b>...</div><div>Registering primitives...</div><div>703 primitives registered</div><div>6033 vertices registered</div><div>Building areas...</div><div><br></div><div>205 areas built</div><div>13 isles built</div><div>Attaching islands...</div><div><br></div><div>Attaching centroids...</div><div><br></div><div>Number of nodes: 306</div><div>Number of primitives: 703</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 498</div><div>Number of centroids: 205</div><div>Number of areas: 205</div><div>Number of isles: 13</div><div>> execGRASS("v.clean", flags = c("overwrite"), input = zm.pol,</div><div>+ output = zm.gnrl, tool = "rmarea", threshold = 3000)</div><div>--------------------------------------------------</div><div>Tool: Threshold</div><div>Remove small areas: 3000</div><div>--------------------------------------------------</div><div>Copying features...</div><div><br></div><div>Rebuilding parts of topology...</div><div>Building topology for vector map <u10f44b@file480c11cc233b>...</div><div>Registering primitives...</div><div>703 primitives registered</div><div>6033 vertices registered</div><div>Building areas...</div><div><br></div><div>205 areas built</div><div>13 isles built</div><div>Attaching islands...</div><div><br></div><div>Attaching centroids...</div><div><br></div><div>Number of nodes: 306</div><div>Number of primitives: 703</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 498</div><div>Number of centroids: 205</div><div>Number of areas: 205</div><div>Number of isles: 13</div><div>--------------------------------------------------</div><div>Tool: Remove small areas</div><div><br></div><div>174 areas of total size 50601.7 removed</div><div>--------------------------------------------------</div><div>Rebuilding topology for output vector map...</div><div>Building topology for vector map <u10f44b@file480c11cc233b>...</div><div>Registering primitives...</div><div>333 primitives registered</div><div>4705 vertices registered</div><div>Building areas...</div><div><br></div><div>31 areas built</div><div>3 isles built</div><div>Attaching islands...</div><div><br></div><div>Attaching centroids...</div><div><br></div><div>Number of nodes: 274</div><div>Number of primitives: 333</div><div>Number of points: 0</div><div>Number of lines: 0</div><div>Number of boundaries: 302</div><div>Number of centroids: 31</div><div>Number of areas: 31</div><div>Number of isles: 3</div><div>> zm.fnl <- readVECT(zm.gnrl)<br></div><div>Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : </div><div>  line 4 did not have 2 elements</div><div>> sessionInfo()</div><div>R version 3.2.2 (2015-08-14)</div><div>Platform: x86_64-w64-mingw32/x64 (64-bit)</div><div>Running under: Windows 7 x64 (build 7601) Service Pack 1</div><div><br></div><div>locale:</div><div>[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252</div><div>[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    </div><div><br></div><div>attached base packages:</div><div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div><div><br></div><div>other attached packages:</div><div> [1] RPyGeo_0.9-3    RSAGA_0.94-3    plyr_1.8.3      gstat_1.0-26    shapefiles_0.7  foreign_0.8-65  maptools_0.8-37 rgdal_1.0-7     classInt_0.1-23</div><div>[10] raster_2.4-20   rgrass7_0.1-3   XML_3.98-1.3    sp_1.2-0       </div><div><br></div><div>loaded via a namespace (and not attached):</div><div> [1] Rcpp_0.12.1      intervals_0.15.1 lattice_0.20-33  FNN_1.1          spacetime_1.1-4  class_7.3-13     zoo_1.7-12       grid_3.2.2      </div><div> [9] e1071_1.6-7      xts_0.9-7        tools_3.2.2</div></div><div><br></div><div>Thanks</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-10-08 18:57 GMT-03:00 Roger Bivand <span dir="ltr"><<a href="mailto:Roger.Bivand@nhh.no" target="_blank">Roger.Bivand@nhh.no</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sorry this has taken a long time; please try installing the development version available from:<br>
<br>
<a href="http://win-builder.r-project.org/8Y3Ihj451Clx" rel="noreferrer" target="_blank">http://win-builder.r-project.org/8Y3Ihj451Clx</a><br>
<br>
(rgrass7_0.1-3.zip). The problem was the use of "_" instead of " " in the name of the OGR shapefile driver - in OGR and R it is "ESRI Shapefile", in GRASS it is "ESRI_Shapefile". Because the new long-name work-around worked on systems not needing to use this driver, it wasn't properly tested - and on Windows the GRASS standalone has OGR with the SQLite driver, but the Windows rgdal binary does not have SQLite. You may wish to install the R RSQLite package to move data if you use long field/column names.<br>
<br>
Before installing this development version, and after library(rgrass7), run example(readVECT) in the basic nc location from:<br>
<br>
<a href="https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip" rel="noreferrer" target="_blank">https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip</a><br>
<br>
it should fail. Then restart R, install the development version of rgrass7 from the first link, and repeat - it works for me and should resolve the problem.<br>
<br>
Hope this helps,<br>
<br>
Roger<br>
<br>
<br>
--<br>
Roger Bivand<br>
Norwegian School of Economics<br>
Helleveien 30, 5045 Bergen, Norway<br>
<a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a><br>
<br>
<br>
<br>
<br>
<br>
Fra: <a href="mailto:grass-stats-bounces@lists.osgeo.org">grass-stats-bounces@lists.osgeo.org</a> [<a href="mailto:grass-stats-bounces@lists.osgeo.org">grass-stats-bounces@lists.osgeo.org</a>] på vegne av Eduardo Diez [<a href="mailto:eduardodiez@gmx.com">eduardodiez@gmx.com</a>]<br>
Sendt: 24. september 2015 9:11<br>
Til: <a href="mailto:grass-stats@lists.osgeo.org">grass-stats@lists.osgeo.org</a><br>
Emne: [GRASS-stats] rgrass7 read/write SpatialPolygonsDataFrames errors<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Hi, I'm a user of R mostly for spatial information processing. Besides sp, maptools, etc. i also use functions from GRASS, at first through spgrass6 and then rgrass7. A few days ago, I started having trouble reading and writing SpatialPolygonsDataFrames using readVECT and writeVECT. I tried both reinstalling both grass (6.4.4, 7.0.0 and 7.0.1) and the R packages (spgrass6 0.8-6 and rgrass7 0.1-2), and also with different R objects but i kept getting the same errors.<br>
<br>
<br>
The "mult.r" object is a RasterLayer with 4 zones and the objective is to convert it to polygons and "clean" small areas with v.clean rmarea (as i don't currently know a way of doing this in plain R).<br>
<br>
<br>
<br>
The first thing that came out strange was that when executing writeVECT it would ask me for the driver to use (in the way of rgdal's writeOGR, it didn't ask for it before). I figured out that object to be written should be projected (not in lat-lon, don't know why). After doing this i could write the vector and execute v.clean. The problem came again when trying to read the cleaned polygons back to R.<br>
Below i paste an extract of my R console with the errors and some information.<br>
<br>
<br>
<br>
Thanks in advance,<br>
<br>
Eduardo<br>
<br>
<br>
> mult.rp <- projectRaster(mult.r, crs = prj.crs, method = "ngb")<br>
> mult.pol <- rasterToPolygons(mult.rp, dissolve = T)<br>
<br>
> initGRASS(gisBase = "c:/Program Files (x86)/GRASS GIS 7.0.1", home = tempdir(), override = T)<br>
gisdbase    C:/Users/ediez1/AppData/Local/Temp/RtmpegbyiQ<br>
location    file2f7c6dc070e6<br>
mapset      file2f7c30eb3f52<br>
rows        1<br>
columns     1<br>
north       1<br>
south       0<br>
west        0<br>
east        1<br>
nsres       1<br>
ewres       1<br>
projection  NA<br>
> writeVECT(mult.pol, "pol1", v.in.ogr_flags = "o")<br>
Error: !is.null(driver) is not TRUE<br>
> writeVECT(mult.pol, "pol1", v.in.ogr_flags = "o", driver = "ESRI Shapefile")<br>
<br>
Over-riding projection check<br>
Check if OGR layer <r848659> contains polygons...<br>
<br>
<br>
Importing 4 features (OGR layer <r848659>)...<br>
<br>
<br>
-----------------------------------------------------<br>
Registering primitives...<br>
3005 primitives registered<br>
15587 vertices registered<br>
Number of nodes: 2691<br>
Number of primitives: 3005<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 3005<br>
Number of centroids: 0<br>
Number of areas: -<br>
Number of isles: -<br>
-----------------------------------------------------<br>
Cleaning polygons<br>
-----------------------------------------------------<br>
Breaking polygons...<br>
Breaking polygons (pass 1: select break points)...<br>
<br>
<br>
Breaking polygons (pass 2: break at selected points)...<br>
<br>
<br>
-----------------------------------------------------<br>
Removing duplicates...<br>
<br>
<br>
-----------------------------------------------------<br>
Breaking boundaries...<br>
<br>
<br>
-----------------------------------------------------<br>
Removing duplicates...<br>
<br>
<br>
-----------------------------------------------------<br>
Cleaning boundaries at nodes...<br>
<br>
<br>
-----------------------------------------------------<br>
Merging boundaries...<br>
<br>
<br>
-----------------------------------------------------<br>
Removing dangles...<br>
<br>
<br>
-----------------------------------------------------<br>
Building areas...<br>
<br>
<br>
95 areas built<br>
8 isles built<br>
Number of nodes: 2771<br>
Number of primitives: 7307<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 7307<br>
Number of centroids: 0<br>
Number of areas: 95<br>
Number of isles: 8<br>
-----------------------------------------------------<br>
Removing bridges...<br>
<br>
<br>
-----------------------------------------------------<br>
Registering primitives...<br>
231 primitives registered<br>
7594 vertices registered<br>
Building areas...<br>
<br>
<br>
95 areas built<br>
8 isles built<br>
Attaching islands...<br>
<br>
<br>
Number of nodes: 144<br>
Number of primitives: 231<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 231<br>
Number of centroids: 0<br>
Number of areas: 95<br>
Number of isles: 8<br>
-----------------------------------------------------<br>
Finding centroids for OGR layer <r848659>...<br>
<br>
<br>
-----------------------------------------------------<br>
Writing centroids...<br>
<br>
<br>
-----------------------------------------------------<br>
95 input polygons<br>
Total area: 1.28981E+006 (95 areas)<br>
-----------------------------------------------------<br>
Copying features...<br>
<br>
<br>
WARNING: Unable to delete file<br>
         'C:/Users/ediez1/AppData/Local/Temp/Rtmpg10lvi/filec2473b0126/filec24129b63ac/.tmp/unknown/vector/tmp_10484/coor'<br>
Building topology for vector map <r848659@filec24129b63ac>...<br>
Registering primitives...<br>
326 primitives registered<br>
7689 vertices registered<br>
Building areas...<br>
<br>
<br>
95 areas built<br>
8 isles built<br>
Attaching islands...<br>
<br>
<br>
Attaching centroids...<br>
<br>
<br>
Number of nodes: 144<br>
Number of primitives: 326<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 231<br>
Number of centroids: 95<br>
Number of areas: 95<br>
Number of isles: 8<br>
<br>
<br>
> execGRASS("v.clean", flags = c("overwrite"), input = "pol1",<br>
+ output = "clnpol", tool = "rmarea", threshold = 3000)<br>
--------------------------------------------------<br>
Tool: Threshold<br>
Remove small areas: 3000<br>
--------------------------------------------------<br>
Copying features...<br>
<br>
<br>
Rebuilding parts of topology...<br>
Building topology for vector map <k1f9f75@filec24129b63ac>...<br>
Registering primitives...<br>
326 primitives registered<br>
7689 vertices registered<br>
Building areas...<br>
<br>
<br>
95 areas built<br>
8 isles built<br>
Attaching islands...<br>
<br>
<br>
Attaching centroids...<br>
<br>
<br>
Number of nodes: 144<br>
Number of primitives: 326<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 231<br>
Number of centroids: 95<br>
Number of areas: 95<br>
Number of isles: 8<br>
--------------------------------------------------<br>
Tool: Remove small areas<br>
<br>
<br>
55 areas of total size 29487.1 removed<br>
--------------------------------------------------<br>
Rebuilding topology for output vector map...<br>
Building topology for vector map <k1f9f75@filec24129b63ac>...<br>
Registering primitives...<br>
212 primitives registered<br>
6840 vertices registered<br>
Building areas...<br>
<br>
<br>
40 areas built<br>
4 isles built<br>
Attaching islands...<br>
<br>
<br>
Attaching centroids...<br>
<br>
<br>
Number of nodes: 136<br>
Number of primitives: 212<br>
Number of points: 0<br>
Number of lines: 0<br>
Number of boundaries: 172<br>
Number of centroids: 40<br>
Number of areas: 40<br>
Number of isles: 4<br>
> cln.pol <- readVECT("clnpol")<br>
Error: !is.null(driver) is not TRUE<br>
> cln.pol <- readVECT("clnpol", driver = "ESRI Shapefile")<br>
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :<br>
  line 4 did not have 2 elements<br>
<br>
<br>
> sessionInfo()<br>
R version 3.2.2 (2015-08-14)<br>
Platform: x86_64-w64-mingw32/x64 (64-bit)<br>
Running under: Windows 7 x64 (build 7601) Service Pack 1<br>
<br>
<br>
locale:<br>
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252<br>
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252<br>
<br>
<br>
attached base packages:<br>
[1] stats     graphics  grDevices utils     datasets  methods   base<br>
<br>
<br>
other attached packages:<br>
[1] rgrass7_0.1-2   classInt_0.1-22 maptools_0.8-36 ggplot2_1.0.1   XML_3.98-1.3    raster_2.4-20   sp_1.2-0<br>
<br>
<br>
loaded via a namespace (and not attached):<br>
 [1] Rcpp_0.12.1      magrittr_1.5     MASS_7.3-43      munsell_0.4.2    colorspace_1.2-6 lattice_0.20-33  stringr_1.0.0    plyr_1.8.3<br>
 [9] tools_3.2.2      parallel_3.2.2   rgdal_1.0-7      grid_3.2.2       gtable_0.1.2     e1071_1.6-7      class_7.3-13     rgeos_0.3-12<br>
[17] digest_0.6.8     reshape2_1.4.1   labeling_0.3     stringi_0.5-5    scales_0.3.0     foreign_0.8-65   proto_0.3-10    </div></div></blockquote></div><br></div>