[GRASS-stats] rgrass7 read/write SpatialPolygonsDataFrames errors

Eduardo Diez eduardodiez at gmx.com
Fri Oct 9 09:05:03 PDT 2015


Here are the traceback and the vInfo(zm.gnrl). The latter seems to work
fine.

> zm.fnl <- readVECT(zm.gnrl)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
 :
  line 4 did not have 2 elements
> traceback()
8: scan(file = file, what = what, sep = sep, quote = quote, dec = dec,
       nmax = nrows, skip = 0, na.strings = na.strings, quiet = TRUE,
       fill = fill, strip.white = strip.white, blank.lines.skip =
blank.lines.skip,
       multi.line = FALSE, comment.char = comment.char, allowEscapes =
allowEscapes,
       flush = flush, encoding = encoding, skipNul = skipNul)
7: read.table(con, header = FALSE, sep = "|")
6: vColumns(vname)
5: nchar(as.character(vColumns(vname)$name))
4: .read_vect_non_plugin(vname = vname, layer = layer, type = type,
       remove.duplicates = remove.duplicates, ignore.stderr =
ignore.stderr,
       pointDropZ = pointDropZ, driver = driver, with_prj = with_prj,
       with_c = with_c)
3: tryCatchList(expr, classes, parentenv, handlers)
2: tryCatch({
       stopifnot(is.logical(plugin) || is.null(plugin))
       stopifnot(is.logical(ignore.stderr))
       if (missing(layer))
           layer <- 1L
       layer <- as.character(layer)
       stopifnot(is.logical(with_c))
       if (!is.null(driver) && driver == "GRASS")
           plugin <- TRUE
       if (!requireNamespace("rgdal", quietly = TRUE)) {
           stop("rgdal not available")
       }
       if (is.null(plugin)) {
           ogrD <- rgdal::ogrDrivers()$name
           plugin <- "GRASS" %in% ogrD
       }
       if (plugin) {
           res <- .read_vect_plugin(vname = vname, layer = layer,
               type = type, ignore.stderr = ignore.stderr, pointDropZ =
pointDropZ,
               mapset = mapset)
       }
       else {
           res <- .read_vect_non_plugin(vname = vname, layer = layer,
               type = type, remove.duplicates = remove.duplicates,
               ignore.stderr = ignore.stderr, pointDropZ = pointDropZ,
               driver = driver, with_prj = with_prj, with_c = with_c)
       }
   }, finally = {
       if (get.suppressEchoCmdInFuncOption()) {
           tull <- set.echoCmdOption(inEchoCmd)
       }
   })
1: readVECT(zm.gnrl)
> vInfo(zm.gnrl)
     nodes     points      lines boundaries  centroids      areas
 islands primitives      map3d
       274          0          0        302         31         31
 3        333          0

Thanks


2015-10-09 11:36 GMT-03:00 Roger Bivand <Roger.Bivand at nhh.no>:

> If it is the v.info call, please run:
>
> res <- execGRASS("v.info", flags="t", map="zm.gnrl", layer=1L,
> intern=TRUE)
>
> and report the output of:
>
> print(res)
>
> and maybe send me offlist the output of
>
> save(res, file="vinfo_odd_output.RData")
>
> Roger
>
> --
> Roger Bivand
> Norwegian School of Economics
> Helleveien 30, 5045 Bergen, Norway
> Roger.Bivand at nhh.no
>
>
> ________________________________________
> Fra: grass-stats [grass-stats-bounces at lists.osgeo.org] på vegne av
> Roger Bivand [Roger.Bivand at nhh.no]
> Sendt: 9. oktober 2015 4:27
> Til: Eduardo Diez
> Kopi: grass-stats at lists.osgeo.org
> Emne: Re: [GRASS-stats] rgrass7 read/write SpatialPolygonsDataFrames errors
>
> OK, please provide the output of traceback() run immediately after the
> failing readVECT(). That will show which command invokes scan(). Also try
> to run vInfo(zm.gnrl) - I think the failure is in:
>
> execGRASS("v.info", flags="t", map="zm.gnrl", layer=1L)
>
> not returning a structure that vInfo understands, and which ois then used
> in readVECT().
>
> Roger
>
> --
> Roger Bivand
> Norwegian School of Economics
> Helleveien 30, 5045 Bergen, Norway
> Roger.Bivand at nhh.no
>
>
>
>
>
>
>
> Fra: diez.edu at gmail.com [diez.edu at gmail.com] på vegne av Eduardo Diez [
> eduardodiez at gmx.com]
>
> Sendt: 9. oktober 2015 4:04
>
> Til: Roger Bivand
>
> Kopi: grass-stats at lists.osgeo.org
>
> Emne: Re: [GRASS-stats] rgrass7 read/write SpatialPolygonsDataFrames errors
>
>
>
>
>
>
> 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:
>
>
>
>
> writeVECT(SDF = mz.pol, vname = zm.pol, v.in.ogr_flags = "o")
> Over-riding projection check
> Check if OGR layer <q7468fb> contains polygons...
>
>
>
> Importing 205 features (OGR layer <q7468fb>)...
>
>
>
> -----------------------------------------------------
> Registering primitives...
> 3924 primitives registered
> 12866 vertices registered
> Number of nodes: 2884
> Number of primitives: 3924
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 3924
> Number of centroids: 0
> Number of areas: -
> Number of isles: -
> -----------------------------------------------------
> Cleaning polygons
> -----------------------------------------------------
> Breaking polygons...
> Breaking polygons (pass 1: select break points)...
>
>
>
> Breaking polygons (pass 2: break at selected points)...
>
>
>
> -----------------------------------------------------
> Removing duplicates...
>
>
>
> -----------------------------------------------------
> Breaking boundaries...
>
>
>
> -----------------------------------------------------
> Removing duplicates...
>
>
>
> -----------------------------------------------------
> Cleaning boundaries at nodes...
>
>
>
> -----------------------------------------------------
> Merging boundaries...
>
>
>
> -----------------------------------------------------
> Removing dangles...
>
>
>
> -----------------------------------------------------
> Building areas...
>
>
>
> 205 areas built
> 13 isles built
> Number of nodes: 2929
> Number of primitives: 7268
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 7268
> Number of centroids: 0
> Number of areas: 205
> Number of isles: 13
> -----------------------------------------------------
> Removing bridges...
>
>
>
> -----------------------------------------------------
> Registering primitives...
> 498 primitives registered
> 5828 vertices registered
> Building areas...
>
>
>
> 205 areas built
> 13 isles built
> Attaching islands...
>
>
>
> Number of nodes: 306
> Number of primitives: 498
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 498
> Number of centroids: 0
> Number of areas: 205
> Number of isles: 13
> -----------------------------------------------------
> Finding centroids for OGR layer <q7468fb>...
>
>
>
> -----------------------------------------------------
> Writing centroids...
>
>
>
> -----------------------------------------------------
> 205 input polygons
> Total area: 1.25187E+006 (205 areas)
> -----------------------------------------------------
> Copying features...
>
>
>
> WARNING: Unable to delete file
>
>  'C:/Users/ediez1/AppData/Local/Temp/Rtmpqkeay4/file480c1e5e16a7/file480c11cc233b/.tmp/unknown/vector/tmp_8308/coor'
> Building topology for vector map <q7468fb at file480c11cc233b>...
> Registering primitives...
> 703 primitives registered
> 6033 vertices registered
> Building areas...
>
>
>
> 205 areas built
> 13 isles built
> Attaching islands...
>
>
>
> Attaching centroids...
>
>
>
> Number of nodes: 306
> Number of primitives: 703
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 498
> Number of centroids: 205
> Number of areas: 205
> Number of isles: 13
> > execGRASS("v.clean", flags = c("overwrite"), input = zm.pol,
> + output = zm.gnrl, tool = "rmarea", threshold = 3000)
> --------------------------------------------------
> Tool: Threshold
> Remove small areas: 3000
> --------------------------------------------------
> Copying features...
>
>
>
> Rebuilding parts of topology...
> Building topology for vector map <u10f44b at file480c11cc233b>...
> Registering primitives...
> 703 primitives registered
> 6033 vertices registered
> Building areas...
>
>
>
> 205 areas built
> 13 isles built
> Attaching islands...
>
>
>
> Attaching centroids...
>
>
>
> Number of nodes: 306
> Number of primitives: 703
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 498
> Number of centroids: 205
> Number of areas: 205
> Number of isles: 13
> --------------------------------------------------
> Tool: Remove small areas
>
>
>
> 174 areas of total size 50601.7 removed
> --------------------------------------------------
> Rebuilding topology for output vector map...
> Building topology for vector map <u10f44b at file480c11cc233b>...
> Registering primitives...
> 333 primitives registered
> 4705 vertices registered
> Building areas...
>
>
>
> 31 areas built
> 3 isles built
> Attaching islands...
>
>
>
> Attaching centroids...
>
>
>
> Number of nodes: 274
> Number of primitives: 333
> Number of points: 0
> Number of lines: 0
> Number of boundaries: 302
> Number of centroids: 31
> Number of areas: 31
> Number of isles: 3
> > zm.fnl <- readVECT(zm.gnrl)
>
>
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
> na.strings,  :
>   line 4 did not have 2 elements
> > sessionInfo()
> R version 3.2.2 (2015-08-14)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
>
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252    LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C                           LC_TIME=English_United
> States.1252
>
>
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>
> other attached packages:
>  [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
> [10] raster_2.4-20   rgrass7_0.1-3   XML_3.98-1.3    sp_1.2-0
>
>
>
> loaded via a namespace (and not attached):
>  [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
>  [9] e1071_1.6-7      xts_0.9-7        tools_3.2.2
>
>
>
>
> Thanks
>
>
>
>
>
>
> 2015-10-08 18:57 GMT-03:00 Roger Bivand
> <Roger.Bivand at nhh.no>:
>
>
> Sorry this has taken a long time; please try installing the development
> version available from:
>
>
>
> http://win-builder.r-project.org/8Y3Ihj451Clx
>
>
>
> (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.
>
>
>
> Before installing this development version, and after library(rgrass7),
> run example(readVECT) in the basic nc location from:
>
>
>
> https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip
>
>
>
> 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.
>
>
>
> Hope this helps,
>
>
>
> Roger
>
>
>
>
>
> --
>
> Roger Bivand
>
> Norwegian School of Economics
>
> Helleveien 30, 5045 Bergen, Norway
>
> Roger.Bivand at nhh.no
>
>
>
>
>
>
>
>
>
>
>
> Fra:
> grass-stats-bounces at lists.osgeo.org [grass-stats-bounces at lists.osgeo.org]
>  på vegne av Eduardo Diez [eduardodiez at gmx.com]
>
> Sendt: 24. september 2015 9:11
>
> Til:
> grass-stats at lists.osgeo.org
>
> Emne: [GRASS-stats] rgrass7 read/write SpatialPolygonsDataFrames errors
>
>
>
>
>
>
> 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.
>
>
>
>
>
> 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).
>
>
>
>
>
>
>
> 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.
>
> Below i paste an extract of my R console with the errors and some
> information.
>
>
>
>
>
>
>
> Thanks in advance,
>
>
>
> Eduardo
>
>
>
>
>
> > mult.rp <- projectRaster(mult.r, crs = prj.crs, method = "ngb")
>
> > mult.pol <- rasterToPolygons(mult.rp, dissolve = T)
>
>
>
> > initGRASS(gisBase = "c:/Program Files (x86)/GRASS GIS 7.0.1", home =
> tempdir(), override = T)
>
> gisdbase    C:/Users/ediez1/AppData/Local/Temp/RtmpegbyiQ
>
> location    file2f7c6dc070e6
>
> mapset      file2f7c30eb3f52
>
> rows        1
>
> columns     1
>
> north       1
>
> south       0
>
> west        0
>
> east        1
>
> nsres       1
>
> ewres       1
>
> projection  NA
>
> > writeVECT(mult.pol, "pol1", v.in.ogr_flags = "o")
>
> Error: !is.null(driver) is not TRUE
>
> > writeVECT(mult.pol, "pol1", v.in.ogr_flags = "o", driver = "ESRI
> Shapefile")
>
>
>
> Over-riding projection check
>
> Check if OGR layer <r848659> contains polygons...
>
>
>
>
>
> Importing 4 features (OGR layer <r848659>)...
>
>
>
>
>
> -----------------------------------------------------
>
> Registering primitives...
>
> 3005 primitives registered
>
> 15587 vertices registered
>
> Number of nodes: 2691
>
> Number of primitives: 3005
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 3005
>
> Number of centroids: 0
>
> Number of areas: -
>
> Number of isles: -
>
> -----------------------------------------------------
>
> Cleaning polygons
>
> -----------------------------------------------------
>
> Breaking polygons...
>
> Breaking polygons (pass 1: select break points)...
>
>
>
>
>
> Breaking polygons (pass 2: break at selected points)...
>
>
>
>
>
> -----------------------------------------------------
>
> Removing duplicates...
>
>
>
>
>
> -----------------------------------------------------
>
> Breaking boundaries...
>
>
>
>
>
> -----------------------------------------------------
>
> Removing duplicates...
>
>
>
>
>
> -----------------------------------------------------
>
> Cleaning boundaries at nodes...
>
>
>
>
>
> -----------------------------------------------------
>
> Merging boundaries...
>
>
>
>
>
> -----------------------------------------------------
>
> Removing dangles...
>
>
>
>
>
> -----------------------------------------------------
>
> Building areas...
>
>
>
>
>
> 95 areas built
>
> 8 isles built
>
> Number of nodes: 2771
>
> Number of primitives: 7307
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 7307
>
> Number of centroids: 0
>
> Number of areas: 95
>
> Number of isles: 8
>
> -----------------------------------------------------
>
> Removing bridges...
>
>
>
>
>
> -----------------------------------------------------
>
> Registering primitives...
>
> 231 primitives registered
>
> 7594 vertices registered
>
> Building areas...
>
>
>
>
>
> 95 areas built
>
> 8 isles built
>
> Attaching islands...
>
>
>
>
>
> Number of nodes: 144
>
> Number of primitives: 231
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 231
>
> Number of centroids: 0
>
> Number of areas: 95
>
> Number of isles: 8
>
> -----------------------------------------------------
>
> Finding centroids for OGR layer <r848659>...
>
>
>
>
>
> -----------------------------------------------------
>
> Writing centroids...
>
>
>
>
>
> -----------------------------------------------------
>
> 95 input polygons
>
> Total area: 1.28981E+006 (95 areas)
>
> -----------------------------------------------------
>
> Copying features...
>
>
>
>
>
> WARNING: Unable to delete file
>
>
>  'C:/Users/ediez1/AppData/Local/Temp/Rtmpg10lvi/filec2473b0126/filec24129b63ac/.tmp/unknown/vector/tmp_10484/coor'
>
> Building topology for vector map <r848659 at filec24129b63ac>...
>
> Registering primitives...
>
> 326 primitives registered
>
> 7689 vertices registered
>
> Building areas...
>
>
>
>
>
> 95 areas built
>
> 8 isles built
>
> Attaching islands...
>
>
>
>
>
> Attaching centroids...
>
>
>
>
>
> Number of nodes: 144
>
> Number of primitives: 326
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 231
>
> Number of centroids: 95
>
> Number of areas: 95
>
> Number of isles: 8
>
>
>
>
>
> > execGRASS("v.clean", flags = c("overwrite"), input = "pol1",
>
> + output = "clnpol", tool = "rmarea", threshold = 3000)
>
> --------------------------------------------------
>
> Tool: Threshold
>
> Remove small areas: 3000
>
> --------------------------------------------------
>
> Copying features...
>
>
>
>
>
> Rebuilding parts of topology...
>
> Building topology for vector map <k1f9f75 at filec24129b63ac>...
>
> Registering primitives...
>
> 326 primitives registered
>
> 7689 vertices registered
>
> Building areas...
>
>
>
>
>
> 95 areas built
>
> 8 isles built
>
> Attaching islands...
>
>
>
>
>
> Attaching centroids...
>
>
>
>
>
> Number of nodes: 144
>
> Number of primitives: 326
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 231
>
> Number of centroids: 95
>
> Number of areas: 95
>
> Number of isles: 8
>
> --------------------------------------------------
>
> Tool: Remove small areas
>
>
>
>
>
> 55 areas of total size 29487.1 removed
>
> --------------------------------------------------
>
> Rebuilding topology for output vector map...
>
> Building topology for vector map <k1f9f75 at filec24129b63ac>...
>
> Registering primitives...
>
> 212 primitives registered
>
> 6840 vertices registered
>
> Building areas...
>
>
>
>
>
> 40 areas built
>
> 4 isles built
>
> Attaching islands...
>
>
>
>
>
> Attaching centroids...
>
>
>
>
>
> Number of nodes: 136
>
> Number of primitives: 212
>
> Number of points: 0
>
> Number of lines: 0
>
> Number of boundaries: 172
>
> Number of centroids: 40
>
> Number of areas: 40
>
> Number of isles: 4
>
> > cln.pol <- readVECT("clnpol")
>
> Error: !is.null(driver) is not TRUE
>
> > cln.pol <- readVECT("clnpol", driver = "ESRI Shapefile")
>
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
> na.strings,  :
>
>   line 4 did not have 2 elements
>
>
>
>
>
> > sessionInfo()
>
> R version 3.2.2 (2015-08-14)
>
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
>
>
>
>
> locale:
>
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252    LC_MONETARY=English_United States.1252
>
> [4] LC_NUMERIC=C                           LC_TIME=English_United
> States.1252
>
>
>
>
>
> attached base packages:
>
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>
>
>
> other attached packages:
>
> [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
>
>
>
>
>
> loaded via a namespace (and not attached):
>
>  [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
>
>  [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
>
> [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
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> grass-stats mailing list
> grass-stats at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-stats
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-stats/attachments/20151009/764b7faf/attachment-0001.html>


More information about the grass-stats mailing list