项目作者: brazil-data-cube

项目描述 :
R Client Library for Web Land Trajectory Service
高级语言: R
项目地址: git://github.com/brazil-data-cube/rwlts.git
创建时间: 2020-11-12T19:08:53Z
项目社区:https://github.com/brazil-data-cube/rwlts

开源协议:Other

下载


" class="reference-link">rwlts

R Client Library for Web Land Trajectory Service (WLTS)

Software
License
Build Status
codecov
Software Life
Cycle
Join us at
Discord

About

Information on Land Use and Land Cover (LULC) is essential to support
governments in making decisions about the impact of human activities on
the environment, planning the use of natural resources, conserving
biodiversity and monitoring climate change.

Currently, several projects systematically provide information on the
dynamics of land use and cover. Well known projects include PRODES,
DETER and TerraClass. These projects are developed by INPE and they
produce information on land use and coverage used by the Brazilian
Government to make public policy decisions. Besides these projects there
are other initiatives from universities and space agencies devoted to
the creation of national and global maps.

Although these projects follow open data policies and provide a rich
collection of data, there is still a gap in tools that facilitate the
integrated use of these collections. Each project adopts its own land
use and land cover classification system, providing different class
names and meanings for the elements of these collections. The forms of
distribution of project data can be carried out in different ways,
through files or web services. In addition, the data has different
spatial and temporal resolutions and storage systems (raster or vector).

In this context, the Web Land Trajectory Service (WLTS)
is a service that aims to facilitate the access to these approach
consists of using a data model that defines a minimum set of temporal
and spatial information to represent different sources and types of
data, but with a focus on land use and land cover.

WLTS can be used in a variety of applications, such as validating land
cover data sets, selecting training samples to support Machine Learning
algorithms used in the generation of new classification maps.

If you want to know more about WLTS service, please, take a look at its
specification.

Installation

To install the development version of rwlts, run the following
commands:

  1. # load necessary libraries
  2. library(devtools)
  3. devtools::install_github("brazil-data-cube/rwlts")

Importing rwlts package:

  1. library(rwlts)

Usage

rwlts implements the following WLTS operations:

WLTS operations rwlts functions
/list_collections list_collections(URL,)
/describe_collections describe_collection(URL, collection_id)
/trajectory get_trajectory(URL, latitude, longitude)

These functions can be used to retrieve information from a WLTS API
service. The code bellow creates a wlts object and list the available
collections of the WLTS API of the Brazil Data Cube project of the
Brazilian National Institute for Space Research INPE.

List Collections

The first operation, list_collections, retrieves all available
collections in WLTS service.

  1. wlts_bdc <- "https://brazildatacube.dpi.inpe.br/wlts/"
  2. list_collections(wlts_bdc)
  3. #> [1] "lapig_areas_pastagem" "terraclass_amazonia"
  4. #> [3] "deter_amazonia_legal" "deter_cerrado"
  5. #> [5] "ibge_cobertura_uso_terra" "prodes_amazonia_legal"
  6. #> [7] "prodes_cerrado" "mapbiomas_caatinga-v5"
  7. #> [9] "mapbiomas_cerrado-v5" "mapbiomas_amazonia-v5"
  8. #> [11] "terraclass_amazonia-v2" "mapbiomas_pantanal-v5"
  9. #> [13] "mapbiomas_pampa-v5" "terraclass_cerrado"
  10. #> [15] "mapbiomas_mata_atlantica-v5"

Describe Collection

Each collection returned by the WLTS service can be used for retrieving
LULC trajectories. To get information about the collections, we use the
describe_collection function. This function returns the metadata of a
given collection, which includes the description and specific details.
The metadata also describes the spatio-temporal extent of the
collection.

In the code below, we retrieve the metadata from the
deter_amazonia_legal collection using the describe_collection
function.

  1. describe_collection(wlts_bdc, "deter_amazonia_legal")
  2. #> $classification_system
  3. #> $classification_system$classification_system_id
  4. #> [1] "21"
  5. #>
  6. #> $classification_system$classification_system_name
  7. #> [1] "DETER Amazônia Legal"
  8. #>
  9. #> $classification_system$classification_system_version
  10. #> [1] "1.0"
  11. #>
  12. #> $classification_system$type
  13. #> [1] "Self"
  14. #>
  15. #>
  16. #> $collection_type
  17. #> [1] "Feature"
  18. #>
  19. #> $description
  20. #> [1] "Alertas de Desmatamento da Amazônia Legal."
  21. #>
  22. #> $detail
  23. #> [1] "O DETER é um levantamento rápido de alertas de evidências de alteração da cobertura florestal na Amazônia, feito pelo INPE. O DETER foi desenvolvido como um sistema de alerta para dar suporte à fiscalização e controle de desmatamento e da degradação florestal realizadas pelo Instituto Brasileiro do Meio Ambiente e dos Recursos Naturais Renováveis (IBAMA) e demais órgãos ligados a esta temática. Mais informações acesse: http://www.obt.inpe.br/OBT/assuntos/programas/amazonia/deter"
  24. #>
  25. #> $name
  26. #> [1] "deter_amazonia_legal"
  27. #>
  28. #> $period
  29. #> $period$end_date
  30. #> [1] "2020-06-18"
  31. #>
  32. #> $period$start_date
  33. #> [1] "2016-08-02"
  34. #>
  35. #>
  36. #> $resolution_unit
  37. #> $resolution_unit$unit
  38. #> [1] "DAY"
  39. #>
  40. #> $resolution_unit$value
  41. #> [1] 1
  42. #>
  43. #>
  44. #> $spatial_extent
  45. #> $spatial_extent$xmax
  46. #> [1] -44.00039
  47. #>
  48. #> $spatial_extent$xmin
  49. #> [1] -73.54909
  50. #>
  51. #> $spatial_extent$ymax
  52. #> [1] 4.555376
  53. #>
  54. #> $spatial_extent$ymin
  55. #> [1] -18.03644

Trajectory

LULC trajectories can be extracted from collections. These LULC
trajectories in WLTS services are associated with a point (lat, long) in
geographic space. In rwlts, we can use the get_trajectory function
to retrieve trajectories. For example, in the code below, the point
(-54, -12) trajectory is retrieved from the mapbiomas_amazonia-v5
collection.

  1. get_trajectory(wlts_bdc,
  2. latitude = -12,
  3. longitude = -54,
  4. collections = "mapbiomas_amazonia-v5",
  5. config = httr::add_headers("x-api-key" = "change-me"))
  6. #> $query
  7. #> NULL
  8. #>
  9. #> $result
  10. #> # A tibble: 35 × 4
  11. #> class collection date point_id
  12. #> <chr> <chr> <chr> <int>
  13. #> 1 Formação Florestal mapbiomas_amazonia-v5 1985 1
  14. #> 2 Formação Florestal mapbiomas_amazonia-v5 1986 1
  15. #> 3 Formação Florestal mapbiomas_amazonia-v5 1987 1
  16. #> 4 Formação Florestal mapbiomas_amazonia-v5 1988 1
  17. #> 5 Formação Florestal mapbiomas_amazonia-v5 1989 1
  18. #> 6 Formação Florestal mapbiomas_amazonia-v5 1990 1
  19. #> 7 Formação Florestal mapbiomas_amazonia-v5 1991 1
  20. #> 8 Formação Florestal mapbiomas_amazonia-v5 1992 1
  21. #> 9 Formação Florestal mapbiomas_amazonia-v5 1993 1
  22. #> 10 Formação Florestal mapbiomas_amazonia-v5 1994 1
  23. #> # … with 25 more rows
  24. #>
  25. #> attr(,"class")
  26. #> [1] "wlts"

The get_trajectory function returns a list of class wlts. This
object contains the query and result attributes. The query
attribute stores the query performed to retrieve the data. By default,
it will be NULL. For this information to be stored, the
query_info = TRUE parameter is required. For example:

  1. get_trajectory(wlts_bdc,
  2. latitude = -12,
  3. longitude = -54,
  4. collections = "mapbiomas_amazonia-v5",
  5. query_info = TRUE,
  6. config = httr::add_headers("x-api-key" = "change-me"))

The result attribute stores the retrieved trajectories. The data is
stored in a tibble for easy manipulation, which has the columns:

  • class: LULC class;
  • collection: Data Collection;
  • date: Time instants of the trajectory;
  • point_id: ID of the point that was queried.

The point_id column of the result tibble is used in rwlts to
identify the entry point. This ID is necessary since the
get_trajectory function can be used with vectors as input. For
example, the code below retrieves the trajectory of data from the
mapbiomas_amazonia-v5 collection for two points (-54, -12) and
(-54, -11.01).

  1. get_trajectory(wlts_bdc,
  2. latitude = c(-12, -11.01),
  3. longitude = c(-54, -54),
  4. collections = "mapbiomas_amazonia-v5",
  5. config = httr::add_headers("x-api-key" = "change-me"))
  6. #> $query
  7. #> NULL
  8. #>
  9. #> $result
  10. #> # A tibble: 70 × 4
  11. #> class collection date point_id
  12. #> <chr> <chr> <chr> <int>
  13. #> 1 Formação Florestal mapbiomas_amazonia-v5 1985 1
  14. #> 2 Formação Florestal mapbiomas_amazonia-v5 1986 1
  15. #> 3 Formação Florestal mapbiomas_amazonia-v5 1987 1
  16. #> 4 Formação Florestal mapbiomas_amazonia-v5 1988 1
  17. #> 5 Formação Florestal mapbiomas_amazonia-v5 1989 1
  18. #> 6 Formação Florestal mapbiomas_amazonia-v5 1990 1
  19. #> 7 Formação Florestal mapbiomas_amazonia-v5 1991 1
  20. #> 8 Formação Florestal mapbiomas_amazonia-v5 1992 1
  21. #> 9 Formação Florestal mapbiomas_amazonia-v5 1993 1
  22. #> 10 Formação Florestal mapbiomas_amazonia-v5 1994 1
  23. #> # … with 60 more rows
  24. #>
  25. #> attr(,"class")
  26. #> [1] "wlts"

In this case, the point (-54, -12) will have point_id equal to 1,
while (-54, -11.01) will have point_id equal to 2.

In addition to multiple point retrieval, the get_trajectory function
allows multiple collections to be queried for the composition of the
trajectory. To do this, in the collections parameter, the collections
must be assigned. For example, data from the collections
mapbiomas_amazonia-v5 and terraclass_amazonia-v2 are retrieved in
the code below.

  1. get_trajectory(wlts_bdc,
  2. latitude = c(-12, -11.01),
  3. longitude = c(-54, -54),
  4. collections = c("mapbiomas_amazonia-v5", "terraclass_amazonia-v2"),
  5. config = httr::add_headers("x-api-key" = "change-me"))
  6. #> $query
  7. #> NULL
  8. #>
  9. #> $result
  10. #> # A tibble: 80 × 4
  11. #> class collection date point_id
  12. #> <chr> <chr> <chr> <int>
  13. #> 1 Formação Florestal mapbiomas_amazonia-v5 1985 1
  14. #> 2 Formação Florestal mapbiomas_amazonia-v5 1986 1
  15. #> 3 Formação Florestal mapbiomas_amazonia-v5 1987 1
  16. #> 4 Formação Florestal mapbiomas_amazonia-v5 1988 1
  17. #> 5 Formação Florestal mapbiomas_amazonia-v5 1989 1
  18. #> 6 Formação Florestal mapbiomas_amazonia-v5 1990 1
  19. #> 7 Formação Florestal mapbiomas_amazonia-v5 1991 1
  20. #> 8 Formação Florestal mapbiomas_amazonia-v5 1992 1
  21. #> 9 Formação Florestal mapbiomas_amazonia-v5 1993 1
  22. #> 10 Formação Florestal mapbiomas_amazonia-v5 1994 1
  23. #> # … with 70 more rows
  24. #>
  25. #> attr(,"class")
  26. #> [1] "wlts"

Finally, the get_trajectory function, through the start_date and
end_date parameters, allows you to specify the time intervals used in
the trajectory. To exemplify its use, in the code below, trajectories
are retrieved for the points (-54, -12) and (-54, -11.01), from the
mapbiomas_amazonia-v5 and terraclass_amazonia-v2 collections in the
time interval [2003-01-01, 2004-01-01].

  1. get_trajectory(wlts_bdc,
  2. latitude = c(-12, -11.01),
  3. longitude = c(-54, -54),
  4. start_date = "2003-01-01",
  5. end_date = "2004-01-01",
  6. collections = c("mapbiomas_amazonia-v5","terraclass_amazonia-v2"),
  7. config = httr::add_headers("x-api-key" = "change-me"))
  8. #> $query
  9. #> NULL
  10. #>
  11. #> $result
  12. #> # A tibble: 6 × 4
  13. #> class collection date point_id
  14. #> <chr> <chr> <chr> <int>
  15. #> 1 Formação Florestal mapbiomas_amazonia-v5 2003 1
  16. #> 2 Formação Florestal mapbiomas_amazonia-v5 2004 1
  17. #> 3 Vegetação Natural Florestal Primária terraclass_amazonia-v2 2004 1
  18. #> 4 Formação Florestal mapbiomas_amazonia-v5 2003 2
  19. #> 5 Formação Florestal mapbiomas_amazonia-v5 2004 2
  20. #> 6 Vegetação Natural Florestal Primária terraclass_amazonia-v2 2004 2
  21. #>
  22. #> attr(,"class")
  23. #> [1] "wlts"

Alluvial plot

To visualize the trajectories and fully understand their time dynamics,
the rwlts package implements the Alluvial-based visualization method.
To create this plot, use the plot function, as shown in the example
below:

  1. # import data from package
  2. data("mt_500_mapbiomas_cerrado")
  3. plot(mt_500_mapbiomas_cerrado)

Besides, you can fully customize the returned plot. This customization
is possible since the plot function returns a ggplot2 object.

  1. library(ggplot2)
  2. library(ggalluvial) # use to create plot
  3. library(cowplot) # use different theme
  4. plot(mt_500_mapbiomas_cerrado, show_count = TRUE) +
  5. cowplot::theme_minimal_hgrid() +
  6. labs(title = "Changes in Primavera do Leste (2004-2014)",
  7. x = "Timeline",
  8. y = "Number of points",
  9. fill = "Class") +
  10. theme(legend.position = "bottom",
  11. plot.title = element_text(hjust = 0.5)) +
  12. scale_fill_manual(values = c("#129912",
  13. "#32CD32",
  14. "#BDB76B",
  15. "#FFD966",
  16. "#FFFFB2"),
  17. labels = c("Formação Florestal",
  18. "Formação Savânica",
  19. "Outras Lavouras Temporárias",
  20. "Pastagem",
  21. "Soja"))

The numbers inside each bar correspond to the quantity of points
extracted in each year. You can see that according to the change of
LULC classes, the quantity of points in each class also changes.

License

Copyright (C) 2021 INPE.

R client for WLTS is free software; you can redistribute it and/or
modify it under the terms of the MIT License; see LICENSE file for more
details.