Skip to content

Commit

Permalink
version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenKriewald authored and cran-robot committed Mar 22, 2019
1 parent 51b186c commit f3d1988
Show file tree
Hide file tree
Showing 23 changed files with 454 additions and 71 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Package: osc
Type: Package
Title: Orthodromic Spatial Clustering
Version: 1.0.0
Date: 2016-05-10
Version: 1.0.4
Date: 2019-03-22
Depends: raster, R (>= 2.14)
Suggests: testthat
Suggests: testthat, maps
Author: Steffen Kriewald, Till Fluschnik, Dominik Reusser, Diego Rybski
Maintainer: Steffen Kriewald <[email protected]>
Description: Allows distance based spatial clustering of georeferenced data by implementing the City Clustering Algorithm - CCA. Multiple versions allow clustering for matrix, raster and single coordinates on a plain (euclidean distance) or on a sphere (great-circle or orthodromic distance).
License: GPL
URL: https://www.pik-potsdam.de/~kriewald/osc/
NeedsCompilation: yes
Packaged: 2016-05-10 13:05:35 UTC; kriewald
Packaged: 2019-03-22 10:34:45 UTC; kriewald
Repository: CRAN
Date/Publication: 2016-05-10 19:05:05
Date/Publication: 2019-03-22 13:30:02 UTC
41 changes: 22 additions & 19 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
f48a7147e02c0724e05b6358e127ab85 *DESCRIPTION
33268da2b5a0174d693206835bc49e9e *NAMESPACE
ef6b29ceb44f4c545f1c9ae0f7eb5d45 *DESCRIPTION
6c76923a8c2910ee5d06d5f1cecd0228 *NAMESPACE
3b7548d94355d3aac0d7a20f96f8bf3f *R/cca.R
456b71ba9225142206fdc6d41077d4f2 *R/cca.single.R
911fcd63d0bc1d8c0ae950319404655d *R/code_revised_cca.R
a820b5cfb7628cc8041ade63275d950b *R/code_revised_cca.R
ebd670ecc096df9ce8e3f53dcc0419cb *R/getPart.R
94bdc1f82757c353cb1003e56241cdd6 *build/vignette.rds
fc5899e593250fad044d9db5808fb1c9 *README.md
6183df66858900ef5caf5b69906f7942 *build/vignette.rds
6d7bc5a2d4e9a0646afa0c7e770a26bb *data/datalist
58fd5c862c5b503e50d5245be0be11d4 *data/exampledata.rda
e4610df58b13625c9b23bd995a55faff *data/landcover.rda
4c396c53f51248f850075e93a4d3ddfc *data/population.rda
971ec966bdc8fc42d3f2eab9a45fc424 *inst/doc/paper.R
b0f652cbee75143ec695dc018de995b2 *inst/doc/paper.pdf
bda20f004bf359c3fffe7c064e7dfc40 *inst/doc/paper.rnw
faf8a645e7dedb1f0350588d42ace4ff *data/exampledata.rda
4a3eeb6d9e208622e6eb7b1e715b5a0a *data/landcover.rda
39758932230e99ea550c14d3e7bfc0b5 *data/population.rda
1123c4ff94fe73d63a0ba479cd61f5cb *inst/doc/paper.R
b303be4d1ef7439cced53bb5ed3f5a39 *inst/doc/paper.pdf
8119f6039bdfd5342556eb8f51a8141d *inst/doc/paper.rnw
71ed23ec67d3a47015db2b0b8dc06b07 *man/assign.data.Rd
f784386850049b09d50f411c8cca098f *man/cca.Rd
6f635bd0482bd3436984d92eaf6c8d17 *man/cca.Rd
a48d5876310a824b38f8bedd1fe49b96 *man/coordinate.list.Rd
caf4c194ad1c8880a0991f019062f05f *man/exampledata.Rd
83dddfbd273fc93fc26ca39690fa42b7 *man/landcover.Rd
0d846cb42d6a64028ee1bf6b573ce27c *man/osc.buffer.Rd
0335607d391a966d625027a432a6a214 *man/osc.buffer.Rd
3fefbda3fcd0894582ba971665e7c3fc *man/population.Rd
436aff5a71c41276d06bbd6a31f2b4e6 *src/cca-core.c
6e3121545e3e3dc8caabba7ba9200906 *src/ccaRevolution.c
cee2d2f0410b6c393f7c93dd5486886f *src/ccaRevolution.c
7c22b1b500cab25872924e218f1645f5 *src/registerDynamicSymbol.c
251bdb10958e0b5ac1737af4a05d85e2 *tests/testthat.R
35f54901471879ab9191912c70ffc422 *tests/testthat/test_cca_multi.R
1173e8ffffc2fc75fee4a0260c93a919 *tests/testthat/test_cca_single.R
d8266d70da0e7737622bb663ea664944 *tests/testthat/test_coordinate_list.R
716806c191b146997b4f6aaa4bd3be08 *vignettes/compare.pdf
bda20f004bf359c3fffe7c064e7dfc40 *vignettes/paper.rnw
49979365c9b21512171323f8aebf9c87 *vignettes/pics/exdat1.pdf
1fdeb0ba794228c0c0a232b901148d0c *vignettes/pics/exdat2.pdf
8183cf69156264257790404ae1a68a15 *vignettes/pics/fig-concordance.tex
63dcbf8e81d4a3f795ff4ce9bc7ed9be *vignettes/pics/landcover.pdf
b273fda9b9218cf2c707d4a4a5bd8b7a *vignettes/pics/raster.pdf
8119f6039bdfd5342556eb8f51a8141d *vignettes/paper.rnw
d8d5c1be654100f7a714505e8431c493 *vignettes/pics/exdat1.pdf
249bbc80805b329a9f1677bd35b8a440 *vignettes/pics/exdat2.pdf
c8c5232df87deeb59f8f53bd479f45be *vignettes/pics/fig-concordance.tex
4c5bf29c6181217bd3b701138ebc34f3 *vignettes/pics/landcover.pdf
3812352fa9f9a0faf087a27284493af2 *vignettes/pics/point_data.pdf
00657ccce1c7e2eab99949d3f9d8cbef *vignettes/pics/raster.pdf
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
useDynLib(osc)
useDynLib(osc, .registration = TRUE)

export(cca, cca.single, assign.data, osc.buffer, coordinate.list)
import(raster)
Expand Down
58 changes: 55 additions & 3 deletions R/code_revised_cca.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ccaRm <- function(data="", d=500, res.x=NULL, res.y=NULL, cell.class, compare)
data <- coordinate.list(data, cell.class, compare)
}

print(paste("use as X-coordinates column '",colnames(data)[1],"'"))
print(paste("use as Y-coordinates column '",colnames(data)[2],"'"))

# preprocessing
n1 <- length(data[,2]);
data <- ccaR.order(data);
Expand All @@ -66,7 +69,14 @@ ccaRm <- function(data="", d=500, res.x=NULL, res.y=NULL, cell.class, compare)
max_abs <- max(abs(data[,2]));
min_dist <- acos(sin(max_abs)*sin(max_abs)+cos(max_abs)*cos(max_abs)*cos(res.y*pi/180))*6371000;
min_dist_h <- acos(sin(0)*sin(res.x*pi/180)+cos(0)*cos(res.x*pi/180)*cos(0))*6371000;


# separate additional data for later
add.data <- NULL
if(ncol(data)>2){
add.data <- data[,3:ncol(data)]
data <- data[,1:2]
}

# create place holder for cluster id
data <- cbind(data, rep(0,length(data[,1])))
data <- as.matrix(data)
Expand All @@ -90,6 +100,8 @@ ccaRm <- function(data="", d=500, res.x=NULL, res.y=NULL, cell.class, compare)
mat1[,2] <- mat1[,2]*180/pi;
mat1 <- as.data.frame(mat1)
colnames(mat1) <- c("long","lat","cluster_id")
# re-add additional data
if(!is.null(add.data)){mat1 <- cbind(mat1, add.data)}
return(list(cluster=mat1,size=m1$mm));
}

Expand All @@ -102,12 +114,22 @@ ccaRd <- function(data="", d=500, cell.class, compare)
data <- coordinate.list(data, cell.class, compare)
}

print(paste("use as X-coordinates column '",colnames(data)[1],"'"))
print(paste("use as Y-coordinates column '",colnames(data)[2],"'"))

# preprocessing
n1 <- length(data[,2]);
#data <- ccaR.order(data);
data <- data[order(data[,1]),];
print("Sorting... Done");

# separate additional data
add.data <- NULL
if(ncol(data)>2){
add.data <- data[,3:ncol(data)]
data <- data[,1:2]
}

# create place holder for cluster id
data <- cbind(data, rep(0,length(data[,1])))
data <- as.matrix(data)
Expand All @@ -124,6 +146,8 @@ ccaRd <- function(data="", d=500, cell.class, compare)

mat1 <- as.data.frame(mat1)
colnames(mat1) <- c("long","lat","cluster_id")
# re-add additional data
if(!is.null(add.data)){mat1 <- cbind(mat1, add.data)}
return(list(cluster=mat1,size=m1$mm));
}

Expand Down Expand Up @@ -168,15 +192,43 @@ assign.data <- function(cluster, points, dist=1000){
# buffer
#########################################################

osc.buffer <- function(input, width)
osc.buffer <- function(input, width=max(dim(input)), return.width=F, complete=F)
{
if(class(input)=="RasterLayer"){
m <- matrix(input[], nrow=input@nrows, byrow=TRUE)
returnraster <- T}else{
m <- input
returnraster <- F
}
m1 <- .C("ccaBuffED", m=as.integer(m), nr=as.integer(dim(m)[1]), nc=as.integer(dim(m)[2]), sz=as.integer(width))
if(return.width){
# print(sum(m==0))
if(complete){
# m1 <- .C("ccaBuffEDszS",
# m=as.integer(m),
# nr=as.integer(dim(m)[1]),
# nc=as.integer(dim(m)[2]),
# sz=as.integer(width),
# nz=as.integer(sum(m==0)))
m1 <- .C("ccaBuffEDszNN",
m=as.integer(m),
nr=as.integer(dim(m)[1]),
nc=as.integer(dim(m)[2]),
sz=as.integer(width))
}else{
m1 <- .C("ccaBuffEDszN",
m=as.integer(m),
nr=as.integer(dim(m)[1]),
nc=as.integer(dim(m)[2]),
sz=as.integer(width),
nz=as.integer(sum(m==0)))
}
}else{
m1 <- .C("ccaBuffED",
m=as.integer(m),
nr=as.integer(dim(m)[1]),
nc=as.integer(dim(m)[2]),
sz=as.integer(width))
}
m1 <- m1$m
# m1[which(m1<0)] <- -1
m1 <- matrix(m1, nrow=dim(m)[1])
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# osc: Orthodromic Spatial Clustering

Allows distance based spatial clustering of georeferenced data by implementing the City Clustering Algorithm - CCA. Multiple versions allow clustering for matrix, raster and single coordinates on a plain (euclidean distance) or on a sphere (great-circle or orthodromic distance).
Binary file modified build/vignette.rds
Binary file not shown.
Binary file modified data/exampledata.rda
Binary file not shown.
Binary file modified data/landcover.rda
Binary file not shown.
Binary file modified data/population.rda
Binary file not shown.
50 changes: 49 additions & 1 deletion inst/doc/paper.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,55 @@ dev.off()


###################################################
### code chunk number 14: paper.rnw:205-234 (eval = FALSE)
### code chunk number 14: paper.rnw:197-200
###################################################
library(maps)
head(world.cities)
str(world.cities)


###################################################
### code chunk number 15: paper.rnw:203-205
###################################################
city.cluster <- cca(data = world.cities[,c(5,4,1:3,6)], s = 0.5)



###################################################
### code chunk number 16: paper.rnw:209-212
###################################################
city.cluster.m <- cca(data = world.cities[,c(5,4,1:3,6)], s = 56*1e+03,
res.x = 0.05, res.y = 0.05, unit = "m")



###################################################
### code chunk number 17: paper.rnw:215-228
###################################################
pdf("pics/point_data.pdf", width=8, height=4)
par(mfrow=c(1,2))
plot(x = city.cluster[[1]]$long,
y = city.cluster[[1]]$lat,
col=city.cluster[[1]]$cluster_id,
main = "d = 0.5°",
pch=19, cex=.1, xlab="long", ylab="lat")
plot(x = city.cluster.m[[1]]$long,
y = city.cluster.m[[1]]$lat,
col=city.cluster.m[[1]]$cluster_id,
main = "d = 56 km",
pch=19, cex=.1, xlab="long", ylab="lat")
dev.off()


###################################################
### code chunk number 18: paper.rnw:238-240
###################################################
coordinates(city.cluster[[1]]) <- ~long+lat
proj4string(city.cluster[[1]]) <- CRS("+init=epsg:4326")


###################################################
### code chunk number 19: paper.rnw:252-281 (eval = FALSE)
###################################################
## library(osc)
## data("population")
Expand Down
Binary file modified inst/doc/paper.pdf
Binary file not shown.
49 changes: 48 additions & 1 deletion inst/doc/paper.rnw
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,57 @@ dev.off()
\begin{figure}
\centering
\includegraphics[width=\textwidth]{pics/landcover.pdf}
\caption{Clustering of land cover data. Left side the original data and on the right side the clutered result.}
\caption{Clustering of land cover data. Left side the original data and on the right side the clustered result.}
\label{fig:landcover}
\end{figure}

\subsection{Clustering point data}

<<results=hide, echo=TRUE>>=
library(maps)
head(world.cities)
str(world.cities)
@

<<echo=TRUE>>=
city.cluster <- cca(data = world.cities[,c(5,4,1:3,6)], s = 0.5)
@


<<echo=TRUE>>=
city.cluster.m <- cca(data = world.cities[,c(5,4,1:3,6)], s = 56*1e+03,
res.x = 0.05, res.y = 0.05, unit = "m")
@

<<results=hide, echo=FALSE>>=
pdf("pics/point_data.pdf", width=8, height=4)
par(mfrow=c(1,2))
plot(x = city.cluster[[1]]$long,
y = city.cluster[[1]]$lat,
col=city.cluster[[1]]$cluster_id,
main = "d = 0.5°",
pch=19, cex=.1, xlab="long", ylab="lat")
plot(x = city.cluster.m[[1]]$long,
y = city.cluster.m[[1]]$lat,
col=city.cluster.m[[1]]$cluster_id,
main = "d = 56 km",
pch=19, cex=.1, xlab="long", ylab="lat")
dev.off()
@

\begin{figure}
\centering
\includegraphics[width=\textwidth]{pics/point_data.pdf}
\caption{CBla bla bla}
\label{fig:landcover}
\end{figure}

<<echo=TRUE>>=
coordinates(city.cluster[[1]]) <- ~long+lat
proj4string(city.cluster[[1]]) <- CRS("+init=epsg:4326")
@

\section{Comparison of the two Versions - matrix vs. list}
\label{sec:compare}
Expand Down
Loading

0 comments on commit f3d1988

Please sign in to comment.