Advertisement
Guest User

readVECT6 debug output

a guest
Mar 6th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.95 KB | None | 0 0
  1. > bugsDF <- readVECT6("bugsites")
  2. debugging in: readVECT6("bugsites")
  3. debug: {
  4. if (is.null(plugin))
  5. plugin <- get("plugin", envir = .GRASS_CACHE)
  6. stopifnot(is.logical(plugin) || is.null(plugin))
  7. if (is.null(ignore.stderr))
  8. ignore.stderr <- get("ignore.stderr", envir = .GRASS_CACHE)
  9. stopifnot(is.logical(ignore.stderr))
  10. G7 <- execGRASS("g.version", intern = TRUE) > "GRASS 7"
  11. if (missing(layer))
  12. layer <- 1L
  13. if (G7)
  14. layer <- as.character(layer)
  15. if (driver == "GRASS")
  16. plugin <- TRUE
  17. require(rgdal)
  18. if (is.null(plugin)) {
  19. ogrD <- ogrDrivers()$name
  20. plugin <- "GRASS" %in% ogrD
  21. }
  22. sss <- strsplit(packageDescription("rgdal")$Version, "-")[[1]]
  23. if (plugin) {
  24. ogrD <- ogrDrivers()$name
  25. if (!("GRASS" %in% ogrD))
  26. stop("no GRASS plugin driver")
  27. gg <- gmeta6()
  28. if (is.null(mapset)) {
  29. c_at <- strsplit(vname[1], "@")[[1]]
  30. if (length(c_at) == 1) {
  31. mapset <- .g_findfile(vname[1], type = "vector")
  32. }
  33. else if (length(c_at) == 2) {
  34. mapset <- c_at[2]
  35. vname[1] <- c_at[1]
  36. }
  37. else stop("malformed vector name")
  38. }
  39. dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
  40. vname[1], "head", sep = "/")
  41. if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  42. res <- readOGR(dsn, layer = as.character(layer),
  43. verbose = !ignore.stderr, pointDropZ = pointDropZ)
  44. }
  45. else {
  46. res <- readOGR(dsn, layer = as.character(layer),
  47. verbose = !ignore.stderr)
  48. }
  49. }
  50. else {
  51. ogrD <- ogrDrivers()$name
  52. if (!(driver %in% ogrD))
  53. stop(paste("Requested driver", driver, "not available in rgdal"))
  54. ogrDGRASS <- execGRASS("v.in.ogr", flags = "f", intern = TRUE,
  55. ignore.stderr = ignore.stderr)
  56. ogrDGRASSs <- strsplit(ogrDGRASS, ": ")
  57. if (!(driver %in% sapply(ogrDGRASSs, "[", 2)))
  58. stop(paste("Requested driver", driver, "not available in GRASS"))
  59. fDrivers <- c("GML", "SQLite")
  60. dDrivers <- c("ESRI_Shapefile", "MapInfo_File")
  61. if (!(gsub(" ", "_", driver) %in% c(fDrivers, dDrivers)))
  62. stop(paste("Requested driver", driver, "not supported"))
  63. is_dDriver <- TRUE
  64. if (gsub(" ", "_", driver) %in% fDrivers)
  65. is_dDriver <- FALSE
  66. vinfo <- vInfo(vname)
  67. types <- names(vinfo)[which(vinfo > 0)]
  68. if (is.null(type)) {
  69. if (length(grep("points", types)) > 0)
  70. type <- "point"
  71. if (length(grep("lines", types)) > 0)
  72. type <- "line"
  73. if (length(grep("areas", types)) > 0)
  74. type <- "area"
  75. if (is.null(type))
  76. stop("Vector type not found")
  77. }
  78. pid <- as.integer(round(runif(1, 1, 1000)))
  79. gtmpfl1 <- dirname(execGRASS("g.tempfile", pid = pid,
  80. intern = TRUE, ignore.stderr = ignore.stderr))
  81. rtmpfl1 <- ifelse(.Platform$OS.type == "windows" && (Sys.getenv("OSTYPE") ==
  82. "cygwin"), system(paste("cygpath -w", gtmpfl1, sep = " "),
  83. intern = TRUE), gtmpfl1)
  84. if (driver == "ESRI Shapefile")
  85. shname <- substring(vname, 1, ifelse(nchar(vname) >
  86. 8, 8, nchar(vname)))
  87. flags <- NULL
  88. if (with_prj)
  89. flags <- "e"
  90. if (with_c)
  91. flags <- c(flags, "c")
  92. if (is_dDriver) {
  93. GDSN <- gtmpfl1
  94. RDSN <- rtmpfl1
  95. LAYER <- shname
  96. }
  97. else {
  98. GDSN <- paste(gtmpfl1, shname, sep = .Platform$file.sep)
  99. RDSN <- paste(rtmpfl1, shname, sep = .Platform$file.sep)
  100. LAYER <- shname
  101. }
  102. execGRASS("v.out.ogr", flags = flags, input = vname,
  103. type = type, layer = layer, dsn = GDSN, olayer = LAYER,
  104. format = gsub(" ", "_", driver), ignore.stderr = ignore.stderr)
  105. if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  106. res <- readOGR(dsn = RDSN, layer = LAYER, verbose = !ignore.stderr,
  107. pointDropZ = pointDropZ)
  108. }
  109. else {
  110. res <- readOGR(dsn = rtmpfl1, layer = shname, verbose = !ignore.stderr)
  111. }
  112. if (.Platform$OS.type != "windows") {
  113. unlink(paste(rtmpfl1, list.files(rtmpfl1, pattern = shname),
  114. sep = .Platform$file.sep))
  115. }
  116. if (remove.duplicates && type != "point") {
  117. dups <- duplicated(slot(res, "data"))
  118. if (any(dups)) {
  119. if (length(grep("line", type)) > 0)
  120. type <- "line"
  121. if (length(grep("area", type)) > 0)
  122. type <- "area"
  123. if (type != "area" && type != "line")
  124. stop("try remove.duplicates=FALSE")
  125. ndata <- as(res, "data.frame")[!dups, , drop = FALSE]
  126. cand <- as.character(ndata$cat)
  127. cand[is.na(cand)] <- "na"
  128. row.names(ndata) <- cand
  129. if (type == "area") {
  130. pls <- slot(res, "polygons")
  131. }
  132. else if (type == "line") {
  133. pls <- slot(res, "lines")
  134. }
  135. p4s <- proj4string(res)
  136. IDs <- as.character(res$cat)
  137. IDs[is.na(IDs)] <- "na"
  138. tab <- table(factor(IDs))
  139. n <- length(tab)
  140. if (n + sum(dups) != length(pls))
  141. stop("length mismatch in duplicate removal")
  142. IDss <- .mixedsort(names(tab))
  143. reg <- match(IDs, IDss)
  144. belongs <- lapply(1:n, function(x) which(x ==
  145. reg))
  146. npls <- vector(mode = "list", length = n)
  147. for (i in 1:n) {
  148. nParts <- length(belongs[[i]])
  149. srl <- NULL
  150. for (j in 1:nParts) {
  151. plij <- pls[[belongs[[i]][j]]]
  152. if (type == "area") {
  153. plijp <- slot(plij, "Polygons")
  154. }
  155. else if (type == "line") {
  156. plijp <- slot(plij, "Lines")
  157. }
  158. srl <- c(srl, plijp)
  159. }
  160. if (type == "area") {
  161. npls[[i]] <- Polygons(srl, ID = IDss[i])
  162. }
  163. else if (type == "line") {
  164. npls[[i]] <- Lines(srl, ID = IDss[i])
  165. }
  166. }
  167. if (type == "area") {
  168. SP <- SpatialPolygons(npls, proj4string = CRS(p4s))
  169. res <- SpatialPolygonsDataFrame(SP, ndata)
  170. }
  171. else if (type == "line") {
  172. SP <- SpatialLines(npls, proj4string = CRS(p4s))
  173. res <- SpatialLinesDataFrame(SP, ndata)
  174. }
  175. }
  176. }
  177. }
  178. res
  179. }
  180. Browse[2]>
  181. debug: if (is.null(plugin)) plugin <- get("plugin", envir = .GRASS_CACHE)
  182. Browse[2]>
  183. debug: plugin <- get("plugin", envir = .GRASS_CACHE)
  184. Browse[2]>
  185. debug: stopifnot(is.logical(plugin) || is.null(plugin))
  186. Browse[2]>
  187. debug: if (is.null(ignore.stderr)) ignore.stderr <- get("ignore.stderr",
  188. envir = .GRASS_CACHE)
  189. Browse[2]>
  190. debug: ignore.stderr <- get("ignore.stderr", envir = .GRASS_CACHE)
  191. Browse[2]>
  192. debug: stopifnot(is.logical(ignore.stderr))
  193. Browse[2]>
  194. debug: G7 <- execGRASS("g.version", intern = TRUE) > "GRASS 7"
  195. Browse[2]>
  196. debug: if (missing(layer)) layer <- 1L
  197. Browse[2]>
  198. debug: layer <- 1L
  199. Browse[2]>
  200. debug: if (G7) layer <- as.character(layer)
  201. Browse[2]>
  202. debug: layer <- as.character(layer)
  203. Browse[2]>
  204. debug: if (driver == "GRASS") plugin <- TRUE
  205. Browse[2]>
  206. debug: NULL
  207. Browse[2]>
  208. debug: require(rgdal)
  209. Browse[2]>
  210. debug: if (is.null(plugin)) {
  211. ogrD <- ogrDrivers()$name
  212. plugin <- "GRASS" %in% ogrD
  213. }
  214. Browse[2]>
  215. debug: {
  216. ogrD <- ogrDrivers()$name
  217. plugin <- "GRASS" %in% ogrD
  218. }
  219. Browse[2]>
  220. debug: ogrD <- ogrDrivers()$name
  221. Browse[2]>
  222. debug: plugin <- "GRASS" %in% ogrD
  223. Browse[2]>
  224. debug: sss <- strsplit(packageDescription("rgdal")$Version, "-")[[1]]
  225. Browse[2]>
  226. debug: if (plugin) {
  227. ogrD <- ogrDrivers()$name
  228. if (!("GRASS" %in% ogrD))
  229. stop("no GRASS plugin driver")
  230. gg <- gmeta6()
  231. if (is.null(mapset)) {
  232. c_at <- strsplit(vname[1], "@")[[1]]
  233. if (length(c_at) == 1) {
  234. mapset <- .g_findfile(vname[1], type = "vector")
  235. }
  236. else if (length(c_at) == 2) {
  237. mapset <- c_at[2]
  238. vname[1] <- c_at[1]
  239. }
  240. else stop("malformed vector name")
  241. }
  242. dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
  243. vname[1], "head", sep = "/")
  244. if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  245. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
  246. pointDropZ = pointDropZ)
  247. }
  248. else {
  249. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
  250. }
  251. } else {
  252. ogrD <- ogrDrivers()$name
  253. if (!(driver %in% ogrD))
  254. stop(paste("Requested driver", driver, "not available in rgdal"))
  255. ogrDGRASS <- execGRASS("v.in.ogr", flags = "f", intern = TRUE,
  256. ignore.stderr = ignore.stderr)
  257. ogrDGRASSs <- strsplit(ogrDGRASS, ": ")
  258. if (!(driver %in% sapply(ogrDGRASSs, "[", 2)))
  259. stop(paste("Requested driver", driver, "not available in GRASS"))
  260. fDrivers <- c("GML", "SQLite")
  261. dDrivers <- c("ESRI_Shapefile", "MapInfo_File")
  262. if (!(gsub(" ", "_", driver) %in% c(fDrivers, dDrivers)))
  263. stop(paste("Requested driver", driver, "not supported"))
  264. is_dDriver <- TRUE
  265. if (gsub(" ", "_", driver) %in% fDrivers)
  266. is_dDriver <- FALSE
  267. vinfo <- vInfo(vname)
  268. types <- names(vinfo)[which(vinfo > 0)]
  269. if (is.null(type)) {
  270. if (length(grep("points", types)) > 0)
  271. type <- "point"
  272. if (length(grep("lines", types)) > 0)
  273. type <- "line"
  274. if (length(grep("areas", types)) > 0)
  275. type <- "area"
  276. if (is.null(type))
  277. stop("Vector type not found")
  278. }
  279. pid <- as.integer(round(runif(1, 1, 1000)))
  280. gtmpfl1 <- dirname(execGRASS("g.tempfile", pid = pid, intern = TRUE,
  281. ignore.stderr = ignore.stderr))
  282. rtmpfl1 <- ifelse(.Platform$OS.type == "windows" && (Sys.getenv("OSTYPE") ==
  283. "cygwin"), system(paste("cygpath -w", gtmpfl1, sep = " "),
  284. intern = TRUE), gtmpfl1)
  285. if (driver == "ESRI Shapefile")
  286. shname <- substring(vname, 1, ifelse(nchar(vname) > 8,
  287. 8, nchar(vname)))
  288. flags <- NULL
  289. if (with_prj)
  290. flags <- "e"
  291. if (with_c)
  292. flags <- c(flags, "c")
  293. if (is_dDriver) {
  294. GDSN <- gtmpfl1
  295. RDSN <- rtmpfl1
  296. LAYER <- shname
  297. }
  298. else {
  299. GDSN <- paste(gtmpfl1, shname, sep = .Platform$file.sep)
  300. RDSN <- paste(rtmpfl1, shname, sep = .Platform$file.sep)
  301. LAYER <- shname
  302. }
  303. execGRASS("v.out.ogr", flags = flags, input = vname, type = type,
  304. layer = layer, dsn = GDSN, olayer = LAYER, format = gsub(" ",
  305. "_", driver), ignore.stderr = ignore.stderr)
  306. if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  307. res <- readOGR(dsn = RDSN, layer = LAYER, verbose = !ignore.stderr,
  308. pointDropZ = pointDropZ)
  309. }
  310. else {
  311. res <- readOGR(dsn = rtmpfl1, layer = shname, verbose = !ignore.stderr)
  312. }
  313. if (.Platform$OS.type != "windows") {
  314. unlink(paste(rtmpfl1, list.files(rtmpfl1, pattern = shname),
  315. sep = .Platform$file.sep))
  316. }
  317. if (remove.duplicates && type != "point") {
  318. dups <- duplicated(slot(res, "data"))
  319. if (any(dups)) {
  320. if (length(grep("line", type)) > 0)
  321. type <- "line"
  322. if (length(grep("area", type)) > 0)
  323. type <- "area"
  324. if (type != "area" && type != "line")
  325. stop("try remove.duplicates=FALSE")
  326. ndata <- as(res, "data.frame")[!dups, , drop = FALSE]
  327. cand <- as.character(ndata$cat)
  328. cand[is.na(cand)] <- "na"
  329. row.names(ndata) <- cand
  330. if (type == "area") {
  331. pls <- slot(res, "polygons")
  332. }
  333. else if (type == "line") {
  334. pls <- slot(res, "lines")
  335. }
  336. p4s <- proj4string(res)
  337. IDs <- as.character(res$cat)
  338. IDs[is.na(IDs)] <- "na"
  339. tab <- table(factor(IDs))
  340. n <- length(tab)
  341. if (n + sum(dups) != length(pls))
  342. stop("length mismatch in duplicate removal")
  343. IDss <- .mixedsort(names(tab))
  344. reg <- match(IDs, IDss)
  345. belongs <- lapply(1:n, function(x) which(x == reg))
  346. npls <- vector(mode = "list", length = n)
  347. for (i in 1:n) {
  348. nParts <- length(belongs[[i]])
  349. srl <- NULL
  350. for (j in 1:nParts) {
  351. plij <- pls[[belongs[[i]][j]]]
  352. if (type == "area") {
  353. plijp <- slot(plij, "Polygons")
  354. }
  355. else if (type == "line") {
  356. plijp <- slot(plij, "Lines")
  357. }
  358. srl <- c(srl, plijp)
  359. }
  360. if (type == "area") {
  361. npls[[i]] <- Polygons(srl, ID = IDss[i])
  362. }
  363. else if (type == "line") {
  364. npls[[i]] <- Lines(srl, ID = IDss[i])
  365. }
  366. }
  367. if (type == "area") {
  368. SP <- SpatialPolygons(npls, proj4string = CRS(p4s))
  369. res <- SpatialPolygonsDataFrame(SP, ndata)
  370. }
  371. else if (type == "line") {
  372. SP <- SpatialLines(npls, proj4string = CRS(p4s))
  373. res <- SpatialLinesDataFrame(SP, ndata)
  374. }
  375. }
  376. }
  377. }
  378. Browse[2]>
  379. debug: {
  380. ogrD <- ogrDrivers()$name
  381. if (!("GRASS" %in% ogrD))
  382. stop("no GRASS plugin driver")
  383. gg <- gmeta6()
  384. if (is.null(mapset)) {
  385. c_at <- strsplit(vname[1], "@")[[1]]
  386. if (length(c_at) == 1) {
  387. mapset <- .g_findfile(vname[1], type = "vector")
  388. }
  389. else if (length(c_at) == 2) {
  390. mapset <- c_at[2]
  391. vname[1] <- c_at[1]
  392. }
  393. else stop("malformed vector name")
  394. }
  395. dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
  396. vname[1], "head", sep = "/")
  397. if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  398. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
  399. pointDropZ = pointDropZ)
  400. }
  401. else {
  402. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
  403. }
  404. }
  405. Browse[2]>
  406. debug: ogrD <- ogrDrivers()$name
  407. Browse[2]>
  408. debug: if (!("GRASS" %in% ogrD)) stop("no GRASS plugin driver")
  409. Browse[2]>
  410. debug: NULL
  411. Browse[2]>
  412. debug: gg <- gmeta6()
  413. Browse[2]>
  414. debug: if (is.null(mapset)) {
  415. c_at <- strsplit(vname[1], "@")[[1]]
  416. if (length(c_at) == 1) {
  417. mapset <- .g_findfile(vname[1], type = "vector")
  418. }
  419. else if (length(c_at) == 2) {
  420. mapset <- c_at[2]
  421. vname[1] <- c_at[1]
  422. }
  423. else stop("malformed vector name")
  424. }
  425. Browse[2]>
  426. debug: {
  427. c_at <- strsplit(vname[1], "@")[[1]]
  428. if (length(c_at) == 1) {
  429. mapset <- .g_findfile(vname[1], type = "vector")
  430. }
  431. else if (length(c_at) == 2) {
  432. mapset <- c_at[2]
  433. vname[1] <- c_at[1]
  434. }
  435. else stop("malformed vector name")
  436. }
  437. Browse[2]>
  438. debug: c_at <- strsplit(vname[1], "@")[[1]]
  439. Browse[2]>
  440. debug: if (length(c_at) == 1) {
  441. mapset <- .g_findfile(vname[1], type = "vector")
  442. } else if (length(c_at) == 2) {
  443. mapset <- c_at[2]
  444. vname[1] <- c_at[1]
  445. } else stop("malformed vector name")
  446. Browse[2]>
  447. debug: {
  448. mapset <- .g_findfile(vname[1], type = "vector")
  449. }
  450. Browse[2]>
  451. debug: mapset <- .g_findfile(vname[1], type = "vector")
  452. Browse[2]>
  453. debug: dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
  454. vname[1], "head", sep = "/")
  455. Browse[2]>
  456. debug: if (sss[1] >= "0.6" && as.integer(sss[2]) > 7) {
  457. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
  458. pointDropZ = pointDropZ)
  459. } else {
  460. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr)
  461. }
  462. Browse[2]>
  463. debug: {
  464. res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
  465. pointDropZ = pointDropZ)
  466. }
  467. Browse[2]>
  468. debug: res <- readOGR(dsn, layer = as.character(layer), verbose = !ignore.stderr,
  469. pointDropZ = pointDropZ)
  470. Browse[2]>
  471. GRASS 7.0.svn (spearfish70):~ >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement