Skip to content

Commit 15346cc

Browse files
committed
set startup messages to none; add sp2Mondrian from maptools
1 parent fe29931 commit 15346cc

17 files changed

+176
-89
lines changed

DESCRIPTION

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: sp
2-
Version: 2.1-0
2+
Version: 2.1-1
33
Title: Classes and Methods for Spatial Data
44
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"),
55
email = "[email protected]"),
@@ -13,7 +13,8 @@ Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"),
1313
person("Jim", "Lemon", role = "ctb"),
1414
person("Finn", "Lindgren", role = "ctb"),
1515
person("Josh", "O'Brien", role = "ctb"),
16-
person("Joseph", "O'Rourke", role = "ctb"))
16+
person("Joseph", "O'Rourke", role = "ctb"),
17+
person("Patrick", "Hausmann", role = "ctb"))
1718
Depends: R (>= 3.5.0), methods
1819
Imports: utils, stats, graphics, grDevices, lattice, grid
1920
Suggests: RColorBrewer, gstat, deldir, knitr, rmarkdown, sf, terra, raster
@@ -45,6 +46,7 @@ Collate: bpy.colors.R AAA.R Class-CRS.R CRS-methods.R
4546
gridded.R asciigrid.R spplot.R over.R spsample.R
4647
recenter.R dms.R gridlines.R spdists.R rbind.R flipSGDF.R
4748
chfids.R loadmeuse.R compassRose.R surfaceArea.R spOptions.R
48-
subset.R disaggregate.R sp_spat1.R merge.R aggregate.R elide.R
49+
subset.R disaggregate.R sp_spat1.R merge.R aggregate.R elide.R
50+
sp2Mondrian.R
4951
VignetteBuilder: knitr
5052

NAMESPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ export(
208208
spDistsN1,
209209
spDists,
210210

211-
write.asciigrid
211+
write.asciigrid,
212+
sp2Mondrian
212213
)
213214

214215
exportClasses(

R/AAA.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assign("Polypath", TRUE, envir = .spOptions)
99
assign("PolypathRule", "winding", envir = .spOptions)
1010
assign("col.regions", bpy.colors(), envir = .spOptions)
1111
assign("evolution_status", 2L, envir=.spOptions) # fixed changed 2.1-0
12-
assign("startup_message", "load", envir=.spOptions)
12+
assign("startup_message", "none", envir=.spOptions) # https://github.com/serafinialessio/mapping/issues/3
1313

1414
#.sp_CRS_cache <- new.env(FALSE, globalenv())
1515
#assign("CRS_CACHE", list(), envir=.sp_CRS_cache)

R/sp2Mondrian.R

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Copyright (c) 2006-7 Patrick Hausmann and Roger Bivand
2+
3+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
sp2Mondrian <- function(SP, file, new_format=TRUE) {
5+
if (!inherits(SP, "SpatialPolygonsDataFrame"))
6+
stop("not a SpatialPolygonsDataFrame object")
7+
pls <- slot(SP, "polygons")
8+
n <- length(pls)
9+
id <- 1:n
10+
df <- as(SP, "data.frame")
11+
df <- data.frame("/P_SP_ID"=id, df, check.names=FALSE)
12+
13+
if (!new_format) {
14+
con <- file(file, open="wt")
15+
write.table(df, file = con,
16+
quote = FALSE,
17+
row.names = FALSE,
18+
col.names = TRUE, sep="\t", dec=".")
19+
IDs <- sapply(pls, function(x) slot(x, "ID"))
20+
for (i in 1:n) {
21+
pl <- slot(pls[[i]], "Polygons")
22+
m <- length(pl)
23+
for (j in 1:m) {
24+
crds <- slot(pl[[j]], "coords")
25+
nc <- nrow(crds)
26+
lab <- paste(id[i], paste("/P", IDs[i], sep=""),
27+
nc, sep="\t")
28+
cat("\n", file = con)
29+
writeLines(lab, con = con)
30+
write.table(crds, file = con,
31+
append = TRUE,
32+
row.names = FALSE,
33+
col.names = FALSE, sep="\t", dec=".")
34+
}
35+
36+
}
37+
close(con)
38+
} else {
39+
bnm <- basename(file)
40+
dnm <- dirname(file)
41+
MAP_file <- paste(dnm, paste("MAP_", bnm, sep=""),
42+
sep=.Platform$file.sep)
43+
44+
con <- file(file, open="wt")
45+
write.table(df, file = con,
46+
quote = FALSE,
47+
row.names = FALSE,
48+
col.names = TRUE, sep="\t", dec=".")
49+
50+
cat("\n", file = con)
51+
writeLines(MAP_file, con, sep="")
52+
53+
close(con)
54+
con <- file(MAP_file, open="wt")
55+
for (i in 1:n) {
56+
pl <- slot(pls[[i]], "Polygons")
57+
m <- length(pl)
58+
for (j in 1:m) {
59+
crds <- slot(pl[[j]], "coords")
60+
nc <- nrow(crds)
61+
lab <- paste(id[i], "/P_SP_ID", nc, sep="\t")
62+
if (i > 1 || j > 1) cat("\n", file = con)
63+
writeLines(lab, con = con)
64+
write.table(crds, file = con,
65+
append = TRUE,
66+
row.names = FALSE,
67+
col.names = FALSE, sep="\t", dec=".")
68+
}
69+
70+
}
71+
close(con)
72+
}
73+
invisible(NULL)
74+
}
75+
76+
77+
Shape2Mondrian <- function(shape, file, id, export.data = TRUE) {
78+
79+
fshape <- shape
80+
xfile <- file
81+
idx <- paste("/P", id, sep="")
82+
83+
#
84+
# Export "att.data" -- TRUE / FALSE
85+
#
86+
if (is.logical(export.data) && export.data) {
87+
y <- fshape$att.data
88+
names(y) <- sub(id, idx, names(y))
89+
write.table(y, file = xfile,
90+
append = TRUE,
91+
row.names = FALSE,
92+
col.names = TRUE, sep="\t", dec=".")
93+
}
94+
95+
for (i in 1:length(fshape$Shapes)) {
96+
97+
xnrow <- nrow(fshape$Shapes[[i]]$verts)
98+
lab <- paste(i, idx, xnrow, sep="\t")
99+
100+
write.table("\n", file = xfile,
101+
append = TRUE, eol = "",
102+
quote = FALSE,
103+
row.names = FALSE,
104+
col.names = FALSE)
105+
write.table(lab, file = xfile,
106+
append = TRUE,
107+
quote = FALSE,
108+
row.names = FALSE,
109+
col.names = FALSE, sep="\t")
110+
write.table(fshape$Shapes[[i]]$verts, file = xfile,
111+
append = TRUE,
112+
row.names = FALSE,
113+
col.names = FALSE, sep="\t", dec=".")
114+
}
115+
}
116+
117+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118+
119+
#library(maptools)
120+
#x <- read.shape(system.file("shapes/columbus.shp", package="maptools")[1])
121+
#Shape2Mondrian(x, file="c:\\colombus.txt", "POLYID", export.data = TRUE)
122+
#xx <- readShapePoly(system.file("shapes/columbus.shp", package="maptools")[1])
123+
#sp2Mondrian(xx, file="colombus1.txt")
124+

man/sp2Mondrian.Rd

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
\name{sp2Mondrian}
2+
\alias{sp2Mondrian}
3+
%- Also NEED an '\alias' for EACH other topic documented here.
4+
\title{write map data for Mondrian}
5+
\description{
6+
The function outputs a SpatialPolygonsDataFrame object to be used by Mondrian
7+
}
8+
\usage{
9+
sp2Mondrian(SP, file, new_format=TRUE)
10+
}
11+
%- maybe also 'usage' for other objects documented here.
12+
\arguments{
13+
\item{SP}{a SpatialPolygonsDataFrame object}
14+
\item{file}{file where output is written}
15+
\item{new_format}{default TRUE, creates a text data file and a separate map file; the old format put both data sets in a single file - the map file is named by inserting "MAP_" into the file= argument after the rightmost directory separator (if any)}
16+
}
17+
18+
19+
\references{\url{https://www.theusrus.de/Mondrian/}, Ihaka Lecture 1: 28 September 2023, Interactive Graphics and Data Analysis, Antony Unwin \url{https://www.auckland.ac.nz/en/science/about-the-faculty/department-of-statistics/ihaka-lecture-series.html}}
20+
\author{Patrick Hausmann and Roger Bivand}
21+
\note{
22+
At this release, the function writes out a text file with both data and polygon(s) identified as belonging to each row of data.
23+
}
24+
25+
\examples{
26+
if (require("sf", quietly=TRUE)) {
27+
td <- tempdir()
28+
xx <- as(sf::st_read(system.file("shape/nc.shp", package="sf")[1], quiet=TRUE), "Spatial")
29+
sp2Mondrian(xx, file=file.path(td, "sids1.txt"))
30+
}
31+
}
32+
\keyword{spatial}

tests/agg.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
2721
> p = as(g, "SpatialPolygons")
2822
> p$z = c(1,0,1,0,1,0,1,0,1)
@@ -34,4 +28,4 @@ package maintainers should consider adding sf to Suggests:.
3428
>
3529
> proc.time()
3630
user system elapsed
37-
0.507 0.051 0.551
31+
0.556 0.042 0.592

tests/base.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse)
2721
> x = meuse[1:10, ] # limit the output
2822
> coordinates(x) = c("x", "y") # names
@@ -466,4 +460,4 @@ Data attributes:
466460
>
467461
> proc.time()
468462
user system elapsed
469-
0.647 0.057 0.697
463+
0.691 0.045 0.730

tests/fail1.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse)
2721
> x = meuse
2822
>
@@ -260,4 +254,4 @@ GEOGCRS["unknown",
260254
>
261255
> proc.time()
262256
user system elapsed
263-
0.708 0.076 0.776
257+
0.815 0.052 0.898

tests/grid.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse.grid)
2721
> x = meuse.grid
2822
> coordinates(x) = c("x", "y")
@@ -282,4 +276,4 @@ Coordinate Reference System (CRS) arguments: NA
282276
>
283277
> proc.time()
284278
user system elapsed
285-
0.682 0.052 0.728
279+
0.740 0.047 0.782

tests/over2.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
>
2721
> g = SpatialGrid(GridTopology(c(0,0), c(1,1), c(3,3)))
2822
> p = as(g, "SpatialPolygons")
@@ -34,4 +28,4 @@ package maintainers should consider adding sf to Suggests:.
3428
>
3529
> proc.time()
3630
user system elapsed
37-
0.484 0.058 0.536
31+
0.556 0.034 0.584

tests/pass1.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse)
2721
> x = meuse
2822
> coordinates(x) = cbind(rnorm(155), rnorm(155))
@@ -607,4 +601,4 @@ Error in SpatialPointsDataFrame(pts, df, match.ID = TRUE) :
607601
>
608602
> proc.time()
609603
user system elapsed
610-
0.855 0.065 0.916
604+
0.944 0.055 0.995

tests/point.in.polygon.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
>
2721
> # open polygon:
2822
> print(point.in.polygon(1:10,1:10,c(3,5,5,3),c(3,3,5,5)))
@@ -33,4 +27,4 @@ package maintainers should consider adding sf to Suggests:.
3327
>
3428
> proc.time()
3529
user system elapsed
36-
0.199 0.037 0.227
30+
0.218 0.019 0.231

tests/sel.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> x = c(0.5, 1.5, 0.5, 1.5, 1.6)
2721
> y = c(1.5, 1.5, 0.5, 0.5, 0.5)
2822
> xy = cbind(x,y)
@@ -207,4 +201,4 @@ e 2 c
207201
>
208202
> proc.time()
209203
user system elapsed
210-
0.633 0.065 0.691
204+
0.718 0.040 0.754

tests/sp1.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse)
2721
> x = meuse
2822
> nm <- names(meuse)
@@ -337,4 +331,4 @@ Data attributes:
337331
>
338332
> proc.time()
339333
user system elapsed
340-
0.538 0.059 0.590
334+
0.577 0.051 0.622

tests/spDists.Rout.save

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Type 'q()' to quit R.
1717

1818
> options("rgdal_show_exportToProj4_warnings"="none")
1919
> library(sp)
20-
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
21-
which was just load ed, were retired in October 2023.
22-
Please refer to R-spatial evolution reports for details, especially
23-
https://r-spatial.org/r/2023/05/15/evolution4.html.
24-
It may be desirable to make the sf package available;
25-
package maintainers should consider adding sf to Suggests:.
2620
> data(meuse)
2721
> data(meuse.grid)
2822
> coordinates(meuse) = ~x+y
@@ -41,4 +35,4 @@ package maintainers should consider adding sf to Suggests:.
4135
>
4236
> proc.time()
4337
user system elapsed
44-
1.050 0.209 1.257
38+
1.106 0.204 1.306

0 commit comments

Comments
 (0)