Title: | CORINE Land Cover Data and Styles |
---|---|
Description: | Streamline the management, analysis, and visualization of CORINE Land Cover data. Addresses challenges associated with its classification system and related styles, such as color mappings and descriptive labels. |
Authors: | Jose Samos [aut, cre] , Universidad de Granada [cph] |
Maintainer: | Jose Samos <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0.9000 |
Built: | 2024-12-14 06:32:51 UTC |
Source: | https://github.com/josesamos/clc |
Returns an object of class 'clc_raster' that contains a 'terra::SpatRaster' raster object representing the converted vector layer into raster format.
as_raster(clo, base_raster, resolution) ## S3 method for class 'clc' as_raster(clo, base_raster = NULL, resolution = NULL)
as_raster(clo, base_raster, resolution) ## S3 method for class 'clc' as_raster(clo, base_raster = NULL, resolution = NULL)
clo |
A 'clc' object. |
base_raster |
(Optional) A raster object to use as the base for rasterization. |
resolution |
(Optional) Numeric resolution to define the raster grid. |
The function requires either 'base_raster' or 'resolution' to be provided. If both are missing, an error is raised.
An object of class 'clc_raster'.
Other CLC class functions:
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") raster_path <- system.file("extdata", "mdt.tif", package = "clc") base_raster <- terra::rast(raster_path) # ex1 r <- clo |> as_raster(base_raster = base_raster) # ex2 r <- clo |> as_raster(resolution = 50)
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") raster_path <- system.file("extdata", "mdt.tif", package = "clc") base_raster <- terra::rast(raster_path) # ex1 r <- clo |> as_raster(base_raster = base_raster) # ex2 r <- clo |> as_raster(resolution = 50)
Create an object of class 'clc'.
clc(source, layer_name, field = NULL)
clc(source, layer_name, field = NULL)
source |
The source of the vector layer. This can be: - A string representing the path to a GeoPackage file. - A 'DBI' database connection object to a PostGIS database, created using [RPostgres::dbConnect()]. |
layer_name |
The name of the layer in the source to be used. |
field |
(Optional) A string, the layer field that contains CLC codes. If NULL, the function will attempt to locate the column containing the CLC codes. |
This function creates an object of class 'clc' from a vector layer in either a GeoPackage or a PostGIS database.
The layer must have a style defined in the source.
An object of class 'clc'.
Other CLC class functions:
as_raster()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
# ex1 source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") ## Not run: # ex2 conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clc(source = conn, layer_name = "clc") ## End(Not run)
# ex1 source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") ## Not run: # ex2 conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clc(source = conn, layer_name = "clc") ## End(Not run)
Each code represents a specific category at the most detailed level (Level 3) of the CLC system.
clc_codes
clc_codes
A vector of strings.
This function copies a style to the specified layers in a GeoPackage file or a PostGIS database. The destination is determined by the 'to' argument.
copy_to(clo, to, database, schema, layers) ## S3 method for class 'clc' copy_to(clo, to, database = NULL, schema = "public", layers = NULL)
copy_to(clo, to, database, schema, layers) ## S3 method for class 'clc' copy_to(clo, to, database = NULL, schema = "public", layers = NULL)
clo |
A 'clc' object. |
to |
A data destination for the output. This can be: - A string representing the path to a GeoPackage file. - A 'DBI' database connection object to a PostGIS database, created using [RPostgres::dbConnect()]. |
database |
A string, database name, only in case the destination is in PostGIS. |
schema |
A string, schema name, only in case the destination is in PostGIS. Defaults to ''public''. |
layers |
An optional character vector specifying the names of layers in the destination to which the styles should be applied. If 'NULL' (default), applies the style to all layers. |
clo A 'clc' object.
Other CLC class functions:
as_raster()
,
clc()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") out_gpkg <- tempfile(fileext = ".gpkg") clo <- clo |> save_to(out_gpkg) # ex1 clo <- clo |> copy_to(out_gpkg, layers = 'clc') ## Not run: conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clo |> save_to(conn, 'exampledb') # ex2 clo <- clo |> copy_to(conn, 'exampledb', layers = 'clc') ## End(Not run)
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") out_gpkg <- tempfile(fileext = ".gpkg") clo <- clo |> save_to(out_gpkg) # ex1 clo <- clo |> copy_to(out_gpkg, layers = 'clc') ## Not run: conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clo |> save_to(conn, 'exampledb') # ex2 clo <- clo |> copy_to(conn, 'exampledb', layers = 'clc') ## End(Not run)
This function clips the object layer using a polygon layer. It handles CRS transformations automatically if necessary, ensuring the output is in the same CRS as the input polygon.
cut_to_extent(clo, polygon) ## S3 method for class 'clc' cut_to_extent(clo, polygon)
cut_to_extent(clo, polygon) ## S3 method for class 'clc' cut_to_extent(clo, polygon)
clo |
A 'clc' object. |
polygon |
An 'sf' object representing the polygon layer used for clipping. |
A 'clc' object.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") polygon <- sf::st_read(source_gpkg, layer = 'lanjaron', quiet = TRUE) clo2 <- clo |> cut_to_extent(polygon)
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") polygon <- sf::st_read(source_gpkg, layer = 'lanjaron', quiet = TRUE) clo2 <- clo |> cut_to_extent(polygon)
This function extracts the color values associated with a CLC style definition. It returns a character vector containing the 'color' field from the CLC style definition.
## S3 method for class 'clc' get_colors(clo) get_colors(clo) ## S3 method for class 'clc_category' get_colors(clo) ## S3 method for class 'clc_raster' get_colors(clo)
## S3 method for class 'clc' get_colors(clo) get_colors(clo) ## S3 method for class 'clc_category' get_colors(clo) ## S3 method for class 'clc_raster' get_colors(clo)
clo |
A 'clc_category' object. |
A character vector of colors.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") levels <- clo |> get_colors()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") levels <- clo |> get_colors()
This function extracts the levels values associated with a CLC style definition. It returns a data frame that contains the fields 'id', 'description', and 'color' from the CLC style definition.
## S3 method for class 'clc' get_levels(clo) get_levels(clo) ## S3 method for class 'clc_category' get_levels(clo) ## S3 method for class 'clc_raster' get_levels(clo)
## S3 method for class 'clc' get_levels(clo) get_levels(clo) ## S3 method for class 'clc_category' get_levels(clo) ## S3 method for class 'clc_raster' get_levels(clo)
clo |
A CLC object. |
A data frame with columns: - 'id': The identifier of the category. - 'description': A textual description of the category. - 'color': The color associated with the category.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") levels <- clo |> get_levels()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") levels <- clo |> get_levels()
Retrieve a raster representation ('terra::SpatRaster') from a CLC object.
get_raster(clo) ## S3 method for class 'clc_raster' get_raster(clo)
get_raster(clo) ## S3 method for class 'clc_raster' get_raster(clo)
clo |
A 'clc_raster' object. |
A 'terra::SpatRaster' object.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
plot_clc()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") r <- clo |> as_raster(resolution = 50) clc_r <- r |> get_raster()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") r <- clo |> as_raster(resolution = 50) clc_r <- r |> get_raster()
Plot CLC data stored in objects of supported classes. The function adapts the plot based on the class of the input data (vectorial or raster format).
plot_clc(clo, ...) ## S3 method for class 'clc' plot_clc(clo, ...) ## S3 method for class 'clc_raster' plot_clc(clo, ...)
plot_clc(clo, ...) ## S3 method for class 'clc' plot_clc(clo, ...) ## S3 method for class 'clc_raster' plot_clc(clo, ...)
clo |
An object containing CLC data. This must be an instance of a supported class, such as: - A vectorial CLC data object (e.g., 'clc' object). - A raster CLC data object (e.g., 'clc_raster'). |
... |
Additional arguments passed to the 'terra::plot' function. |
For the raster version, the 'terra::plot' function is used with the 'col' parameter configured, while all other parameters supported by the function can also be defined (using '...').
For the vector version, 'ggplot2::ggplot' is used, and by using the 'prepare_plot' function instead of this one ('plot_clc'), further customization can be applied as needed.
A 'ggplot2' object or a 'terra' plot.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
prepare_plot()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") temp_file <- tempfile(fileext = ".png") png(filename = temp_file, width = 800, height = 600) clo |> plot_clc() dev.off()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") temp_file <- tempfile(fileext = ".png") png(filename = temp_file, width = 800, height = 600) clo |> plot_clc() dev.off()
Generates a 'ggplot2' object to visualize CLC Vectorial data. The function processes the data stored in a 'clc' object, ensuring that the codes field is mapped correctly to the categories and their associated styles.
prepare_plot(clo) ## S3 method for class 'clc' prepare_plot(clo)
prepare_plot(clo) ## S3 method for class 'clc' prepare_plot(clo)
clo |
A 'clc' object. |
A 'ggplot2' object ready for rendering.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
save_to()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") p <- clo |> prepare_plot() levels <- clo |> get_levels() p <- p + ggplot2::scale_fill_manual( values = stats::setNames(levels$color, levels$id), labels = stats::setNames(levels$description, levels$id), name = "" ) + ggplot2::theme( legend.position = "right", legend.key.height = ggplot2::unit(2, "cm"), legend.title = ggplot2::element_text(size = 12), legend.text = ggplot2::element_text(size = 10) ) + ggplot2::theme_minimal() temp_file <- tempfile(fileext = ".png") png(filename = temp_file, width = 800, height = 600) p dev.off()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") p <- clo |> prepare_plot() levels <- clo |> get_levels() p <- p + ggplot2::scale_fill_manual( values = stats::setNames(levels$color, levels$id), labels = stats::setNames(levels$description, levels$id), name = "" ) + ggplot2::theme( legend.position = "right", legend.key.height = ggplot2::unit(2, "cm"), legend.title = ggplot2::element_text(size = 12), legend.text = ggplot2::element_text(size = 10) ) + ggplot2::theme_minimal() temp_file <- tempfile(fileext = ".png") png(filename = temp_file, width = 800, height = 600) p dev.off()
This function saves a layer and its style to a GeoPackage file or a PostGIS database. The destination is determined by the 'to' argument.
save_to(clo, to, database, schema, layer_name) ## S3 method for class 'clc' save_to(clo, to, database = NULL, schema = "public", layer_name = NULL)
save_to(clo, to, database, schema, layer_name) ## S3 method for class 'clc' save_to(clo, to, database = NULL, schema = "public", layer_name = NULL)
clo |
A 'clc' object. |
to |
A data destination for the output. This can be: - A string representing the path to a GeoPackage file. - A 'DBI' database connection object to a PostGIS database, created using [RPostgres::dbConnect()]. |
database |
A string, database name, only in case the destination is in PostGIS. |
schema |
A string, schema name, only in case the destination is in PostGIS. Defaults to ''public''. |
layer_name |
A character string specifying the name of the layer in the output. If 'NULL', the name of the input 'layer' is used. |
The function overwrites the table if it already exists.
clo A 'clc' object.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") # ex1 out_gpkg <- tempfile(fileext = ".gpkg") sink(tempfile()) clo <- clo |> save_to(out_gpkg) sink() ## Not run: # ex2 conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clo |> save_to(conn, 'exampledb') ## End(Not run)
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc") clo <- clc(source = source_gpkg, layer_name = "clc") # ex1 out_gpkg <- tempfile(fileext = ".gpkg") sink(tempfile()) clo <- clo |> save_to(out_gpkg) sink() ## Not run: # ex2 conn <- RPostgres::dbConnect( RPostgres::Postgres(), dbname = 'exampledb', host = 'localhost', port = '5432', user = 'user', password = 'password' ) clo <- clo |> save_to(conn, 'exampledb') ## End(Not run)