The lczexplore package was developped thanks to the PAENDORA2 (Pour la gestion du confort estival : Données, Outils et Recherche-Action, 2022 -2025, funded by ADEME, a French agency for ecological transition).
The purpose of this package is to easily compare different local
climate zone (LCZ) classifications on the same study territory. For
these LCZ, the repr="standard" representation sets proper
levels and colors by default. You can read the
lczexplore_english vignette for an overview.
This vignette deals with other cases, when repr="alter",
that is:
- when one groups LCZ levels into broader categories,
- when LCZ levels are expressed in an unexpected format,
- or even compares maps of other qualitative variables.
The package lczexplore allows to group several Local
Climate Zone levels (LCZ) into broader categories . The
groupLCZ function allows this grouping, and the main
functions of the package allow to specify the expected levels and colors
to use.
First, let’s load the example data of Redon City.
library(lczexplore)
dirPath <- system.file("extdata/multipleWfs/Redon", package = "lczexplore")
redonOSM <- importLCZvect(dirPath = dirPath, file = "osm_lcz.fgb", column = "LCZ_PRIMARY")
redonBDT <- importLCZvect(dirPath = dirPath, file = "bdt_lcz.fgb", column = "LCZ_PRIMARY")
#If we compare the LCZ classifications produced with GeoClimate and OpenStreetMAp and French BDTOPO data, we can see they seem to quite disagree.
comparison <- compareLCZ(sf1 = redonBDT, column1 = "LCZ_PRIMARY", wf1 = "BD TOPO v2.2",
sf2 = redonOSM, column2 = "LCZ_PRIMARY", wf2 = "Open Street Map", ref = 1,
repr = "standard", exwrite = FALSE, location = "Redon", saveG = "")
#> The column LCZ_PRIMARY of the dataset sf1 is the reference against which the LCZ_PRIMARY column of the dataset sf2 will be compared.
#> For Technical reason in this package, worfklow names can't contain spaces or underscores, they were replaced by dots
#> Workflow names are used in produced graphics and as column names, long names are not suitable,
#> the first 3 and last 3 letters were kept instead
#> For Technical reason in this package, worfklow names can't contain spaces or underscores, they were replaced by dots
#> Workflow names are used in produced graphics and as column names, long names are not suitable,
#> the first 3 and last 3 letters were kept instead
#> Both sf datasets need to live in the same crs projection (srid / epsg),
#> they will be coerced to the specified reference (sf1)
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometriesBut maybe the disagreement is not as strong as it seems. One may want to see, for example, if the urban envelopes differ that much. Let’s group all the urban LCZ levels in a category and all the vegetation in another one, the remaining LCZ being their own categories.
Use the groupLCZ function, set the dataset with the
argument sf and the column with column. Then
pass as many vectors as there are grouped category, each of them
containing the levels to be grouped together. The newly created
categories will be stored in the outCol column. If the user
doesn’t specify any name, by default the column is called
"grouped".
The newly created dataset can be mapped with showLCZ
function. At this point, we pass the names of the new categories present
in the “grouped” column to an LCZlevels vector and the colors associated
as a colors vector.
redonOSMgrouped <- groupLCZ(redonOSM, column = "LCZ_PRIMARY",
urban = c("1", "2", "3", "4", "5", "6", "7", "8", "9"),
industry = "10",
vegetation = c("101", "102", "103", "104"),
impervious = "105", pervious = "106", water = "107",
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 3, 4, 7, 10, 103, 106
#> Warning: Unknown levels in `f`: 1, 3, 4, 7, 10, 103, 106
levCol(sf = redonOSMgrouped, column = "grouped", LCZlevels = c("urban", "industry", "vegetation", "impervious", "pervious", "water"),
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
map1 <- showLCZ(redonOSMgrouped, column = "grouped", repr = "alter", wf = "OSM",
LCZlevels = c("urban", "industry", "vegetation", "impervious", "pervious", "water"),
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #3dff3a
#> One vector of levels, one vector of colors, either the same length (case 9: and 10:), or colors longer (case 12:, unused colors were dropped),
#> reduced to 6: A single vector was provided, whose names don't cover the levels in the data,
#> missing levels were assigned random colors.alter representationAs for standard LCZ, we use the compareLCZ function. We
specify the names of the sf1 and sf2 objects
containing the data, and the names of the column1 and
column2 containing the newly grouped categories.
redonBDTgrouped <- groupLCZ(redonBDT, column = "LCZ_PRIMARY",
urban = c("1", "2", "3", "4", "5", "6", "7", "8", "9"),
industry = "10",
vegetation = c("101", "102", "103", "104"),
impervious = "105", pervious = "106", water = "107",
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
#> Warning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
map1.1 <- showLCZ(redonBDTgrouped, column = "grouped", repr = "alter", wf = "OSM",
LCZlevels = c("urban", "industry", "vegetation", "impervious", "pervious", "water"),
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #ffcca3
#> One vector of levels, one vector of colors, either the same length (case 9: and 10:), or colors longer (case 12:, unused colors were dropped),
#> reduced to 6: A single vector was provided, whose names don't cover the levels in the data,
#> missing levels were assigned random colors.
comparisonGrouped <- compareLCZ(sf1 = redonOSMgrouped, column1 = "grouped", wf1 = "osmGpd",
sf2 = redonBDTgrouped, column2 = "grouped", wf2 = "bdtGpd",
repr = "alter",
levels = c("urban", "industry", "vegetation", "impervious", "pervious", "water"),
colors = c("red", "black", "green", "grey", "burlywood", "blue"))
#> The column grouped of the dataset sf1 is the reference against which the grouped column of the dataset sf2 will be compared.
#> Both sf datasets need to live in the same crs projection (srid / epsg),
#> they will be coerced to the specified reference (sf1)
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #d308b1
#> One vector of levels, one vector of colors, either the same length (case 9: and 10:), or colors longer (case 12:, unused colors were dropped),
#> reduced to 6: A single vector was provided, whose names don't cover the levels in the data,
#> missing levels were assigned random colors.
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: redstandard LCZ types detected, the standard colors will be associated to them: blackstandard LCZ types detected, the standard colors will be associated to them: greenstandard LCZ types detected, the standard colors will be associated to them: greystandard LCZ types detected, the standard colors will be associated to them: burlywoodstandard LCZ types detected, the standard colors will be associated to them: bluestandard LCZ types detected, the standard colors will be associated to them: ghostwhite
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #b529d1
#> One vector of levels, one vector of colors, either the same length (case 9: and 10:), or colors longer (case 12:, unused colors were dropped),
#> reduced to 6: A single vector was provided, whose names don't cover the levels in the data,
#> missing levels were assigned random colors.
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: redstandard LCZ types detected, the standard colors will be associated to them: blackstandard LCZ types detected, the standard colors will be associated to them: greenstandard LCZ types detected, the standard colors will be associated to them: greystandard LCZ types detected, the standard colors will be associated to them: burlywoodstandard LCZ types detected, the standard colors will be associated to them: bluestandard LCZ types detected, the standard colors will be associated to them: ghostwhiteThere are many cases when one doesn’t necessarily know the levels of the qualitative variables, or the colors one wants to choose. One may also want to pair the levels and colors in a way that shows their correspondence.
The package allows quite some flexibility to the user, thanks to the
levCol function. This function is designed to be called by
showLCZ and compareLCZ functions, not by the
user, but one can use it to see how the levels and colors are dealt
with. It outputs a vector of levels and associated colors, as well as a
message, explaining the case it dealt with.
Here are some examples.
When levels don’t have a particular meaning, using random colors may be enough. One can specify a single vector of levels and no vector of colors.
levCol(sf=redonOSMgrouped,column="grouped",
levels=c("urban","industry","vegetation","impervious","pervious","water"))
redonGroupedCompare<-compareLCZ(sf1 = redonOSMgrouped, column1 = "grouped",
sf2 = redonBDTgrouped, column2 = "grouped",
repr = "alter",
levels = c("urban", "industry", "vegetation", "impervious", "pervious", "water")
)
#> The column grouped of the dataset sf1 is the reference against which the grouped column of the dataset sf2 will be compared.
#> Workflow names are used in produced graphics and as column names, long names are not suitable,
#> the first 3 and last 3 letters were kept instead
#> Workflow names are used in produced graphics and as column names, long names are not suitable,
#> the first 3 and last 3 letters were kept instead
#> Both sf datasets need to live in the same crs projection (srid / epsg),
#> they will be coerced to the specified reference (sf1)
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> typeLevels before trying to group are #7825edtypeLevels before trying to group are #f9dbb1typeLevels before trying to group are #fcfcabtypeLevels before trying to group are #e595c0typeLevels before trying to group are #b7b3f9typeLevels before trying to group are #b317c4typeLevels before trying to group are #f968c2
#> 8: No color vector but a level vector whose names don't cover the levels in the data.
#> Missing levels will be deduced from the data and colors will be chosen from a standard palette.
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: #7825edstandard LCZ types detected, the standard colors will be associated to them: #f9dbb1standard LCZ types detected, the standard colors will be associated to them: #fcfcabstandard LCZ types detected, the standard colors will be associated to them: #e595c0standard LCZ types detected, the standard colors will be associated to them: #b7b3f9standard LCZ types detected, the standard colors will be associated to them: #b317c4standard LCZ types detected, the standard colors will be associated to them: ghostwhite
#> typeLevels before trying to group are #3fcc54typeLevels before trying to group are #ecb1eftypeLevels before trying to group are #42d9fftypeLevels before trying to group are #f46bc7typeLevels before trying to group are #fc6771typeLevels before trying to group are #aad0eftypeLevels before trying to group are #0eefa0
#> 8: No color vector but a level vector whose names don't cover the levels in the data.
#> Missing levels will be deduced from the data and colors will be chosen from a standard palette.
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: #3fcc54standard LCZ types detected, the standard colors will be associated to them: #ecb1efstandard LCZ types detected, the standard colors will be associated to them: #42d9ffstandard LCZ types detected, the standard colors will be associated to them: #f46bc7standard LCZ types detected, the standard colors will be associated to them: #fc6771standard LCZ types detected, the standard colors will be associated to them: #aad0efstandard LCZ types detected, the standard colors will be associated to them: ghostwhiteIf one knows the number of levels of a qualitative variable but not
their names, in an exploratory approach, one can simply specify a vector
of preferred colors. In this example, we use the
importQualVar function to explore a classification other
than LCZ, namely the urban territory by random forest (UTRF)
classification produced by the GeoClimate workflow.
utrfRedonBDT <- importQualVar(dirPath = paste0(
system.file("extdata", package = "lczexplore"), "/utrfFiles"),
file = "bdt_utrf_area.fgb", column = "TYPO_MAJ")
#> Reading layer `rsu_utrf_area' from data source
#> `/tmp/RtmppWIPZu/Rinst132c522a1db42/lczexplore/extdata/utrfFiles/bdt_utrf_area.fgb'
#> using driver `FlatGeobuf'
#> Simple feature collection with 433 features and 3 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 316346.1 ymin: 6738046 xmax: 321758.2 ymax: 6743264
#> Projected CRS: RGF93 v1 / Lambert-93
summary(utrfRedonBDT)
#> ID_RSU TYPO_MAJ UNIQUENESS_VALUE geometry
#> Min. : 32 pd :174 Min. :6.497e-05 POLYGON :433
#> 1st Qu.: 768 ba : 70 1st Qu.:3.859e-01 epsg:2154 : 0
#> Median :1066 local : 44 Median :7.852e-01 +proj=lcc ...: 0
#> Mean :1115 icio : 34 Mean :6.789e-01
#> 3rd Qu.:1514 pcio : 26 3rd Qu.:1.000e+00
#> Max. :2126 psc : 25 Max. :1.000e+00
#> (Other): 60
summary(utrfRedonBDT$TYPO_MAJ)
#> icio pd id psc pcio local pcif ba icif
#> 34 174 24 25 26 44 14 70 22
map3 <- showLCZ(sf = utrfRedonBDT, column = "TYPO_MAJ", repr = "alter",
title = " UTRF classification of the French city of Redon",
colors = c("red", "black", "green", "grey", "burlywood", "blue", "orange", "lightgreen", "brown"))
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are orangetypeLevels before trying to group are lightgreentypeLevels before trying to group are browntypeLevels before trying to group are #f2f091
#> 3: No levels but a color vector which size does not cover the number of levels in the data, missing colors will be picked from a standard palette.One may specify a color wrong, or use a name which is known in a
certain environment but not known in R. The levCol function
will replace it with a color chosen from a standard palette.
Sometimes, the data can include unexpected levels, and the user might not specify them within the level vectors passed to the functions. In those cases, a message is produced to alert the user.
For instance, if the user forgets to specify the level “water” of the
redonOSMgrouped dataset. The levels are then deduced from
the data and a random color is added.
levCol(sf = redonOSMgrouped, column = "grouped",
levels = c("urban", "industry", "vegetation", "impervious", "pervious"),
colors = c("red", "black", "green", "grey", "burlywood")
)Sometimes, the vector of levels covers the levels of the data, but the vector of colors doesn’t. A random color is then assigned to the last level of vector.
levCol(sf = redonOSMgrouped, column = "grouped",
levels = c("urban", "industry", "vegetation", "impervious", "pervious", "water"),
colors = c("red", "black", "green", "grey", "burlywood")
)levCol(sf = redonOSMgrouped, column = "grouped",
levels = c("urban", "industry", "vegetation", "impervious", "pervious"),
colors = c("red", "black", "green", "grey", "burlywood", "blue")
)All the cases are not listed in this vignette as the messages are hopefully explicit enough.
Sometimes, one wants to explore how different grouping of levels from
the same original pair of datasets compare. In this case, one can do the
grouping and the plotting or comparing in one step. One needs to pass
the original column names, the grouping vectors and set the
argumenttryGroup=TRUE. If the values of the grouping
vectors cover the original values of the datasets, the function will
perform grouping before comparing.
map4 <- showLCZ(sf = redonBDT, column = "LCZ_PRIMARY", repr = "alter",
urban = c("1", "2", "3", "4", "5", "6", "7", "8", "9"),
industry = "10",
vegetation = c("101", "102", "103", "104"),
impervious = "105", pervious = "106", water = "107",
colors = c("red", "black", "green", "grey", "burlywood", "blue"), tryGroup = TRUE)
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #416ea0typeLevels before trying to group are #33cc63typeLevels before trying to group are #95d660typeLevels before trying to group are #ef39cetypeLevels before trying to group are #d69239typeLevels before trying to group are #bcf2f4typeLevels before trying to group are #a17bd1typeLevels before trying to group are #cadb0ftypeLevels before trying to group are #32c132typeLevels before trying to group are #8eed9ftypeLevels before trying to group are #915ccetypeLevels before trying to group are #204dbftypeLevels before trying to group are #17abc1typeLevels before trying to group are #dfed1etypeLevels before trying to group are #dd87c5typeLevels before trying to group are #0019d8typeLevels before trying to group are #ba830dtypeLevels before trying to group are #5100c4
#> Level names in your 1st dataset didn't match original data.
#> As tryGroup=TRUE, the function groupLCZ will try to create a "grouped" column with level names and levels specified in (...).
#> If this doesn't work, compareLCZ function may fail.
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
#> Warning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
#> Case 14: with at least a color or 15:, or 17: or 18:, then reduced to Case one vector of levels, one of colors, the vector of colors being shorter, some colors were picked, case 11:, reduced to 4: & 5: A single vector was provided, whose names cover the levels in the data (values are expected to be colors). your may want to check your vector of colors
compareLCZ(sf1 = redonBDT, column1 = "LCZ_PRIMARY",
sf2 = redonOSM, column2 = "LCZ_PRIMARY",
repr = "alter", ref = 2, saveG = "", exwrite = FALSE, location = "Redon", plot = TRUE,
urban = c("1", "2", "3", "4", "5", "6", "7", "8", "9"),
industry = "10",
vegetation = c("101", "102", "103", "104"),
impervious = "105", pervious = "106", water = "107",
colors = c("red", "black", "green", "grey", "burlywood", "blue"), tryGroup = TRUE)
#> The column LCZ_PRIMARY of the dataset sf1 is the reference against which the LCZ_PRIMARY column of the dataset sf2 will be compared.
#> Both sf datasets need to live in the same crs projection (srid / epsg),
#> they will be coerced to the specified reference (sf2)
#> Level names in your 1st dataset didn't match original data.
#> As tryGroup=TRUE, the function groupLCZ will try to create a "grouped" column with level names and levels specified in (...).
#> If this doesn't work, compareLCZ function may fail.
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
#> Warning: Unknown levels in `f`: 1, 4, 5, 7, 10, 103, 106
#> As tryGroup=TRUE, the function groupLCZ will try to create a "grouped" column with level names and levels specified in (...).
#> If this doesn't work, compareLCZ function may fail.
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 3, 4, 7, 10, 103, 106
#> Warning: Unknown levels in `f`: 1, 3, 4, 7, 10, 103, 106
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #2e09ea
#> Level names in your 1st dataset didn't match original data.
#> As tryGroup=TRUE, the function groupLCZ will try to create a "grouped" column with level names and levels specified in (...).
#> If this doesn't work, compareLCZ function may fail.
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103, 104, 105, 106, 107
#> Warning: Unknown levels in `f`: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103,
#> 104, 105, 106, 107
#> Case 14: with at least a color or 15:, or 17: or 18:, then reduced to Case one vector of levels, one of colors, the vector of colors being shorter, some colors were picked, case 11:, reduced to 4: & 5: A single vector was provided, whose names cover the levels in the data (values are expected to be colors). your may want to check your vector of colors
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: redstandard LCZ types detected, the standard colors will be associated to them: blackstandard LCZ types detected, the standard colors will be associated to them: greenstandard LCZ types detected, the standard colors will be associated to them: greystandard LCZ types detected, the standard colors will be associated to them: burlywoodstandard LCZ types detected, the standard colors will be associated to them: blue
#> typeLevels before trying to group are redtypeLevels before trying to group are blacktypeLevels before trying to group are greentypeLevels before trying to group are greytypeLevels before trying to group are burlywoodtypeLevels before trying to group are bluetypeLevels before trying to group are #840317
#> Level names in your 1st dataset didn't match original data.
#> As tryGroup=TRUE, the function groupLCZ will try to create a "grouped" column with level names and levels specified in (...).
#> If this doesn't work, compareLCZ function may fail.
#> Grouping
#> One of the specified levels to group doesn't exist in the data, if it is a mispelled level of the data,
#> this level will be kept as ungroupedsimpleWarning: Unknown levels in `f`: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103, 104, 105, 106, 107
#> Warning: Unknown levels in `f`: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103,
#> 104, 105, 106, 107
#> Case 14: with at least a color or 15:, or 17: or 18:, then reduced to Case one vector of levels, one of colors, the vector of colors being shorter, some colors were picked, case 11:, reduced to 4: & 5: A single vector was provided, whose names cover the levels in the data (values are expected to be colors). your may want to check your vector of colors
#> As useStandCol is set to TRUE, some of the specified colors may have been over-ridden to use standard colors if standard LCZ values have been detected
#> standard LCZ types detected, the standard colors will be associated to them: redstandard LCZ types detected, the standard colors will be associated to them: blackstandard LCZ types detected, the standard colors will be associated to them: greenstandard LCZ types detected, the standard colors will be associated to them: greystandard LCZ types detected, the standard colors will be associated to them: burlywoodstandard LCZ types detected, the standard colors will be associated to them: blue
This is meant as an exploratory tool, as the resulting grouped columns
are not actually kept after the analysis.
Please feel free to contact us if some cases are not handled by the package.