Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 4, 2025
1 parent 183d9cf commit 2cf429f
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
## new

- `$<SpatRaster>` can now be used to get a categorical SpatRaster with a different active category
- `scale_linear<SpatRaster>` method for linear scaling of cell values between a minumum and maximum value such as 0 and 1
- `scale_linear<SpatRaster>` method for linear scaling of cell values between a minimum and maximum value such as 0 and 1
- `distance` and related methods get argument "method" to choose the distance algorithm for lon/lat data [#1677](https://github.com/rspatial/terra/issues/1677) by Márcia Barbosa
- `divide<SpatRaster>` and `divide<SpatVector>` methods
- `nseg` counts the number of segments in a SpatVector [#1647](https://github.com/rspatial/terra/pull/1674) by Michael Chirico
Expand All @@ -60,7 +60,7 @@ Released 2024-12-12
- `buffer<SpatVector>` is now more accurate buffers for lonlat polygons [#1616](https://github.com/rspatial/terra/issues/1616) by Roberto Amaral-Santos
- `terra:interpNear` used square windows, not circles, beyond 100 points [#1509](https://github.com/rspatial/terra/issues/1509) by Jean-Luc Dupouey
- `vect` read INT64 fields as integers, sometimes leading to overflows. [#1666](https://github.com/rspatial/terra/issues/1666) by bengannon-fc
- `plot` showed a legend title even if none was requestd if title parameters were specified . [#1664](https://github.com/rspatial/terra/issues/1664) by Márcia Barbosa
- `plot` showed a legend title even if none was requested if title parameters were specified . [#1664](https://github.com/rspatial/terra/issues/1664) by Márcia Barbosa

## enhancements

Expand Down
2 changes: 1 addition & 1 deletion man/datatype.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The following raster datatypes are available:

For all integer types, except the single byte types, the lowest (signed) or highest (unsigned) value is used to store \code{NA}.

Note that very large integer numbers may be inpreceise as they are internally represented as decimal numbers.
Note that very large integer numbers may be imprecise as they are internally represented as decimal numbers.

\code{INT4U} is available but they are best avoided as R does not support 32-bit unsigned integers.
}
Expand Down
2 changes: 1 addition & 1 deletion man/divide.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Divides a \code{SpatVector} of polygons into \code{n} compact and approximately


\value{
SpatVector or SpatRaster, or a list with bith
SpatVector or SpatRaster, or a list with both
}


Expand Down
2 changes: 1 addition & 1 deletion man/extract.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Alternatively, you can use \code{\link{zonal}} after using \code{\link{rasterize
\item{layer}{character or numeric to select the layer to extract from for each geometry. If \code{layer} is a character it can be a name in \code{y} or a vector of layer names. If it is numeric, it must be integer values between \code{1} and \code{nlyr(x)}}
\item{bind}{logical. If \code{TRUE}, a SpatVector is returned consisting of the input SpatVector \code{y} and the \code{cbind}-ed extracted values}
\item{raw}{logical. If \code{TRUE}, a matrix is returned with the "raw" numeric cell values. If \code{FALSE}, a data.frame is returned and the cell values are transformed to factor, logical, or integer values, where appropriate}
\item{search_radius}{positive number. A search-radius that is used when \code{y} has point geometry. If this value is larger than zero, it is the maximum distance used to find the a cell with a value that is nearest to the cell that the point falls in if that cell that has a missing (\code{NA}) value. The value of this nearest cell, the distance to the original cell, and the new cell number are returned. The radius should be expressed in m if the data have lon/lat coordinates or in the distance unit of the crs in other cases (typically also m). For lon/lat data, the mean latitude of the points is used to compute the distances, so this may be inprecise for data with a large latitudinal range}
\item{search_radius}{positive number. A search-radius that is used when \code{y} has point geometry. If this value is larger than zero, it is the maximum distance used to find the a cell with a value that is nearest to the cell that the point falls in if that cell that has a missing (\code{NA}) value. The value of this nearest cell, the distance to the original cell, and the new cell number are returned. The radius should be expressed in m if the data have lon/lat coordinates or in the distance unit of the crs in other cases (typically also m). For lon/lat data, the mean latitude of the points is used to compute the distances, so this may be imprecise for data with a large latitudinal range}
\item{...}{additional arguments to \code{fun} if \code{y} is a SpatVector. For example \code{na.rm=TRUE}. Or arguments passed to the \code{SpatRaster,SpatVector} method if \code{y} is a matrix (such as the \code{method} and \code{cells} arguments)}
}

Expand Down
2 changes: 1 addition & 1 deletion man/geometry.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Get the geometry of a SpatVector. If \code{wkt=FALSE}, this is a five-column matrix or data.frame: the vector object ID, the IDs for the parts of each object (e.g. five polygons that together are one spatial object), the x (longitude) and y (latitude) coordinates, and a flag indicating whether the part is a "hole" (only relevant for polygons).

If \code{wkt=TRUE}, the "well-known text" representation is returned as a character vector.
If \code{hex=TRUE}, the "hexademical" representation is returned as a character vector.
If \code{hex=TRUE}, the "hexadecimal" representation is returned as a character vector.
If \code{wkb=TRUE}, the "well-known binary" representation is returned as a list of raw vectors.
}

Expand Down
2 changes: 1 addition & 1 deletion man/lines.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ These methods also work for a small(!) SpatRaster. Only cells that are not NA in
\item{alpha}{number between 0 and 1 to set transparency}
\item{lwd}{numeric, line-width. See \code{\link{par}}}
\item{lty}{positive integer, line type. See \code{\link{par}}}
\item{arrows}{logical. If \code{TRUE} and \code{y} is a SpatVector, arrows are drawn intead of lines. See \code{?\link{arrows}} for additional arguments}
\item{arrows}{logical. If \code{TRUE} and \code{y} is a SpatVector, arrows are drawn instead of lines. See \code{?\link{arrows}} for additional arguments}
\item{mx}{positive number. If the number of cells of SpatRaster \code{x} is higher, the method will fail with an error message}
\item{dissolve}{logical. Should boundaries between cells with the same value be removed?}
\item{...}{additional graphical arguments such as \code{lwd}, \code{cex} and \code{pch}}
Expand Down
2 changes: 1 addition & 1 deletion man/plot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis
\item{background}{background color. Default is no color (white)}
\item{box}{logical. Should a box be drawn around the map?}
\item{clip}{logical. Should the axes be clipped to the extent of \code{x}?}
\item{overview}{logical. Should "overviews" be used for fast rendering? This can result in much faster plotting of raster files that have overvies (e.g. "COG" format) and are accessed over a http connection. However, these overviews generally show aggregate values, thus reducing the range of the actual values. If \code{NULL}, the argument is set to \code{TRUE} for rasters that are accessed over http and \code{FALSE} in other cases}
\item{overview}{logical. Should "overviews" be used for fast rendering? This can result in much faster plotting of raster files that have overviews (e.g. "COG" format) and are accessed over a http connection. However, these overviews generally show aggregate values, thus reducing the range of the actual values. If \code{NULL}, the argument is set to \code{TRUE} for rasters that are accessed over http and \code{FALSE} in other cases}
\item{plg}{list with parameters for drawing the legend. For the classes and interval type legend see the arguments for \code{\link[graphics]{legend}}. For example \code{x} and \code{y} can be used to place the legend. You can also use keywords such as "topleft" and "bottomright" to place the legend at these locations inside the map rectangle.

Some of these do not apply to a continuous legend, or they behave a little differently. For example, only the placement keywords "left", "right", "top", and "bottom" are recognized; and when using these keywords, the legend is placed outside of the map rectangle. Additional parameters for continuous legends include:
Expand Down
2 changes: 1 addition & 1 deletion man/predict.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This approach of using model predictions is commonly used in remote sensing (for
\item{...}{additional arguments for \code{fun}}

\item{const}{data.frame. Can be used to add a constant value as a predictor variable so that you do not need to make a SpatRaster layer for it}
\item{na.rm}{logical. If \code{TRUE}, cells with \code{NA} values in the any of the layers of \code{x} are removed from the computation (even if the \code{NA} cell is in a layer that is not used as a variable in the model). This option prevents errors with models that cannot handle \code{NA} values when makeing predictions. In most other cases this will not affect the output. However, there are some models that return predicted values even if some (or all) variables are \code{NA} }
\item{na.rm}{logical. If \code{TRUE}, cells with \code{NA} values in the any of the layers of \code{x} are removed from the computation (even if the \code{NA} cell is in a layer that is not used as a variable in the model). This option prevents errors with models that cannot handle \code{NA} values when making predictions. In most other cases this will not affect the output. However, there are some models that return predicted values even if some (or all) variables are \code{NA} }
\item{index}{integer or character. Can be used to to select a subset of the model output variables}
\item{cores}{positive integer. If \code{cores > 1}, a 'parallel' package cluster with that many cores is created and used}
\item{cpkgs}{character. The package(s) that need to be loaded on the nodes to be able to run the model.predict function (see examples)}
Expand Down
2 changes: 1 addition & 1 deletion man/rast.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A SpatRaster represents a spatially referenced surface divided into three dimens

When a SpatRaster is created from one or more files, it does not load the cell (pixel) values into memory (RAM). It only reads the parameters that describe the geometry of the SpatRaster, such as the number of rows and columns and the coordinate reference system. The actual values will be read when needed.

Note that there are operating system level limitations to the number of files that can be opened simulatenously. Using a SpatRaster of very many files (e.g. 10,000) may cause R to crash when you use it in a computation. In situations like that you may need to split up the task or combine data into fewer (multi-layer) files. Also note that the GTiff format used for temporary files cannot store more than 65535 layers in a single file.
Note that there are operating system level limitations to the number of files that can be opened simultaneously. Using a SpatRaster of very many files (e.g. 10,000) may cause R to crash when you use it in a computation. In situations like that you may need to split up the task or combine data into fewer (multi-layer) files. Also note that the GTiff format used for temporary files cannot store more than 65535 layers in a single file.
}

\usage{
Expand Down
2 changes: 1 addition & 1 deletion man/writeCDF.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Always use the \code{".nc"} or \code{".cdf"} file extension to assure that the f
\item{unit}{character. Unit of the data}
\item{split}{logical. If \code{TRUE} each layer of \code{x} is treated as a sub-dataset}
\item{atts}{character. A vector of additional global attributes to write. The must be formatted like c("x=a value", "y=abc")}
\item{gridmap}{character. The crs is always writting to the file in standard formats. With this argument you can also write the format commonly used in netcdf files. Something like \code{c("grid_mapping_name=lambert_azimuthal_equal_area", "longitude_of_projection_origin=10", "latitude_of_projection_origin=52", "false_easting=4321000", "false_northing=3210000")}}
\item{gridmap}{character. The crs is always written to the file in standard formats. With this argument you can also write the format commonly used in netcdf files. Something like \code{c("grid_mapping_name=lambert_azimuthal_equal_area", "longitude_of_projection_origin=10", "latitude_of_projection_origin=52", "false_easting=4321000", "false_northing=3210000")}}
\item{overwrite}{logical. If \code{TRUE}, \code{filename} is overwritten}
\item{zname}{character. The name of the "time" dimension}
\item{prec}{character. One of "double", "float", "integer", "short", "byte" or "char"}
Expand Down
13 changes: 8 additions & 5 deletions src/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ void SpatRaster::readRowColBlock(size_t src, std::vector<std::vector<double>> &o
// if (rows[j] >= rend) break; // if rows are sorted
if ((rows[j] >= rstart) && (rows[j] < rend)) {
size_t cell = (rows[j]-rstart) * nc + cols[j];
for (size_t k=outstart; k<outend; k++) {
out[k][j] = v[cell + k];
for (size_t lyr=0; lyr<nl; lyr++) {
size_t off = lyr * bs.nrows[i] * nc;
for (size_t k=outstart; k<outend; k++) {
out[k][j] = v[cell+off];
}
}
}
}
Expand Down Expand Up @@ -1231,7 +1234,7 @@ std::vector<std::vector<double>> SpatRaster::extractCell(std::vector<double> &ce
std::vector<std::vector<int_64>> rc, wrc;
rc = rowColFromCell(cell);

size_t n = cell.size();
size_t n = cell.size();
if (!hasValues()) {
std::vector<std::vector<double>> out(nlyr(), std::vector<double>(n, NAN));
return out;
Expand Down Expand Up @@ -1282,8 +1285,8 @@ std::vector<std::vector<double>> SpatRaster::extractCell(std::vector<double> &ce
}
} else {
#ifdef useGDAL
size_t pos = source[0].filename.find("https://");
if ((pos != std::string::npos) && (rc[0].size() > 200)) {
size_t pos = source[src].filename.find("https://");
if ((pos != std::string::npos)) { // && (rc[0].size() > 200)) {
if (win) {
readRowColBlock(src, out, lyr, wrc[0], wrc[1]);
} else {
Expand Down
15 changes: 6 additions & 9 deletions src/read_gdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,12 +1679,9 @@ void SpatRaster::readRowColGDAL(size_t src, std::vector<std::vector<double>> &ou
return;
}


std::vector<size_t> lyrs = source[src].layers;
size_t nl = lyrs.size();

size_t outend = outstart + nl;
// lyrs.size();

size_t fnr = nrow() - 1;
if (source[src].flipped) {
Expand All @@ -1701,8 +1698,8 @@ void SpatRaster::readRowColGDAL(size_t src, std::vector<std::vector<double>> &ou
}
}

for (size_t j=outstart; j<outend; j++) {
out[j] = std::vector<double> (n, NAN);
for (size_t i=outstart; i<outend; i++) {
out[i] = std::vector<double> (n, NAN);
}

int_64 nr1 = nrow()-1;
Expand All @@ -1715,8 +1712,8 @@ void SpatRaster::readRowColGDAL(size_t src, std::vector<std::vector<double>> &ou
if ((cols[i] < 0) || (cols[i] > nc1) || (rows[i] < 0) || (rows[i] > nr1) ) continue;
err = poDataset->RasterIO(GF_Read, cols[i], rows[i], 1, 1, &value[0], 1, 1, GDT_Float64, nl, NULL, 0, 0, 0, NULL);
if (err == CE_None) {
for (size_t j=outstart; j<outend; j++) {
out[j][i] = value[j];
for (size_t j=0; j<nl; j++) {
out[outstart+j][i] = value[j];
}
} else {
break;
Expand All @@ -1727,8 +1724,8 @@ void SpatRaster::readRowColGDAL(size_t src, std::vector<std::vector<double>> &ou
if ((cols[i] < 0) || (rows[i] < 0)) continue;
err = poDataset->RasterIO(GF_Read, cols[i], rows[i], 1, 1, &value[0], 1, 1, GDT_Float64, nl, &panBandMap[0], 0, 0, 0, NULL);
if (err == CE_None) {
for (size_t j=outstart; j<outend; j++) {
out[j][i] = value[j];
for (size_t j=0; j<nl; j++) {
out[outstart+j][i] = value[j];
}
} else {
break;
Expand Down

0 comments on commit 2cf429f

Please sign in to comment.