[r-cran-maptools] 07/20: Import Upstream version 0.7-34

Andreas Tille tille at debian.org
Sun Jan 15 18:55:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-maptools.

commit 093f3b4c5f8f500e574d83084eb3c7befae97b66
Author: Andreas Tille <tille at debian.org>
Date:   Sun Jan 15 19:53:26 2017 +0100

    Import Upstream version 0.7-34
---
 ChangeLog                   |  65 ++++++++++++++++++++++-
 DESCRIPTION                 |   8 +--
 NAMESPACE                   |   2 +
 R/AAA.R                     |  22 ++++++++
 R/DP.R                      |  15 ++++--
 R/Rgshhs.R                  | 123 ++++++++++++++++++++++++++++++++++++++++----
 R/checkHoles.R              |  21 ++++++--
 R/nowrapRecenter.R          |  30 +++++++++--
 R/shapelib.R                |  15 +++++-
 R/sp_bind.R                 |   4 +-
 R/union.R                   |  13 +++--
 R/zzz.R                     |   6 +--
 inst/ChangeLog              |  65 ++++++++++++++++++++++-
 man/Rgshhs.Rd               |   9 ++--
 man/checkPolygonsHoles.Rd   |  15 ++++--
 man/nowrapRecenter.Rd       |   2 +-
 man/readShapeLines.Rd       |   2 +-
 man/readShapePoints.Rd      |   2 +-
 man/readShapePoly.Rd        |   2 +-
 man/readShapeSpatial.Rd     |   6 +--
 man/spRbind-methods.Rd      |   8 +--
 man/thinnedSpatialPoly.Rd   |   4 +-
 man/unionSpatialPolygons.Rd |  13 +++--
 src/Rgshhs.c                |  17 +++---
 src/Rgshhs.h                |   4 +-
 25 files changed, 402 insertions(+), 71 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5920e07..4d898cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,69 @@
+2010-04-12 08:55  rsbivand
+
+	* DESCRIPTION: tidy
+
+2010-04-05 12:42  rsbivand
+
+	* DESCRIPTION, man/checkPolygonsHoles.Rd,
+	  man/thinnedSpatialPoly.Rd, man/unionSpatialPolygons.Rd: comment
+	  out links to rgeos
+
+2010-04-03 21:24  rsbivand
+
+	* DESCRIPTION, R/DP.R, R/Rgshhs.R, R/checkHoles.R,
+	  R/nowrapRecenter.R, R/union.R, ChangeLog, inst/ChangeLog: hide
+	  rgeos
+
+2010-04-03 18:22  rsbivand
+
+	* R/shapelib.R, ChangeLog, inst/ChangeLog: DBF filename, GSHHS C
+	  code errors addressed
+
+2010-04-03 18:01  rsbivand
+
+	* DESCRIPTION, R/AAA.R, R/shapelib.R, R/union.R,
+	  man/readShapeLines.Rd, man/readShapePoints.Rd,
+	  man/readShapePoly.Rd, man/readShapeSpatial.Rd,
+	  man/unionSpatialPolygons.Rd, src/Rgshhs.c, src/Rgshhs.h,
+	  ChangeLog, inst/ChangeLog: DBF filename, GSHHS C code errors
+	  addressed
+
+2010-01-17 20:26  rsbivand
+
+	* R/AAA.R, R/sp_bind.R, man/spRbind-methods.Rd: change spRbind for
+	  SpatialPointsDataFrame objects
+
+2010-01-10 20:42  rsbivand
+
+	* ChangeLog, inst/ChangeLog: gshhs hole fix
+
+2010-01-10 20:37  rsbivand
+
+	* R/Rgshhs.R: gshhs hole fix
+
+2010-01-08 10:46  rsbivand
+
+	* R/Rgshhs.R, ChangeLog, inst/ChangeLog: hole assignment in GSHHS
+
+2010-01-07 19:07  rsbivand
+
+	* ChangeLog, inst/ChangeLog: rgeos integration
+
+2010-01-07 19:03  rsbivand
+
+	* R/AAA.R, R/Rgshhs.R, man/Rgshhs.Rd: rgeos integration
+
+2010-01-07 13:10  rsbivand
+
+	* DESCRIPTION, NAMESPACE, R/DP.R, R/Rgshhs.R, R/checkHoles.R,
+	  R/nowrapRecenter.R, R/union.R, R/zzz.R, man/Rgshhs.Rd,
+	  man/checkPolygonsHoles.Rd, man/nowrapRecenter.Rd,
+	  man/thinnedSpatialPoly.Rd, man/unionSpatialPolygons.Rd, R/AAA.R:
+	  rgeos integration
+
 2009-12-21 13:39  rsbivand
 
-	* ChangeLog, INDEX: adding CCmaps
+	* ChangeLog, INDEX, inst/ChangeLog: adding CCmaps
 
 2009-12-21 13:35  rsbivand
 
diff --git a/DESCRIPTION b/DESCRIPTION
index c576ca4..6f44954 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
 Package: maptools
-Version: 0.7-29
-Date: 2009-12-21
+Version: 0.7-34
+Date: 2010-04-12
 Title: Tools for reading and handling spatial objects
 Encoding: latin1
 Author: Nicholas J. Lewin-Koh and Roger Bivand, contributions by Edzer
@@ -19,6 +19,6 @@ Description: Set of tools for manipulating and reading geographic data,
         with packages such as PBSmapping, spatstat, maps, RArcInfo,
         Stata tmap, WinBUGS, Mondrian, and others.
 License: GPL (>= 2)
-Packaged: 2009-12-21 12:42:44 UTC; rsb
+Packaged: 2010-04-12 07:10:58 UTC; rsb
 Repository: CRAN
-Date/Publication: 2009-12-21 17:43:10
+Date/Publication: 2010-04-12 09:41:40
diff --git a/NAMESPACE b/NAMESPACE
index 868d71e..cdb6811 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -39,6 +39,8 @@ export(as.owin.SpatialGridDataFrame, as.owin.SpatialPixelsDataFrame, as.owin.Spa
 
 export(as.psp.SpatialLinesDataFrame, as.psp.SpatialLines, as.psp.Lines, as.psp.Line)
 
+export(gpclibPermit, gpclibPermitStatus)
+
 export(unionSpatialPolygons, nowrapSpatialPolygons, nowrapRecenter, checkPolygonsHoles)
 
 export(Rgshhs)
diff --git a/R/AAA.R b/R/AAA.R
new file mode 100644
index 0000000..c7a31fd
--- /dev/null
+++ b/R/AAA.R
@@ -0,0 +1,22 @@
+.MAPTOOLS_CACHE <- new.env(FALSE, parent=globalenv())
+
+.onLoad <- function(lib, pkg) {
+    require(methods, quietly = TRUE, warn.conflicts = FALSE)
+    require("sp")
+    assign("gpclib", FALSE, envir=.MAPTOOLS_CACHE)
+    cat(paste("\n\tNote: polygon geometry computations in maptools\n",
+              "\tdepend on the package gpclib, which has a\n",
+              "\trestricted licence. It is disabled by default;\n",
+              "\tto enable gpclib, type gpclibPermit()\n"))
+    cat("\nChecking rgeos availability as gpclib substitute:\n")
+#    rgeosI <- require(rgeos, quietly = TRUE, warn.conflicts = FALSE)
+    rgeosI <- FALSE
+    cat(rgeosI, "\n")
+    assign("rgeos", rgeosI, envir=.MAPTOOLS_CACHE)
+}
+
+.onUnload <- function(libpath) {
+    rm(.MAPTOOLS_CACHE)
+}
+
+
diff --git a/R/DP.R b/R/DP.R
index ffdabe5..2f91220 100644
--- a/R/DP.R
+++ b/R/DP.R
@@ -101,9 +101,15 @@ dp_func <- function(points, tolerance) {
 
 thinnedSpatialPoly <- function(SP, tolerance, minarea=0) {
     stopifnot(inherits(SP, "SpatialPolygons"))
-    pls <- slot(SP, "polygons")
-    pls_dp <- vector(mode="list", length=length(pls))
-    for (i in 1:length(pls)) {
+    rgeosI <- rgeosStatus()
+    if (rgeosI) {
+#        require(rgeos)
+#        res <- thinnedSpatialPolyGEOS(SP=SP, tolerance=tolerance,
+#            minarea=minarea)
+    } else {
+      pls <- slot(SP, "polygons")
+      pls_dp <- vector(mode="list", length=length(pls))
+      for (i in 1:length(pls)) {
         Pls <- slot(pls[[i]], "Polygons")
         Pls_dp <- vector(mode="list", length=length(Pls))
         for (j in 1:length(Pls)) {
@@ -119,8 +125,9 @@ thinnedSpatialPoly <- function(SP, tolerance, minarea=0) {
         if (all(!Keep)) Keep[which.max(areas)] <- TRUE
         Pls_dp <- Pls_dp[Keep]
         pls_dp[[i]] <- Polygons(Pls_dp, ID=slot(pls[[i]], "ID"))
+      }
+      res <- SpatialPolygons(pls_dp, proj4string=CRS(proj4string(SP)))
     }
-    res <- SpatialPolygons(pls_dp, proj4string=CRS(proj4string(SP)))
     if (is(SP, "SpatialPolygonsDataFrame"))
         res <- SpatialPolygonsDataFrame(res, data=slot(SP, "data"))
     res
diff --git a/R/Rgshhs.R b/R/Rgshhs.R
index 375c115..c5c7a05 100644
--- a/R/Rgshhs.R
+++ b/R/Rgshhs.R
@@ -1,4 +1,4 @@
-# Copyright (c) 2005-8 Roger Bivand
+# Copyright (c) 2005-2010 Roger Bivand
 
 Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0, 
 	shift=FALSE, verbose=TRUE, no.clip = FALSE) {
@@ -23,6 +23,13 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 		as.logical(dolim), as.numeric(lim), as.integer(level), 
 		as.double(minarea), PACKAGE="maptools")
 	else clip <- NULL
+        rgeosI <- rgeosStatus()
+        if (rgeosI) {
+#            require(rgeos)
+        } else {
+            stopifnot(isTRUE(gpclibPermitStatus()))
+	    require("gpclib")
+        }
 	polys <- .Call("Rgshhs", as.character(fn), as.integer(5), 
 		as.logical(dolim), as.numeric(lim), as.integer(level), 
 		as.double(minarea), PACKAGE="maptools")
@@ -44,15 +51,43 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 	}
 
 	if (!no.clip && dolim && any(clip == 1) && line == 0) {
-		limbb <- cbind(c(lim[1], lim[1], lim[2], lim[2], lim[1]), 
-			c(lim[3], lim[4], lim[4], lim[3], lim[3]))
-		require("gpclib")
+	    limbb <- cbind(c(lim[1], lim[1], lim[2], lim[2], lim[1]), 
+		c(lim[3], lim[4], lim[4], lim[3], lim[3]))
+	    which_null <- NULL
+	    opolys <- vector(mode="list", length=length(polys))
+	    ic <- 1
+	    if (verbose) cat("Rgshhs: clipping", sum(clip), "of", 
+		length(polys), "polygons ...\n")
+            if (rgeosI) {
+		limgp <- Polygons(list(Polygon(limbb)), ID="0")
+		for (i in seq(along=polys)) {
+		    if (clip[i] == 1) {
+                        tp <- Polygons(list(Polygon(polys[[i]])), ID="1")
+                        rp0 <- NULL
+#                        rp0 <- PolygonsIntersections(tp, limgp)
+                        rp <- NULL
+                        if (!is.null(rp0)) 
+                            rp <- lapply(slot(rp0, "Polygons"), slot, "coords")
+			l <- length(rp)
+			if (l > 0) {
+		            outl <- vector(mode="list", length=l)
+			    for (j in 1:l) 
+				outl[[j]] <- as(rp[[j]], "matrix")
+			    opolys[[ic]] <- outl
+			    if (i < length(polys)) ic <- ic+1
+			} else {
+			    which_null <- c(which_null, i)
+			    if (verbose) cat("null polygon: [[", i,
+                                "]]\n", sep="");
+			}
+		    } else {
+			opolys[[ic]] <- list(polys[[i]])
+			if (i < length(polys)) ic <- ic+1
+		    }
+		}
+		polys <- opolys[1:ic]
+            } else {
 		limgp <- as(limbb, "gpc.poly")
-		which_null <- NULL
-		opolys <- vector(mode="list", length=length(polys))
-		ic <- 1
-		if (verbose) cat("Rgshhs: clipping", sum(clip), "of", 
-			length(polys), "polygons ...\n")
 		for (i in seq(along=polys)) {
 			if (clip[i] == 1) {
 				tp <- as(polys[[i]], "gpc.poly")
@@ -75,6 +110,7 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 			}
 		}
 		polys <- opolys[1:ic]
+            }
 	} else {
 		for (i in seq(along=polys)) polys[[i]] <- list(polys[[i]])
 		which_null <- NULL
@@ -82,8 +118,73 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 
 	if (!is.null(which_null)) chosen_0 <- chosen_0[-which_null]
 	chosen_1 <- chosen_0+1
-	levels <- polydata$level[chosen_1]
 	if (line == 0) {
+	 levels <- polydata$level[chosen_1]
+         if (rgeosI) {
+          ids <- polydata$id[chosen_1]
+          containers <- polydata$container[chosen_1]
+          ancestors <- polydata$ancestor[chosen_1]
+          tl <- as.list(table(levels))
+          ntl <- as.integer(names(tl))
+          mntl <- match(1:4, ntl)
+          l1 <- which(levels == 1L)
+          if (length(l1) > 0) {
+              c1 <- which(containers == -1L)
+              if (any(l1 != c1)) warning("containers and levels not coherent")
+              if (!is.na(mntl[4])) {
+                  wl4 <- which(levels == 4L)
+                  cw4 <- containers[wl4]
+                  mcw4 <- match(cw4, ids)
+                  containers[wl4] <- containers[mcw4]
+              }
+              if (!is.na(mntl[3])) {
+                  wl3 <- which(levels == 3L | levels == 4L)
+                  cw3 <- containers[wl3]
+                  mcw3 <- match(cw3, ids)
+                  containers[wl3] <- containers[mcw3]
+              }
+              IDs <- ids[l1]
+              if (is.na(mntl[2])) {
+                  belongs <- as.list(l1)
+              } else {
+                  belongs <- lapply(1:length(IDs), function(i)
+                      c(i, which(containers == IDs[i])))
+              }
+          } else {
+              stop("no shoreline in selection")
+          }
+	  holes <- !as.logical(levels %% 2)
+	  nps <- sapply(polys, length)
+          n <- length(belongs)
+          Srl <- vector(mode="list", length=n)
+	  for (i in 1:n) {
+		nParts <- length(belongs[[i]])
+		srl <- NULL
+		for (j in 1:nParts) {
+		    this <- belongs[[i]][j]
+		    for (k in 1:nps[this]) {
+			crds <- polys[[this]][[k]]
+			if (!identical(crds[1,], crds[nrow(crds),])) {
+			    crds <- rbind(crds, crds[1,,drop=FALSE])
+			    if (verbose) 
+			        cat("  closing polygon", this, ":", k, "\n")
+			}
+			if (shift) crds[,1] <- ifelse(crds[,1] > 180, 
+			    crds[,1] - 360, crds[,1])
+			jres <- list(Polygon(crds, hole=holes[this]))
+			srl <- c(srl, jres)
+		    }
+		}
+                pls0 <- Polygons(srl, ID=IDs[i])
+#		Srl[[i]] <- checkPolygonsGEOS(pls0)
+                Srl[[i]] <- pls0
+	  }
+	  res <- as.SpatialPolygons.PolygonsList(Srl, 
+		proj4string=CRS("+proj=longlat +datum=WGS84"))
+
+	  list(polydata=data.frame(polydata)[chosen_1,], belongs=belongs,
+              SP=res)
+         } else {
 	  belongs <- matrix(1:length(chosen_1), ncol=1)
 #	  belonged_to <- as.numeric(rep(NA, length(chosen_1)))
 
@@ -98,7 +199,6 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 	    mlevel <- as.integer(max(levels))
 	    belongs <- matrix(rep(1:length(chosen_1), mlevel), ncol=mlevel)
 	    first_time <- TRUE
-	    require("gpclib")
 	    for (il in mlevel:2) {
 		w_il <- which(levels == il)
 		w_il_1 <- which(levels == (il-1))
@@ -187,6 +287,7 @@ Rgshhs <- function(fn, xlim=NULL, ylim=NULL, level=4, minarea=0,
 		proj4string=CRS("+proj=longlat +datum=WGS84"))
 	  list(polydata=data.frame(polydata)[chosen_1,], belongs=belongs,
 		new_belongs=new_belongs, SP=res)
+         }
 	} else {
 	  Sll <- lapply(1:length(polys), function(i) {
               ID <- as.character(i)
diff --git a/R/checkHoles.R b/R/checkHoles.R
index 7f129f1..90e09f2 100644
--- a/R/checkHoles.R
+++ b/R/checkHoles.R
@@ -1,9 +1,23 @@
+gpclibPermit <- function() {
+    if (require("gpclib", quietly = TRUE, warn.conflicts = FALSE))
+        assign("gpclib", TRUE, envir=.MAPTOOLS_CACHE)
+    get("gpclib", envir=.MAPTOOLS_CACHE)
+}
+
+gpclibPermitStatus <- function() get("gpclib", envir=.MAPTOOLS_CACHE)
+
+rgeosStatus <- function() get("rgeos", envir=.MAPTOOLS_CACHE)
+
 checkPolygonsHoles <- function(x) {
+    if (rgeosStatus()) {
+#        require(rgeos)
+#        return(checkPolygonsGEOS(x))
+    } else {
+        stopifnot(isTRUE(gpclibPermitStatus()))
 	require(gpclib)
 	if (!is(x, "Polygons")) stop("not an Polygons object")
 	pls <- slot(x, "Polygons")
 	nParts <- length(pls)
-#	proj4CRS <- CRS(proj4string(x))
 	ID <- slot(x, "ID")
 	gpc <- as(slot(pls[[1]], "coords"), "gpc.poly")
 	if (nParts > 1) for (i in 2:nParts) gpc <- append.poly(gpc, 
@@ -22,12 +36,11 @@ checkPolygonsHoles <- function(x) {
 		rD <- .ringDirxy_gpc(crds)
 		if (rD == 1 & hole) crds <- crds[nrow(crds):1,]
 		if (rD == -1 & !hole)  crds <- crds[nrow(crds):1,]
-		Srl[[j]] <- Polygon(coords=crds, 
-#proj4string=proj4CRS, 
-hole=hole)
+		Srl[[j]] <- Polygon(coords=crds, hole=hole)
 	}
 	res <- Polygons(Srl, ID=ID)
 	res
+    }
 }
 
 .ringDirxy_gpc <- function(xy) {
diff --git a/R/nowrapRecenter.R b/R/nowrapRecenter.R
index 977c4e3..d70b1f7 100644
--- a/R/nowrapRecenter.R
+++ b/R/nowrapRecenter.R
@@ -1,5 +1,11 @@
 nowrapSpatialPolygons <- function(obj, offset=0, eps=rep(.Machine$double.eps, 2)) {
+    rgeosI <- rgeosStatus()
+    if (rgeosI) {
+#        require(rgeos)
+    } else {
+        stopifnot(isTRUE(gpclibPermitStatus()))
 	require(gpclib)
+    }
 	if (!is(obj, "SpatialPolygons")) stop("obj not a SpatialPolygons object")
 	proj <- is.projected(obj)
 	if (is.na(proj)) stop("unknown coordinate reference system")
@@ -8,21 +14,38 @@ nowrapSpatialPolygons <- function(obj, offset=0, eps=rep(.Machine$double.eps, 2)
 	inout <- bblong[1] < offset && bblong[2] >= offset
 	if (inout) {
 		pls <- slot(obj, "polygons")
-		Srl <- lapply(pls, .nowrapPolygons, offset=offset, eps=eps)
+		Srl <- lapply(pls, .nowrapPolygons, offset=offset, eps=eps,
+                    rgeosI=rgeosI)
 		res <- as.SpatialPolygons.PolygonsList(Srl,
 			proj4string=CRS(proj4string(obj)))
 	} else res <- obj
 	res
 }
 
-.nowrapPolygons <- function(obj, offset=0, eps=rep(.Machine$double.eps, 2)) {
+.nowrapPolygons <- function(obj, offset=0, eps=rep(.Machine$double.eps, 2),
+     rgeosI) {
 	if (!is(obj, "Polygons")) stop("not an Polygons object")
 	bbo <- bbox(obj)
 	inout <- bbo[1,1] < offset && bbo[1,2] >= offset
 	if (inout) {
+            if (rgeosI) {
+                 bb <- bbox(obj)
+                 bb <- list(x=bb[1,], y=bb[2,])
+                 bbmatW <- matrix(c(rep(bb$x[1], 2), rep(offset-eps[1], 2), 
+                     bb$x[1], bb$y[1], rep(bb$y[2], 2), rep(bb$y[1], 2)), 
+                     ncol=2)
+                 bbmatE <- matrix(c(rep(offset+eps[2], 2), rep(bb$x[2], 2), 
+                     offset+eps[2], bb$y[1], rep(bb$y[2], 2), 
+                     rep(bb$y[1], 2)), ncol=2)
+#                 resW <- PolygonsIntersections(obj,
+#                     Polygons(list(Polygon(bbmatW)), ID="W"))
+#                 resE <- PolygonsIntersections(obj,
+#                     Polygons(list(Polygon(bbmatE)), ID="E"))
+#                 res <- Polygons(c(slot(resW, "Polygons"),
+#                     slot(resE, "Polygons")), ID=slot(obj, "ID"))
+            } else {
 		pls <- slot(obj, "Polygons")
 		nParts <- length(pls)
-#		proj4CRS <- CRS(proj4string(obj))
 		ID <- slot(obj, "ID")
 		gpc <- as(slot(pls[[1]], "coords"), "gpc.poly")
 		if (nParts > 1) for (i in 2:nParts) gpc <- append.poly(gpc, 
@@ -51,6 +74,7 @@ nowrapSpatialPolygons <- function(obj, offset=0, eps=rep(.Machine$double.eps, 2)
 			Srl[[j]] <- Polygon(coords=crds, hole=hole)
 		}
 		res <- Polygons(Srl, ID=ID)
+            }
 	} else res <- obj
 	res
 }
diff --git a/R/shapelib.R b/R/shapelib.R
index d837ce5..11a4cb1 100644
--- a/R/shapelib.R
+++ b/R/shapelib.R
@@ -10,7 +10,20 @@ read.shape <- function(filen, dbf.data=TRUE, verbose=TRUE, repair=FALSE) {
   shinfo <- getinfo.shape(filen)
   if (dbf.data) {
 #    library(foreign)
-    df <- read.dbf(filen)
+# filename wrong assumption BDR 100403
+#    df <- read.dbf(filen)
+    bn <- basename(filen)
+    dn <- dirname(filen)
+    sbn <- strsplit(bn, "\\.")[[1]]
+    lsbn <- length(sbn)
+    if (lsbn > 1 && tolower(sbn[lsbn]) == "shp") sbn[lsbn] <- "dbf"
+    filen1 <- paste(sbn, collapse=".")
+    if (length(grep("\\.dbf$", filen1)) == 0)
+        filen1 <- paste(filen1, "dbf", sep=".")
+    if (length(dn) > 0) {
+        filen1 <- paste(dn, filen1, sep=.Platform$file.sep)
+    }
+    df <- read.dbf(filen1)
     ndf <- as.integer(nrow(df))
   } else ndf <- as.integer(NA)
   if (shinfo[[2]] == 8) {
diff --git a/R/sp_bind.R b/R/sp_bind.R
index 842c2f5..3e62978 100644
--- a/R/sp_bind.R
+++ b/R/sp_bind.R
@@ -92,7 +92,9 @@ setMethod("spRbind", signature(obj="SpatialPoints", x="SpatialPoints"),
 
 rbindSpatialPointsDataFrame <- function(obj, x) {
     SP <- spRbind(as(obj, "SpatialPoints"), as(x, "SpatialPoints"))
-    df <- rbind(as(obj, "data.frame"), as(x, "data.frame"))
+#    df <- rbind(as(obj, "data.frame"), as(x, "data.frame"))
+#    stopped adding coordinates as variables; Steve Eick 100117
+    df <- rbind(slot(obj, "data"), slot(x, "data"))
     SpatialPointsDataFrame(SP, data=df)
 }
 
diff --git a/R/union.R b/R/union.R
index c59f140..ebd306c 100644
--- a/R/union.R
+++ b/R/union.R
@@ -1,6 +1,12 @@
-unionSpatialPolygons <- function(SpP, IDs, threshold=NULL) {
+unionSpatialPolygons <- function(SpP, IDs, threshold=NULL, avoidGEOS=FALSE) {
+    if (!is(SpP, "SpatialPolygons")) stop("not a SpatialPolygons object")
+    rgeosI <- rgeosStatus()
+    if (rgeosI && !avoidGEOS) {
+#        require(rgeos)
+#        res <- unionSpatialPolygonsGEOS(SpP=SpP, IDs=IDs, threshold=threshold)
+    } else {
+        stopifnot(isTRUE(gpclibPermitStatus()))
 	require(gpclib)
-	if (!is(SpP, "SpatialPolygons")) stop("not a SpatialPolygons object")
 	pl <- slot(SpP, "polygons")
 	proj4CRS <- CRS(proj4string(SpP))
 	SrnParts <- sapply(pl, function(x) length(slot(x, "Polygons")))
@@ -53,6 +59,7 @@ unionSpatialPolygons <- function(SpP, IDs, threshold=NULL) {
 		}
 	}
 	res <- as.SpatialPolygons.PolygonsList(Srl, proj4string=proj4CRS)
-	res
+    }
+    res
 }
 
diff --git a/R/zzz.R b/R/zzz.R
index e09463a..52e4fad 100644
--- a/R/zzz.R
+++ b/R/zzz.R
@@ -3,6 +3,6 @@
 #}
 ## .noGenerics <- TRUE
 #maptools()
-
-".onLoad" <- function(lib, pkg) require(methods)
-
+#
+#".onLoad" <- function(lib, pkg) require(methods)
+#
diff --git a/inst/ChangeLog b/inst/ChangeLog
index 5920e07..4d898cc 100644
--- a/inst/ChangeLog
+++ b/inst/ChangeLog
@@ -1,6 +1,69 @@
+2010-04-12 08:55  rsbivand
+
+	* DESCRIPTION: tidy
+
+2010-04-05 12:42  rsbivand
+
+	* DESCRIPTION, man/checkPolygonsHoles.Rd,
+	  man/thinnedSpatialPoly.Rd, man/unionSpatialPolygons.Rd: comment
+	  out links to rgeos
+
+2010-04-03 21:24  rsbivand
+
+	* DESCRIPTION, R/DP.R, R/Rgshhs.R, R/checkHoles.R,
+	  R/nowrapRecenter.R, R/union.R, ChangeLog, inst/ChangeLog: hide
+	  rgeos
+
+2010-04-03 18:22  rsbivand
+
+	* R/shapelib.R, ChangeLog, inst/ChangeLog: DBF filename, GSHHS C
+	  code errors addressed
+
+2010-04-03 18:01  rsbivand
+
+	* DESCRIPTION, R/AAA.R, R/shapelib.R, R/union.R,
+	  man/readShapeLines.Rd, man/readShapePoints.Rd,
+	  man/readShapePoly.Rd, man/readShapeSpatial.Rd,
+	  man/unionSpatialPolygons.Rd, src/Rgshhs.c, src/Rgshhs.h,
+	  ChangeLog, inst/ChangeLog: DBF filename, GSHHS C code errors
+	  addressed
+
+2010-01-17 20:26  rsbivand
+
+	* R/AAA.R, R/sp_bind.R, man/spRbind-methods.Rd: change spRbind for
+	  SpatialPointsDataFrame objects
+
+2010-01-10 20:42  rsbivand
+
+	* ChangeLog, inst/ChangeLog: gshhs hole fix
+
+2010-01-10 20:37  rsbivand
+
+	* R/Rgshhs.R: gshhs hole fix
+
+2010-01-08 10:46  rsbivand
+
+	* R/Rgshhs.R, ChangeLog, inst/ChangeLog: hole assignment in GSHHS
+
+2010-01-07 19:07  rsbivand
+
+	* ChangeLog, inst/ChangeLog: rgeos integration
+
+2010-01-07 19:03  rsbivand
+
+	* R/AAA.R, R/Rgshhs.R, man/Rgshhs.Rd: rgeos integration
+
+2010-01-07 13:10  rsbivand
+
+	* DESCRIPTION, NAMESPACE, R/DP.R, R/Rgshhs.R, R/checkHoles.R,
+	  R/nowrapRecenter.R, R/union.R, R/zzz.R, man/Rgshhs.Rd,
+	  man/checkPolygonsHoles.Rd, man/nowrapRecenter.Rd,
+	  man/thinnedSpatialPoly.Rd, man/unionSpatialPolygons.Rd, R/AAA.R:
+	  rgeos integration
+
 2009-12-21 13:39  rsbivand
 
-	* ChangeLog, INDEX: adding CCmaps
+	* ChangeLog, INDEX, inst/ChangeLog: adding CCmaps
 
 2009-12-21 13:35  rsbivand
 
diff --git a/man/Rgshhs.Rd b/man/Rgshhs.Rd
index 358451f..abe6705 100644
--- a/man/Rgshhs.Rd
+++ b/man/Rgshhs.Rd
@@ -22,7 +22,7 @@ verbose = TRUE, no.clip = FALSE)
 }
 
 \details{
-  The package is distributed with the coarse version of the shoreline data, and much more detailed versions may be downloaded from the referenced websites. The data is of high quality, matching the accuracy of SRTM shorelines for the full dataset (but not for inland waterbodies). In general, users will construct study region SpatialPolygons objects, which can then be exported (for example as a shapefile), or used in other R packages (such as PBSmapping). The largest land polygons take co [...]
+  The package is distributed with the coarse version of the shoreline data, and much more detailed versions may be downloaded from the referenced websites. The data is of high quality, matching the accuracy of SRTM shorelines for the full dataset (but not for inland waterbodies). In general, users will construct study region SpatialPolygons objects, which can then be exported (for example as a shapefile), or used in other R packages (such as PBSmapping). The largest land polygons take co [...]
 }
 
 \value{
@@ -38,12 +38,15 @@ verbose = TRUE, no.clip = FALSE)
 \author{Roger Bivand}
 
 \note{
-  A number of steps are taken in this implementation that are unexpected, print messages, and so require explanation. Following the extraction of polygons intersecting the required region, a check is made to see if Antarctica is present. If it is, a new southern border is imposed at the southern ylim value or -90 if no ylim value is given. When clipping polygons seeming to intersect the required region boundary, it can happen that no polygon is left within the region (for example when th [...]
+  A number of steps are taken in this implementation that are unexpected, print messages, and so require explanation. Following the extraction of polygons intersecting the required region, a check is made to see if Antarctica is present. If it is, a new southern border is imposed at the southern ylim value or -90 if no ylim value is given. When clipping polygons seeming to intersect the required region boundary, it can happen that no polygon is left within the region (for example when th [...]
 
-Please also note that limitations on the use of gpclib are very unclear, as exactly the same GPC code is included in the GPL'ed PBSmapping package on CRAN.
+
+By default, if the rgeos package is available, it is used for topology operations. If it is not available, the gpclib package may be used. Please also note that gpclib has a restricted licence.
 }
 
 \examples{
+gpclibPermit()
+require(gpclib)
 gshhs.c.b <- system.file("share/gshhs_c.b", package="maptools")
 NZx <- c(160,180)
 NZy <- c(-50,-30)
diff --git a/man/checkPolygonsHoles.Rd b/man/checkPolygonsHoles.Rd
index b61d1c8..d4ad60e 100644
--- a/man/checkPolygonsHoles.Rd
+++ b/man/checkPolygonsHoles.Rd
@@ -1,27 +1,34 @@
 \name{checkPolygonsHoles}
 \alias{checkPolygonsHoles}
+\alias{rgeosStatus}
+\alias{gpclibPermit}
+\alias{gpclibPermitStatus}
 %- Also NEED an '\alias' for EACH other topic documented here.
 \title{Check holes in Polygons objects}
 \description{
-  The function checks holes in Polygons objects, using an intersection between a gpclib package gpc.poly object with one or more polygon contours and its bounding box to set the hole flag. The function will set single polygon contours to hole=FALSE, and if multiple polygon contours are holes, will set them TRUE.
+  The function checks holes in Polygons objects. Use of the rgeos package functions is prefered, and if rgeos is available, they will be used automatically. In this case, member Polygon objects are checked against each other for containment, and the returned Polygons object has component hole slots set appropriately. In addition, the output Polygons object may be provided with a comment string, encoding the external and internal rings. For gpclib use, see details below.
 }
 \usage{
 checkPolygonsHoles(x)
+gpclibPermitStatus()
+gpclibPermit()
+rgeosStatus()
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
   \item{x}{An Polygons object as defined in package sp}
 }
+\details{
+If the gpclib package is used, an intersection between a gpc.poly object with one or more polygon contours and its bounding box is used to set the hole flag. The function will set single polygon contours to hole=FALSE, and if multiple polygon contours are holes, will set them TRUE. The \code{gpclibPermit} function is used to choose to permit the use of gpclib if installed, and \code{gpclibPermitStatus} reports its status. The licence for gpclib is not Free or Open Source and explicitly f [...]
 
 \value{
   An Polygons object re-created from the input object.
 }
 
 \author{Roger Bivand}
-
+%\seealso{\code{\link[rgeos]{checkPolygonsGEOS}}}
 \examples{
-library(sp)
-library(gpclib)
+gpclibPermit()
 nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
  proj4string=CRS("+proj=longlat +ellps=clrk66"))
 pl <- slot(nc1, "polygons")
diff --git a/man/nowrapRecenter.Rd b/man/nowrapRecenter.Rd
index 52762fd..e31804f 100644
--- a/man/nowrapRecenter.Rd
+++ b/man/nowrapRecenter.Rd
@@ -27,8 +27,8 @@ nowrapSpatialPolygons(obj, offset = 0, eps=rep(.Machine$double.eps, 2))
 \seealso{\code{\link[sp]{recenter-methods}}, \code{\link[sp]{nowrapSpatialLines}}}
 
 \examples{
-library(gpclib)
 \dontrun{
+gpclibPermit()
 library(maps)
 world <- map("world", fill=TRUE, col="transparent", plot=FALSE)
 worldSpP <- map2SpatialPolygons(world, world$names, CRS("+proj=longlat"))
diff --git a/man/readShapeLines.Rd b/man/readShapeLines.Rd
index 2a9859b..f3fb889 100644
--- a/man/readShapeLines.Rd
+++ b/man/readShapeLines.Rd
@@ -39,7 +39,7 @@ xxx <- xx[xx$LENGTH > 30000,]
 plot(xxx, col="red", add=TRUE)
 tmpfl <- paste(tempdir(), "xxline", sep="/")
 writeLinesShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 axx <- readShapeLines(tmpfl, proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
 plot(xxx, col="black", lwd=4)
 plot(axx, col="yellow", lwd=1, add=TRUE)
diff --git a/man/readShapePoints.Rd b/man/readShapePoints.Rd
index c476b1c..ec35c1e 100644
--- a/man/readShapePoints.Rd
+++ b/man/readShapePoints.Rd
@@ -36,7 +36,7 @@ summary(xx)
 xxx <- xx[xx$PRICE < 40,]
 tmpfl <- paste(tempdir(), "xxpts", sep="/")
 writePointsShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 axx <- readShapePoints(tmpfl)
 plot(axx, col="red", add=TRUE)
 unlink(paste(tmpfl, ".*", sep=""))
diff --git a/man/readShapePoly.Rd b/man/readShapePoly.Rd
index cdcd161..63e3516 100644
--- a/man/readShapePoly.Rd
+++ b/man/readShapePoly.Rd
@@ -47,7 +47,7 @@ xxx <- xx[xx$SID74 < 2,]
 plot(xxx, border="red", add=TRUE)
 tmpfl <- paste(tempdir(), "xxpoly", sep="/")
 writePolyShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 axx <- readShapePoly(tmpfl, proj4string=CRS("+proj=longlat +ellps=clrk66"))
 plot(xxx, border="black", lwd=4)
 plot(axx, border="yellow", lwd=1, add=TRUE)
diff --git a/man/readShapeSpatial.Rd b/man/readShapeSpatial.Rd
index 1543a70..1c5b029 100644
--- a/man/readShapeSpatial.Rd
+++ b/man/readShapeSpatial.Rd
@@ -43,7 +43,7 @@ summary(xx)
 xxx <- xx[xx$SID74 < 2,]
 tmpfl <- paste(tempdir(), "xxpoly", sep="/")
 writeSpatialShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 unlink(paste(tmpfl, ".*", sep=""))
 xx <- readShapeSpatial(system.file("shapes/fylk-val.shp",
  package="maptools")[1], proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
@@ -52,14 +52,14 @@ xxx <- xx[xx$LENGTH > 30000,]
 plot(xxx, col="red", add=TRUE)
 tmpfl <- paste(tempdir(), "xxline", sep="/")
 writeSpatialShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 unlink(paste(tmpfl, ".*", sep=""))
 xx <- readShapeSpatial(system.file("shapes/baltim.shp", package="maptools")[1])
 summary(xx)
 xxx <- xx[xx$PRICE < 40,]
 tmpfl <- paste(tempdir(), "xxpts", sep="/")
 writeSpatialShape(xxx, tmpfl)
-maptools:::getinfo.shape(paste(tmpfl, ".shp", sep=""))
+getinfo.shape(paste(tmpfl, ".shp", sep=""))
 unlink(paste(tmpfl, ".*", sep=""))
 }
 \keyword{spatial}
diff --git a/man/spRbind-methods.Rd b/man/spRbind-methods.Rd
index eca28e9..8db1035 100644
--- a/man/spRbind-methods.Rd
+++ b/man/spRbind-methods.Rd
@@ -38,12 +38,8 @@ In addition to the \code{spRbind}-methods, there are also
  \item{some \code{rbind} can accept objects with duplicated IDs, for all 
      \code{spRbind}-methods these have to be modified explicitly, e.g. by 
      calling \code{\link[sp]{spChFIDs-methods}}}
- \item{in \code{spRbind} for \code{Spatial*DataFrame}s, data is extracted
-     by \code{as(x,"data.frame")}. Because of this, the coordinates will
-     be added back to the new object when applying \code{spRbind} on 
-     \code{SpatialPointsDataFrame}s. }
-}
-}
+
+}}
 
 \author{Roger Bivand}
 
diff --git a/man/thinnedSpatialPoly.Rd b/man/thinnedSpatialPoly.Rd
index cac705f..4e856fd 100644
--- a/man/thinnedSpatialPoly.Rd
+++ b/man/thinnedSpatialPoly.Rd
@@ -4,7 +4,7 @@
 \title{Douglas-Peuker line generalization for Spatial Polygons}
 
 \description{
-The function applies the implementation of the Douglas-Peuker algorithm for line generalization or simplification (originally from shapefiles) to objects inheriting from Spatial Polygons. It does not preserve topology, so is suitable for visualisation, but not for the subsequent analysis of the polygon boundaries, as artefacts may be created, and boundaries of neighbouring entities may be generalized differently.
+The function applies the implementation of the Douglas-Peuker algorithm for line generalization or simplification (originally from shapefiles) to objects inheriting from Spatial Polygons. It does not preserve topology, so is suitable for visualisation, but not for the subsequent analysis of the polygon boundaries, as artefacts may be created, and boundaries of neighbouring entities may be generalized differently. If the rgeos package is available, \code{thinnedSpatialPolyGEOS} will be us [...]
 }
 \usage{
 thinnedSpatialPoly(SP, tolerance, minarea=0)
@@ -24,6 +24,8 @@ represent a digitized line or its caricature.
 
 \note{Warnings reporting: Non-finite label point detected and replaced, reflect the changes in the geometries of the polygons induced by line generalization.}
 
+%\seealso{\code{\link[rgeos]{thinnedSpatialPolyGEOS}}}
+
 \examples{
 xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1],
       IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
diff --git a/man/unionSpatialPolygons.Rd b/man/unionSpatialPolygons.Rd
index d4856f5..8cd5ea8 100644
--- a/man/unionSpatialPolygons.Rd
+++ b/man/unionSpatialPolygons.Rd
@@ -3,27 +3,30 @@
 %- Also NEED an '\alias' for EACH other topic documented here.
 \title{Aggregate Polygons in a SpatialPolygons object}
 \description{
-  The function aggregates Polygons in a SpatialPolygons object, according to the IDs vector specifying which input Polygons belong to which output Polygons; internal boundaries are dissolved using the gpclib package union() function.
+  The function aggregates Polygons in a SpatialPolygons object, according to the IDs vector specifying which input Polygons belong to which output Polygons; internal boundaries are dissolved using the gpclib package union() function. If the rgeos package is available, \code{unionSpatialPolygonsGEOS} will be used with partial topology preservation instead of the R implementation here by passing arguments through.
 }
 \usage{
-unionSpatialPolygons(SpP, IDs, threshold=NULL)
+unionSpatialPolygons(SpP, IDs, threshold=NULL, avoidGEOS=FALSE)
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
   \item{SpP}{A SpatialPolygons object as defined in package sp}
   \item{IDs}{A vector defining the output Polygons objects, equal in length to the length of the polygons slot of SpRs; it may be character, integer, or factor (try table(factor(IDs)) for a sanity check)}
   \item{threshold}{if not NULL, an area measure below which slivers will be discarded (some polygons have non-identical boundaries, for instance along rivers, generating slivers on union which are artefacts, not real sub-polygons)}
+  \item{avoidGEOS}{default FALSE; if TRUE force use of gpclib even when GEOS is available}
 }
 
 \value{
   Returns an aggregated SpatialPolygons object named with the aggregated IDs values in their sorting order; see the ID values of the output object to view the order.
 }
 
-\author{Roger Bivand}
+\section{Warning}{When using GEOS Unary Union, it has been found that some polygons are not dissolved correctly when the absolute values of the coordinates are very small. No work-around is available at present.}
 
+\author{Roger Bivand}
+%\seealso{\code{\link[rgeos]{unionSpatialPolygonsGEOS}}}
 \examples{
-library(sp)
-library(gpclib)
+gpclibPermit()
+require(gpclib)
 nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
  proj4string=CRS("+proj=longlat +datum=NAD27"))
 lps <- coordinates(nc1)
diff --git a/src/Rgshhs.c b/src/Rgshhs.c
index d3d5386..1f0b29a 100644
--- a/src/Rgshhs.c
+++ b/src/Rgshhs.c
@@ -1,4 +1,4 @@
-/*	$Id: Rgshhs.c,v 1.7 2009/12/21 12:37:45 rsbivand Exp $
+/*	$Id: Rgshhs.c,v 1.8 2010/04/03 16:01:48 rsbivand Exp $
  *
  *	Copyright (c) 1996-2009 by P. Wessel and W. H. F. Smith
  *	See COPYING file for copying and redistribution conditions.
@@ -79,14 +79,14 @@ SEXP Rgshhs(SEXP fn, SEXP mode, SEXP dolim, SEXP lim, SEXP level, SEXP minarea)
 {
 	FILE *fp;
 	double w, e, s, n, area, lon, lat;
-	char source, kind[2] = {'P', 'L'};
+	char source;
 	char msg[255];
-	char *name[2] = {"polygon", "line"}, container[8], ancestor[8];
-	int k, line, max_east = 270000000, info, n_read, /*flip,*/ Level, version, greenwich, src;
+	char *name[2] = {"polygon", "line"};
+	int k, line, max_east = 270000000, n_read, /*flip,*/ Level, version, greenwich, src;
 	struct POINT p;
 	struct GSHHS h;
 	int npols, pc=0;
-	SEXP res, resnames, resa, plist, choice, chosen, clip, subset;
+	SEXP res, resnames, plist, choice, chosen, clip, subset;
 	int i, ipols;
 	signed int fpos;
 	double bb[4], bbi[4];
@@ -100,6 +100,8 @@ SEXP Rgshhs(SEXP fn, SEXP mode, SEXP dolim, SEXP lim, SEXP level, SEXP minarea)
 	}
 
 	npols = getNpols(fp);
+        line = 0;
+        res = R_NilValue;
 	if (INTEGER_POINTER(mode)[0] == 0) {
 		fclose (fp);
 
@@ -353,12 +355,13 @@ SEXP Rgshhs(SEXP fn, SEXP mode, SEXP dolim, SEXP lim, SEXP level, SEXP minarea)
 		    return(plist);
 		}
 	}
+        error("shouldn't be here");
+        return(R_NilValue);
 }
 
 int getNpols(FILE *fp) {
 	struct GSHHS h;
-	int n_read, /*flip,*/ version;
-	int npols;
+	int n_read/*, flip, version*/;
 	int n;
 
 	n_read = fread ((void *)&h, (size_t)sizeof (struct GSHHS), 
diff --git a/src/Rgshhs.h b/src/Rgshhs.h
index 5decb31..0aaf1ae 100644
--- a/src/Rgshhs.h
+++ b/src/Rgshhs.h
@@ -1,4 +1,4 @@
-/*	$Id: Rgshhs.h,v 1.5 2009/12/18 21:56:57 rsbivand Exp $
+/*	$Id: Rgshhs.h,v 1.6 2010/04/03 16:01:48 rsbivand Exp $
  *
  * Include file defining structures used in gshhs.c
  *
@@ -40,7 +40,7 @@ This modification of gshhs.h is Copyright (c) 2005-9 Roger Bivand
 
 #ifndef _GSHHS
 #define _GSHHS
-#define _POSIX_SOURCE 1		/* GSHHS code is POSIX compliant */
+/* RSB #define _POSIX_SOURCE 1		 GSHHS code is POSIX compliant */
 
 /*#include <stdio.h>
 #include <stdlib.h>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/r-cran-maptools.git



More information about the debian-science-commits mailing list