Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > bugsDF <- readVECT6("bugsites")
- debugging in: readVECT6("bugsites")
- debug: {
- if (is.null(plugin))
- plugin <- get("plugin", envir = .GRASS_CACHE)
- stopifnot(is.logical(plugin) || is.null(plugin))
- if (is.null(ignore.stderr))
- ignore.stderr <- get("ignore.stderr", envir = .GRASS_CACHE)
- stopifnot(is.logical(ignore.stderr))
- G7 <- execGRASS("g.version", intern = TRUE) > "GRASS 7"
- if (missing(layer))
- layer <- 1L
- if (G7)
- layer <- as.character(layer)
- if (driver == "GRASS")
- plugin <- TRUE
- require(rgdal)
- if (is.null(plugin)) {
- ogrD <- ogrDrivers()$name
- plugin <- "GRASS" %in% ogrD
- }
- sss <- strsplit(packageDescription("rgdal")$Version, "-")[[1]]
- if (plugin) {
- ogrD <- ogrDrivers()$name
- if (!("GRASS" %in% ogrD))
- stop("no GRASS plugin driver")
- gg <- gmeta6()
- if (is.null(mapset)) {
- c_at <- strsplit(vname[1], "@")[[1]]
- if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- }
- else stop("malformed vector name")
- }
- dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
- vname[1], "head", sep = "/")
- if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn, layer = as.character(layer),
- verbose = !ignore.stderr, pointDropZ = pointDropZ)
- }
- else {
- res <- readOGR(dsn, layer = as.character(layer),
- verbose = !ignore.stderr)
- }
- }
- else {
- ogrD <- ogrDrivers()$name
- if (!(driver %in% ogrD))
- stop(paste("Requested driver", driver, "not available in rgdal"))
- ogrDGRASS <- execGRASS("v.in.ogr", flags = "f", intern = TRUE,
- ignore.stderr = ignore.stderr)
- ogrDGRASSs <- strsplit(ogrDGRASS, ": ")
- if (!(driver %in% sapply(ogrDGRASSs, "[", 2)))
- stop(paste("Requested driver", driver, "not available in GRASS"))
- fDrivers <- c("GML", "SQLite")
- dDrivers <- c("ESRI_Shapefile", "MapInfo_File")
- if (!(gsub(" ", "_", driver) %in% c(fDrivers, dDrivers)))
- stop(paste("Requested driver", driver, "not supported"))
- is_dDriver <- TRUE
- if (gsub(" ", "_", driver) %in% fDrivers)
- is_dDriver <- FALSE
- vinfo <- vInfo(vname)
- types <- names(vinfo)[which(vinfo > 0)]
- if (is.null(type)) {
- if (length(grep("points", types)) > 0)
- type <- "point"
- if (length(grep("lines", types)) > 0)
- type <- "line"
- if (length(grep("areas", types)) > 0)
- type <- "area"
- if (is.null(type))
- stop("Vector type not found")
- }
- pid <- as.integer(round(runif(1, 1, 1000)))
- gtmpfl1 <- dirname(execGRASS("g.tempfile", pid = pid,
- intern = TRUE, ignore.stderr = ignore.stderr))
- rtmpfl1 <- ifelse(.Platform$OS.type == "windows" && (Sys.getenv("OSTYPE") ==
- "cygwin"), system(paste("cygpath -w", gtmpfl1, sep = " "),
- intern = TRUE), gtmpfl1)
- if (driver == "ESRI Shapefile")
- shname <- substring(vname, 1, ifelse(nchar(vname) >
- 8, 8, nchar(vname)))
- flags <- NULL
- if (with_prj)
- flags <- "e"
- if (with_c)
- flags <- c(flags, "c")
- if (is_dDriver) {
- GDSN <- gtmpfl1
- RDSN <- rtmpfl1
- LAYER <- shname
- }
- else {
- GDSN <- paste(gtmpfl1, shname, sep = .Platform$file.sep)
- RDSN <- paste(rtmpfl1, shname, sep = .Platform$file.sep)
- LAYER <- shname
- }
- execGRASS("v.out.ogr", flags = flags, input = vname,
- type = type, layer = layer, dsn = GDSN, olayer = LAYER,
- format = gsub(" ", "_", driver), ignore.stderr = ignore.stderr)
- if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn = RDSN, layer = LAYER, verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- }
- else {
- res <- readOGR(dsn = rtmpfl1, layer = shname, verbose = !ignore.stderr)
- }
- if (.Platform$OS.type != "windows") {
- unlink(paste(rtmpfl1, list.files(rtmpfl1, pattern = shname),
- sep = .Platform$file.sep))
- }
- if (remove.duplicates && type != "point") {
- dups <- duplicated(slot(res, "data"))
- if (any(dups)) {
- if (length(grep("line", type)) > 0)
- type <- "line"
- if (length(grep("area", type)) > 0)
- type <- "area"
- if (type != "area" && type != "line")
- stop("try remove.duplicates=FALSE")
- ndata <- as(res, "data.frame")[!dups, , drop = FALSE]
- cand <- as.character(ndata$cat)
- cand[is.na(cand)] <- "na"
- row.names(ndata) <- cand
- if (type == "area") {
- pls <- slot(res, "polygons")
- }
- else if (type == "line") {
- pls <- slot(res, "lines")
- }
- p4s <- proj4string(res)
- IDs <- as.character(res$cat)
- IDs[is.na(IDs)] <- "na"
- tab <- table(factor(IDs))
- n <- length(tab)
- if (n + sum(dups) != length(pls))
- stop("length mismatch in duplicate removal")
- IDss <- .mixedsort(names(tab))
- reg <- match(IDs, IDss)
- belongs <- lapply(1:n, function(x) which(x ==
- reg))
- npls <- vector(mode = "list", length = n)
- for (i in 1:n) {
- nParts <- length(belongs[[i]])
- srl <- NULL
- for (j in 1:nParts) {
- plij <- pls[[belongs[[i]][j]]]
- if (type == "area") {
- plijp <- slot(plij, "Polygons")
- }
- else if (type == "line") {
- plijp <- slot(plij, "Lines")
- }
- srl <- c(srl, plijp)
- }
- if (type == "area") {
- npls[[i]] <- Polygons(srl, ID = IDss[i])
- }
- else if (type == "line") {
- npls[[i]] <- Lines(srl, ID = IDss[i])
- }
- }
- if (type == "area") {
- SP <- SpatialPolygons(npls, proj4string = CRS(p4s))
- res <- SpatialPolygonsDataFrame(SP, ndata)
- }
- else if (type == "line") {
- SP <- SpatialLines(npls, proj4string = CRS(p4s))
- res <- SpatialLinesDataFrame(SP, ndata)
- }
- }
- }
- }
- res
- }
- Browse[2]>
- debug: if (is.null(plugin)) plugin <- get("plugin", envir = .GRASS_CACHE)
- Browse[2]>
- debug: plugin <- get("plugin", envir = .GRASS_CACHE)
- Browse[2]>
- debug: stopifnot(is.logical(plugin) || is.null(plugin))
- Browse[2]>
- debug: if (is.null(ignore.stderr)) ignore.stderr <- get("ignore.stderr",
- envir = .GRASS_CACHE)
- Browse[2]>
- debug: ignore.stderr <- get("ignore.stderr", envir = .GRASS_CACHE)
- Browse[2]>
- debug: stopifnot(is.logical(ignore.stderr))
- Browse[2]>
- debug: G7 <- execGRASS("g.version", intern = TRUE) > "GRASS 7"
- Browse[2]>
- debug: if (missing(layer)) layer <- 1L
- Browse[2]>
- debug: layer <- 1L
- Browse[2]>
- debug: if (G7) layer <- as.character(layer)
- Browse[2]>
- debug: layer <- as.character(layer)
- Browse[2]>
- debug: if (driver == "GRASS") plugin <- TRUE
- Browse[2]>
- debug: NULL
- Browse[2]>
- debug: require(rgdal)
- Browse[2]>
- debug: if (is.null(plugin)) {
- ogrD <- ogrDrivers()$name
- plugin <- "GRASS" %in% ogrD
- }
- Browse[2]>
- debug: {
- ogrD <- ogrDrivers()$name
- plugin <- "GRASS" %in% ogrD
- }
- Browse[2]>
- debug: ogrD <- ogrDrivers()$name
- Browse[2]>
- debug: plugin <- "GRASS" %in% ogrD
- Browse[2]>
- debug: sss <- strsplit(packageDescription("rgdal")$Version, "-")[[1]]
- Browse[2]>
- debug: if (plugin) {
- ogrD <- ogrDrivers()$name
- if (!("GRASS" %in% ogrD))
- stop("no GRASS plugin driver")
- gg <- gmeta6()
- if (is.null(mapset)) {
- c_at <- strsplit(vname[1], "@")[[1]]
- if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- }
- else stop("malformed vector name")
- }
- dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
- vname[1], "head", sep = "/")
- if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- }
- else {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
- }
- } else {
- ogrD <- ogrDrivers()$name
- if (!(driver %in% ogrD))
- stop(paste("Requested driver", driver, "not available in rgdal"))
- ogrDGRASS <- execGRASS("v.in.ogr", flags = "f", intern = TRUE,
- ignore.stderr = ignore.stderr)
- ogrDGRASSs <- strsplit(ogrDGRASS, ": ")
- if (!(driver %in% sapply(ogrDGRASSs, "[", 2)))
- stop(paste("Requested driver", driver, "not available in GRASS"))
- fDrivers <- c("GML", "SQLite")
- dDrivers <- c("ESRI_Shapefile", "MapInfo_File")
- if (!(gsub(" ", "_", driver) %in% c(fDrivers, dDrivers)))
- stop(paste("Requested driver", driver, "not supported"))
- is_dDriver <- TRUE
- if (gsub(" ", "_", driver) %in% fDrivers)
- is_dDriver <- FALSE
- vinfo <- vInfo(vname)
- types <- names(vinfo)[which(vinfo > 0)]
- if (is.null(type)) {
- if (length(grep("points", types)) > 0)
- type <- "point"
- if (length(grep("lines", types)) > 0)
- type <- "line"
- if (length(grep("areas", types)) > 0)
- type <- "area"
- if (is.null(type))
- stop("Vector type not found")
- }
- pid <- as.integer(round(runif(1, 1, 1000)))
- gtmpfl1 <- dirname(execGRASS("g.tempfile", pid = pid, intern = TRUE,
- ignore.stderr = ignore.stderr))
- rtmpfl1 <- ifelse(.Platform$OS.type == "windows" && (Sys.getenv("OSTYPE") ==
- "cygwin"), system(paste("cygpath -w", gtmpfl1, sep = " "),
- intern = TRUE), gtmpfl1)
- if (driver == "ESRI Shapefile")
- shname <- substring(vname, 1, ifelse(nchar(vname) > 8,
- 8, nchar(vname)))
- flags <- NULL
- if (with_prj)
- flags <- "e"
- if (with_c)
- flags <- c(flags, "c")
- if (is_dDriver) {
- GDSN <- gtmpfl1
- RDSN <- rtmpfl1
- LAYER <- shname
- }
- else {
- GDSN <- paste(gtmpfl1, shname, sep = .Platform$file.sep)
- RDSN <- paste(rtmpfl1, shname, sep = .Platform$file.sep)
- LAYER <- shname
- }
- execGRASS("v.out.ogr", flags = flags, input = vname, type = type,
- layer = layer, dsn = GDSN, olayer = LAYER, format = gsub(" ",
- "_", driver), ignore.stderr = ignore.stderr)
- if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn = RDSN, layer = LAYER, verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- }
- else {
- res <- readOGR(dsn = rtmpfl1, layer = shname, verbose = !ignore.stderr)
- }
- if (.Platform$OS.type != "windows") {
- unlink(paste(rtmpfl1, list.files(rtmpfl1, pattern = shname),
- sep = .Platform$file.sep))
- }
- if (remove.duplicates && type != "point") {
- dups <- duplicated(slot(res, "data"))
- if (any(dups)) {
- if (length(grep("line", type)) > 0)
- type <- "line"
- if (length(grep("area", type)) > 0)
- type <- "area"
- if (type != "area" && type != "line")
- stop("try remove.duplicates=FALSE")
- ndata <- as(res, "data.frame")[!dups, , drop = FALSE]
- cand <- as.character(ndata$cat)
- cand[is.na(cand)] <- "na"
- row.names(ndata) <- cand
- if (type == "area") {
- pls <- slot(res, "polygons")
- }
- else if (type == "line") {
- pls <- slot(res, "lines")
- }
- p4s <- proj4string(res)
- IDs <- as.character(res$cat)
- IDs[is.na(IDs)] <- "na"
- tab <- table(factor(IDs))
- n <- length(tab)
- if (n + sum(dups) != length(pls))
- stop("length mismatch in duplicate removal")
- IDss <- .mixedsort(names(tab))
- reg <- match(IDs, IDss)
- belongs <- lapply(1:n, function(x) which(x == reg))
- npls <- vector(mode = "list", length = n)
- for (i in 1:n) {
- nParts <- length(belongs[[i]])
- srl <- NULL
- for (j in 1:nParts) {
- plij <- pls[[belongs[[i]][j]]]
- if (type == "area") {
- plijp <- slot(plij, "Polygons")
- }
- else if (type == "line") {
- plijp <- slot(plij, "Lines")
- }
- srl <- c(srl, plijp)
- }
- if (type == "area") {
- npls[[i]] <- Polygons(srl, ID = IDss[i])
- }
- else if (type == "line") {
- npls[[i]] <- Lines(srl, ID = IDss[i])
- }
- }
- if (type == "area") {
- SP <- SpatialPolygons(npls, proj4string = CRS(p4s))
- res <- SpatialPolygonsDataFrame(SP, ndata)
- }
- else if (type == "line") {
- SP <- SpatialLines(npls, proj4string = CRS(p4s))
- res <- SpatialLinesDataFrame(SP, ndata)
- }
- }
- }
- }
- Browse[2]>
- debug: {
- ogrD <- ogrDrivers()$name
- if (!("GRASS" %in% ogrD))
- stop("no GRASS plugin driver")
- gg <- gmeta6()
- if (is.null(mapset)) {
- c_at <- strsplit(vname[1], "@")[[1]]
- if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- }
- else stop("malformed vector name")
- }
- dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
- vname[1], "head", sep = "/")
- if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- }
- else {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
- }
- }
- Browse[2]>
- debug: ogrD <- ogrDrivers()$name
- Browse[2]>
- debug: if (!("GRASS" %in% ogrD)) stop("no GRASS plugin driver")
- Browse[2]>
- debug: NULL
- Browse[2]>
- debug: gg <- gmeta6()
- Browse[2]>
- debug: if (is.null(mapset)) {
- c_at <- strsplit(vname[1], "@")[[1]]
- if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- }
- else stop("malformed vector name")
- }
- Browse[2]>
- debug: {
- c_at <- strsplit(vname[1], "@")[[1]]
- if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- }
- else stop("malformed vector name")
- }
- Browse[2]>
- debug: c_at <- strsplit(vname[1], "@")[[1]]
- Browse[2]>
- debug: if (length(c_at) == 1) {
- mapset <- .g_findfile(vname[1], type = "vector")
- } else if (length(c_at) == 2) {
- mapset <- c_at[2]
- vname[1] <- c_at[1]
- } else stop("malformed vector name")
- Browse[2]>
- debug: {
- mapset <- .g_findfile(vname[1], type = "vector")
- }
- Browse[2]>
- debug: mapset <- .g_findfile(vname[1], type = "vector")
- Browse[2]>
- debug: dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
- vname[1], "head", sep = "/")
- Browse[2]>
- debug: if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- } else {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
- }
- Browse[2]>
- debug: {
- res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- }
- Browse[2]>
- debug: res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
- pointDropZ = pointDropZ)
- Browse[2]>
- GRASS 7.0.svn (spearfish70):~ >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement