Skip to content

Commit

Permalink
Merge branch 'master' into statnmap-patch-st_ll_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed May 29, 2018
2 parents bd389e3 + 4922d16 commit a04233a
Show file tree
Hide file tree
Showing 55 changed files with 605 additions and 418 deletions.
4 changes: 1 addition & 3 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.travis.yml
attic
docs
PROPOSAL.md
cov
config.log
config.status
TODO
^windows
^appveyor\.yml$
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: r

r:
- release
- oldrel
- devel
# - oldrel

sudo: required
dist: trusty
Expand Down
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: sf
Version: 0.6-3
Version: 0.6-4
Title: Simple Features for R
Description: Support for simple features, a standardized way to encode spatial vector data. Binds
to 'GDAL' for reading and writing data, to 'GEOS' for geometrical operations, and to 'PROJ' for projection
Expand All @@ -24,7 +24,6 @@ Imports:
grDevices,
grid,
Rcpp,
RPostgreSQL,
DBI (>= 0.8),
units (>= 0.5-1),
classInt,
Expand All @@ -45,7 +44,10 @@ Suggests:
rlang,
dplyr (>= 0.7-0),
tidyr (>= 0.7-2),
RPostgreSQL,
RPostgres (>= 1.1.0),
pool,
odbc,
tidyselect,
ggplot2,
mapview,
Expand All @@ -56,7 +58,7 @@ Suggests:
rmarkdown
LinkingTo: Rcpp
VignetteBuilder: knitr
SystemRequirements: GDAL (>= 2.0.0), GEOS (>= 3.4.0), PROJ.4 (>= 4.8.0)
SystemRequirements: GDAL (>= 2.0.1), GEOS (>= 3.4.0), PROJ.4 (>= 4.8.0)
License: GPL-2 | MIT + file LICENSE
URL: https://github.com/r-spatial/sf/
BugReports: https://github.com/r-spatial/sf/issues/
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ S3method(Ops,sgbp)
S3method(aggregate,sf)
S3method(as.data.frame,sf)
S3method(as.data.frame,sfc)
S3method(as.data.frame,sgbp)
S3method(as.matrix,sfg)
S3method(as.matrix,sgbp)
S3method(c,sfc)
Expand Down Expand Up @@ -181,7 +182,9 @@ S3method(st_polygonize,sfg)
S3method(st_precision,sf)
S3method(st_precision,sfc)
S3method(st_read,DBIObject)
S3method(st_read,Pool)
S3method(st_read,PostgreSQLConnection)
S3method(st_read,character)
S3method(st_read,default)
S3method(st_segmentize,sf)
S3method(st_segmentize,sfc)
Expand Down Expand Up @@ -343,7 +346,6 @@ exportMethods(dbDataType)
exportMethods(dbWriteTable)
import(graphics)
importClassesFrom(DBI,DBIObject)
importClassesFrom(RPostgreSQL,PostgreSQLConnection)
importFrom(DBI,dbConnect)
importFrom(DBI,dbDisconnect)
importFrom(DBI,dbExecute)
Expand All @@ -353,6 +355,7 @@ importFrom(DBI,dbSendQuery)
importFrom(DBI,dbWriteTable)
importFrom(Rcpp,evalCpp)
importFrom(classInt,classIntervals)
importFrom(grDevices,dev.size)
importFrom(grDevices,rgb)
importFrom(grid,convertUnit)
importFrom(grid,current.viewport)
Expand Down
34 changes: 25 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# version 0.6-2
# version 0.6-4

# version 0.6-3

* move dependency `RPostgreSQL` back to Suggests:, from Imports:

* `st_centroid.sf` and `st_point_on_surface.sf` now also warn if attributes are not constant over geometries.

* `summarise` now allows the user to define geometries for summaries; #714, by Kirill Mueller

* support read/write of logical variables through GDAL; #722
* `plot.sf` now emits a warning if `col` does not have length 1 or `nrow(x)`, and requires `pal` (rather than `col`) to set a palette for factors.

* add temp file copying workaround for writing GPKG files to network drives; #628
* `plot.sf` provides control over legend keys using `key.length` and `key.width`, decrease default key length; #731

* `sgbp` objects receive an `as.data.frame` method; #715

# version 0.6-2

* GDAL read/write now supports logical variables; #722

* add `st_crop` to simplify cropping objects with a rectangular area; #720

* fix bug in `[<-` when columns are added to an `sf` object; #718

* use dynamic registration of S3 methods, similar to how hms does this; #710 by Kirill Mueller

* (partially) address writing GPKG to network drive; #628
* (partially) address writing GPKG to network drive, writing to temp file first; #628

* add Kirill Mueller as contributor

* improve speed of `st_make_grid`; #708, by Dan Baston
* `st_make_grid` is now faster; #708, by Dan Baston

* `st_read` and `st_write` are now generic, with methods for directly reading from and writing to database connections; `st_read_db` and `st_write_db` are now deprecated; #558, thanks to Etienne Racine @etiennebr

* Package `RPostgreSQL` moved from Suggests to Imports

* restore compatibility with GDAL 2.0.x versions (which won't have `gdal_utils`); #686

* `read_sf` can now also read tables without geometry; #684, by Andy Teucher
Expand All @@ -32,7 +48,7 @@

* all Rcpp interfaces needed by package `stars` have now been moved into `sf`; pkg `stars` is now R-only, and only `sf` needs linking to GDAL.

* interface the 9 gdal utils using the C++ API; see R function `gdal_utils()`
* `gdal_utils()` now interfaces the 9 gdal utils using the C++ API

* improve resetting (base) plots; add `reset = FALSE` in a call to `plot` to enable adding to plots that have a legend

Expand Down Expand Up @@ -60,7 +76,7 @@

* `st_distance` for long/lat geographic coordinates now uses `lwgeom`, accepting all geometry types; argument `dist_fun` is deprecated as a consequence, and distance calculations are different from those in sf versions 0.5-5 or earlier; #593

* add package `lwgeom` to Suggests; `st_area`, `st_length`, `st_distance`, `st_segmentize` for long/lat CRS now use functions from package `lwgeom` instead of `geosphere`; #593
* add package `lwgeom` to Suggests; `st_area`, `st_length`, `st_distance`, `st_segmentize` for long/lat CRS now use package `lwgeom` instead of `geosphere`; #593

* `st_length` now returns zero for polygon-type geometries; #593

Expand Down Expand Up @@ -212,7 +228,7 @@

* add a `[<-` method for `sfc` objects; automatically replaces `NULL` with an empty geometry; #411

* add `st_point_on_surface` function to return a point that is guaranteed to be on the surface (standard compliance)
* add `st_point_on_surface()` to return a point that is guaranteed to be on the surface (standard compliance)

* `read_sf` now returns an sf-tibble, an object of class `c("sf", "tbl_df", "tbl", "data.frame")`

Expand Down Expand Up @@ -308,7 +324,7 @@

* build proper support for `cbind` and `rbind` methods for `sf`, which work (as documented) when _all_ arguments are of class `sf`; `dplyr::bind_cols` or `st_sf(data.frame(sf, df))` work for binding `data.frame`s to an `sf` object.

* units support for function arguments of `st_segmentize` and `st_line_sample`
* `st_segmentize()` and `st_line_sample()` now accept units arguments

* document problem reading shapefiles from USB drives on OSX; #252

Expand Down
80 changes: 4 additions & 76 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,76 +77,8 @@ CPL_gdal_with_geos <- function() {
.Call('_sf_CPL_gdal_with_geos', PACKAGE = 'sf')
}

CPL_area <- function(sfc) {
.Call('_sf_CPL_area', PACKAGE = 'sf', sfc)
}

CPL_gdal_dimension <- function(sfc, NA_if_empty = TRUE) {
.Call('_sf_CPL_gdal_dimension', PACKAGE = 'sf', sfc, NA_if_empty)
}

CPL_length <- function(sfc) {
.Call('_sf_CPL_length', PACKAGE = 'sf', sfc)
}

CPL_gdal_segmentize <- function(sfc, dfMaxLength = 0.0) {
.Call('_sf_CPL_gdal_segmentize', PACKAGE = 'sf', sfc, dfMaxLength)
}

CPL_gdal_linestring_sample <- function(sfc, distLst) {
.Call('_sf_CPL_gdal_linestring_sample', PACKAGE = 'sf', sfc, distLst)
}

CPL_get_layers <- function(datasource, options, do_count = FALSE) {
.Call('_sf_CPL_get_layers', PACKAGE = 'sf', datasource, options, do_count)
}

CPL_read_ogr <- function(datasource, layer, options, quiet, toTypeUser, promote_to_multi = TRUE, int64_as_string = FALSE) {
.Call('_sf_CPL_read_ogr', PACKAGE = 'sf', datasource, layer, options, quiet, toTypeUser, promote_to_multi, int64_as_string)
}

CPL_gdalinfo <- function(obj, options) {
.Call('_sf_CPL_gdalinfo', PACKAGE = 'sf', obj, options)
}

CPL_gdalwarp <- function(src, dst, options) {
.Call('_sf_CPL_gdalwarp', PACKAGE = 'sf', src, dst, options)
}

CPL_gdalrasterize <- function(src, dst, options) {
.Call('_sf_CPL_gdalrasterize', PACKAGE = 'sf', src, dst, options)
}

CPL_gdaltranslate <- function(src, dst, options) {
.Call('_sf_CPL_gdaltranslate', PACKAGE = 'sf', src, dst, options)
}

CPL_gdalvectortranslate <- function(src, dst, options) {
.Call('_sf_CPL_gdalvectortranslate', PACKAGE = 'sf', src, dst, options)
}

CPL_gdalbuildvrt <- function(src, dst, options) {
.Call('_sf_CPL_gdalbuildvrt', PACKAGE = 'sf', src, dst, options)
}

CPL_gdaldemprocessing <- function(src, dst, options, processing, colorfilename) {
.Call('_sf_CPL_gdaldemprocessing', PACKAGE = 'sf', src, dst, options, processing, colorfilename)
}

CPL_gdalnearblack <- function(src, dst, options) {
.Call('_sf_CPL_gdalnearblack', PACKAGE = 'sf', src, dst, options)
}

CPL_gdalgrid <- function(src, dst, options) {
.Call('_sf_CPL_gdalgrid', PACKAGE = 'sf', src, dst, options)
}

CPL_write_ogr <- function(obj, dsn, layer, driver, dco, lco, geom, dim, quiet = FALSE, update = FALSE, delete_dsn = FALSE, delete_layer = FALSE) {
.Call('_sf_CPL_write_ogr', PACKAGE = 'sf', obj, dsn, layer, driver, dco, lco, geom, dim, quiet, update, delete_dsn, delete_layer)
}

CPL_geos_binop <- function(sfc0, sfc1, op, par = 0.0, pattern = "", sparse = TRUE, prepared = FALSE) {
.Call('_sf_CPL_geos_binop', PACKAGE = 'sf', sfc0, sfc1, op, par, pattern, sparse, prepared)
CPL_geos_binop <- function(sfc0, sfc1, op, par = 0.0, pattern = "", prepared = FALSE) {
.Call('_sf_CPL_geos_binop', PACKAGE = 'sf', sfc0, sfc1, op, par, pattern, prepared)
}

CPL_geos_is_valid_reason <- function(sfc) {
Expand Down Expand Up @@ -177,8 +109,8 @@ CPL_geos_snap <- function(sfc0, sfc1, tolerance) {
.Call('_sf_CPL_geos_snap', PACKAGE = 'sf', sfc0, sfc1, tolerance)
}

CPL_geos_op <- function(op, sfc, bufferDist, nQuadSegs = 30L, dTolerance = 0.0, preserveTopology = FALSE, bOnlyEdges = 1L, dfMaxLength = 0.0) {
.Call('_sf_CPL_geos_op', PACKAGE = 'sf', op, sfc, bufferDist, nQuadSegs, dTolerance, preserveTopology, bOnlyEdges, dfMaxLength)
CPL_geos_op <- function(op, sfc, bufferDist, nQuadSegs, dTolerance, preserveTopology, bOnlyEdges = 1L) {
.Call('_sf_CPL_geos_op', PACKAGE = 'sf', op, sfc, bufferDist, nQuadSegs, dTolerance, preserveTopology, bOnlyEdges)
}

CPL_geos_voronoi <- function(sfc, env, dTolerance = 0.0, bOnlyEdges = 1L) {
Expand All @@ -197,10 +129,6 @@ CPL_geos_dist <- function(sfc0, sfc1, which, par) {
.Call('_sf_CPL_geos_dist', PACKAGE = 'sf', sfc0, sfc1, which, par)
}

CPL_geos_relate <- function(sfc0, sfc1) {
.Call('_sf_CPL_geos_relate', PACKAGE = 'sf', sfc0, sfc1)
}

CPL_transpose_sparse_incidence <- function(m, n) {
.Call('_sf_CPL_transpose_sparse_incidence', PACKAGE = 'sf', m, n)
}
Expand Down
8 changes: 6 additions & 2 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ st_interpolate_aw = function(x, to, extensive) {
i = st_cast(i, "MULTIPOLYGON")
x$...area_s = unclass(st_area(x))
st_geometry(x) = NULL # sets back to data.frame
x = x[idx[,1], ] # create st table
x = x[idx[,1], ] # create st table
x$...area_st = unclass(st_area(i))
x$...area_t = unclass(st_area(to)[idx[,2]])

target = sapply(split(st_area(i), idx[, 2]), sum)
df = data.frame(area = target, idx = as.integer(names(target)))
x$...area_t = merge(data.frame(idx = idx[,2]), df)$area

x = if (extensive)
lapply(x, function(v) v * x$...area_st / x$...area_s)
else
Expand Down
1 change: 1 addition & 0 deletions R/cast_sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ which_sfc_col = function(cls) {
POLYGON = 2,
MULTIPOLYGON = 3,
GEOMETRYCOLLECTION = 4,
MULTISURFACE = 4,
GEOMETRY = 5,
stop(paste("st_cast for", cls, "not supported"))
)
Expand Down
13 changes: 10 additions & 3 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ st_read.DBIObject = function(dsn = NULL, layer = NULL, query = NULL,
st_sf(tbl, ...)
}

#' @export
st_read.Pool = function(dsn = NULL, layer = NULL, ...) {
if (! requireNamespace("pool", quietly = TRUE))
stop("package pool required, please install it first")
dsn = pool::poolCheckout(dsn)
on.exit(pool::poolReturn(dsn))
st_read(dsn, layer = layer, ...)
}


#' @export
st_read.PostgreSQLConnection <- function(...) {
st_read.DBIObject(...)
Expand Down Expand Up @@ -215,7 +225,6 @@ get_new_postgis_srid <- function(conn) {
#' @inheritParams RPostgreSQL::postgresqlWriteTable
#' @md
#' @rdname st_write
#' @importClassesFrom RPostgreSQL PostgreSQLConnection
#' @importMethodsFrom DBI dbWriteTable
#' @export
setMethod("dbWriteTable", c("PostgreSQLConnection", "character", "sf"),
Expand Down Expand Up @@ -245,7 +254,6 @@ setMethod("dbWriteTable", c("PostgreSQLConnection", "character", "sf"),
#' to PostgreSQL. See `dbDataType()` for details.
#' @md
#' @rdname st_write
#' @importClassesFrom RPostgreSQL PostgreSQLConnection
#' @importMethodsFrom DBI dbWriteTable
#' @export
setMethod("dbWriteTable", c("DBIObject", "character", "sf"),
Expand Down Expand Up @@ -295,7 +303,6 @@ sync_crs <- function(conn, geom) {
#' @export
#' @inheritParams RPostgreSQL dbDataType
#' @rdname dbDataType
#' @importClassesFrom RPostgreSQL PostgreSQLConnection
#' @importMethodsFrom DBI dbDataType
setMethod("dbDataType", c("PostgreSQLConnection", "sf"), function(dbObj, obj) {
dtyp <- vapply(obj, RPostgreSQL::dbDataType, character(1), dbObj = dbObj)
Expand Down
Loading

0 comments on commit a04233a

Please sign in to comment.