Precompiling GeoDataFrames...
451.6 ms โ IteratorInterfaceExtensions
561.9 ms โ LaTeXStrings
526.2 ms โ GeoFormatTypes
566.3 ms โ CEnum
606.6 ms โ TensorCore
609.7 ms โ Requires
736.7 ms โ Statistics
731.9 ms โ Observables
782.7 ms โ OrderedCollections
436.0 ms โ DataValueInterfaces
472.8 ms โ Reexport
776.8 ms โ IntervalSets
903.1 ms โ InlineStrings
546.8 ms โ InvertedIndices
1863.4 ms โ OffsetArrays
703.8 ms โ Extents
445.5 ms โ DataAPI
522.8 ms โ StaticArraysCore
524.8 ms โ MappedArrays
915.5 ms โ LRUCache
884.7 ms โ MPIPreferences
945.5 ms โ OpenSSL_jll
1074.1 ms โ Qhull_jll
950.2 ms โ Bzip2_jll
2374.1 ms โ SentinelArrays
1982.7 ms โ boost_jll
1203.8 ms โ Lz4_jll
1127.7 ms โ ICU_jll
937.6 ms โ libaec_jll
889.9 ms โ Xorg_libXau_jll
880.2 ms โ libpng_jll
849.6 ms โ Hwloc_jll
842.7 ms โ Giflib_jll
869.8 ms โ LERC_jll
864.0 ms โ SQLite_jll
912.3 ms โ EarCut_jll
868.8 ms โ JpegTurbo_jll
835.9 ms โ XZ_jll
862.6 ms โ snappy_jll
709.2 ms โ Xorg_libXdmcp_jll
911.1 ms โ brotli_jll
952.3 ms โ Zstd_jll
831.5 ms โ Expat_jll
737.8 ms โ MicrosoftMPI_jll
823.2 ms โ Xorg_xtrans_jll
894.2 ms โ GEOS_jll
824.3 ms โ Kerberos_krb5_jll
1074.5 ms โ Libgpg_error_jll
807.5 ms โ Xorg_libpthread_stubs_jll
449.2 ms โ TableTraits
1103.4 ms โ XML2_jll
2469.1 ms โ RecipesBase
1021.9 ms โ IntervalSets โ IntervalSetsRandomExt
488.6 ms โ IntervalSets โ IntervalSetsStatisticsExt
875.0 ms โ StackViews
852.6 ms โ PaddedViews
2865.4 ms โ DataStructures
3584.6 ms โ StringManipulation
1023.0 ms โ PooledArrays
915.7 ms โ Missings
4598.0 ms โ FixedPointNumbers
1659.1 ms โ GeoInterface
1138.8 ms โ Thrift_jll
1928.5 ms โ DiskArrays
1568.0 ms โ MPItrampoline_jll
1541.1 ms โ OpenMPI_jll
1008.7 ms โ Blosc_jll
1276.1 ms โ HDF4_jll
964.5 ms โ libzip_jll
888.4 ms โ Libtiff_jll
1976.8 ms โ MPICH_jll
855.3 ms โ Libgcrypt_jll
1226.0 ms โ LibPQ_jll
744.3 ms โ IntervalSets โ IntervalSetsRecipesBaseExt
651.4 ms โ MosaicViews
1179.7 ms โ Tables
809.5 ms โ SortingAlgorithms
990.0 ms โ GeoInterfaceRecipes
1221.9 ms โ Arrow_jll
1280.1 ms โ PROJ_jll
1132.0 ms โ LittleCMS_jll
875.4 ms โ XSLT_jll
1253.1 ms โ libgeotiff_jll
4107.9 ms โ ColorTypes
2876.7 ms โ HDF5_jll
1233.5 ms โ OpenJpeg_jll
2363.0 ms โ Xorg_libxcb_jll
12653.4 ms โ StaticArrays
2092.3 ms โ NetCDF_jll
1132.1 ms โ Xorg_libX11_jll
4226.6 ms โ ColorVectorSpace
1099.7 ms โ StaticArrays โ StaticArraysStatisticsExt
964.5 ms โ Xorg_libXext_jll
923.6 ms โ Libglvnd_jll
1289.1 ms โ libwebp_jll
7888.5 ms โ Colors
2759.9 ms โ GDAL_jll
4967.9 ms โ GDAL
17594.7 ms โ GeometryBasics
6684.2 ms โ MakieCore
31966.4 ms โ PrettyTables
1856.4 ms โ GeoInterfaceMakie
26724.3 ms โ ImageCore
11180.8 ms โ ArchGDAL
42008.7 ms โ DataFrames
2573.5 ms โ GeoDataFrames
106 dependencies successfully precompiled in 96 seconds. 37 already precompiled.
177ร11 DataFrame
152 rows omitted
Row
geom
iso_a2
name_long
continent
region_un
subregion
type
area_km2
pop
lifeExp
gdpPercap
IGeometrโฆ
String?
String
String
String
String
String
Float64
Float64?
Float64?
Float64?
1
Geometry: wkbMultiPolygon
FJ
Fiji
Oceania
Oceania
Melanesia
Sovereign country
19290.0
885806.0
69.96
8222.25
2
Geometry: wkbMultiPolygon
TZ
Tanzania
Africa
Africa
Eastern Africa
Sovereign country
9.32746e5
5.22349e7
64.163
2402.1
3
Geometry: wkbMultiPolygon
EH
Western Sahara
Africa
Africa
Northern Africa
Indeterminate
96270.6
missing
missing
missing
4
Geometry: wkbMultiPolygon
CA
Canada
North America
Americas
Northern America
Sovereign country
1.0036e7
3.55353e7
81.953
43079.1
5
Geometry: wkbMultiPolygon
US
United States
North America
Americas
Northern America
Country
9.51074e6
3.18623e8
78.8415
51922.0
6
Geometry: wkbMultiPolygon
KZ
Kazakhstan
Asia
Asia
Central Asia
Sovereign country
2.72981e6
1.72883e7
71.62
23587.3
7
Geometry: wkbMultiPolygon
UZ
Uzbekistan
Asia
Asia
Central Asia
Sovereign country
4.6141e5
3.07577e7
71.039
5370.87
8
Geometry: wkbMultiPolygon
PG
Papua New Guinea
Oceania
Oceania
Melanesia
Sovereign country
4.6452e5
7.75578e6
65.23
3709.08
9
Geometry: wkbMultiPolygon
ID
Indonesia
Asia
Asia
South-Eastern Asia
Sovereign country
1.81925e6
2.55131e8
68.856
10003.1
10
Geometry: wkbMultiPolygon
AR
Argentina
South America
Americas
South America
Sovereign country
2.78447e6
4.29815e7
76.252
18797.5
11
Geometry: wkbMultiPolygon
CL
Chile
South America
Americas
South America
Sovereign country
8.14844e5
1.76138e7
79.117
22195.3
12
Geometry: wkbMultiPolygon
CD
Democratic Republic of the Congo
Africa
Africa
Middle Africa
Sovereign country
2.32349e6
7.37229e7
58.782
785.347
13
Geometry: wkbMultiPolygon
SO
Somalia
Africa
Africa
Eastern Africa
Sovereign country
4.84333e5
1.35131e7
55.467
missing
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
โฎ
166
Geometry: wkbMultiPolygon
ET
Ethiopia
Africa
Africa
Eastern Africa
Sovereign country
1.13239e6
9.73668e7
64.535
1424.53
167
Geometry: wkbMultiPolygon
DJ
Djibouti
Africa
Africa
Eastern Africa
Sovereign country
21880.3
912164.0
62.006
missing
168
Geometry: wkbMultiPolygon
missing
Somaliland
Africa
Africa
Eastern Africa
Indeterminate
1.6735e5
missing
missing
missing
169
Geometry: wkbMultiPolygon
UG
Uganda
Africa
Africa
Eastern Africa
Sovereign country
2.45768e5
3.88333e7
59.224
1637.28
170
Geometry: wkbMultiPolygon
RW
Rwanda
Africa
Africa
Eastern Africa
Sovereign country
23365.4
1.13454e7
66.188
1629.87
171
Geometry: wkbMultiPolygon
BA
Bosnia and Herzegovina
Europe
Europe
Southern Europe
Sovereign country
50605.1
3.566e6
76.561
10516.8
172
Geometry: wkbMultiPolygon
MK
Macedonia
Europe
Europe
Southern Europe
Sovereign country
25062.3
2.0775e6
75.384
12298.5
173
Geometry: wkbMultiPolygon
RS
Serbia
Europe
Europe
Southern Europe
Sovereign country
76388.6
7.13058e6
75.3366
13112.9
174
Geometry: wkbMultiPolygon
ME
Montenegro
Europe
Europe
Southern Europe
Sovereign country
13443.7
621810.0
76.712
14796.6
175
Geometry: wkbMultiPolygon
XK
Kosovo
Europe
Europe
Southern Europe
Sovereign country
11230.3
1.8218e6
71.0976
8698.29
176
Geometry: wkbMultiPolygon
TT
Trinidad and Tobago
North America
Americas
Caribbean
Sovereign country
7737.81
1.35449e6
70.426
31181.8
177
Geometry: wkbMultiPolygon
SS
South Sudan
Africa
Africa
Eastern Africa
Sovereign country
6.24909e5
1.1531e7
55.817
1935.88
usingCairoMakieusingGeoMakief, a, p =poly(df.geom)
Precompiling CairoMakie...
464.1 ms โ RangeArrays
476.9 ms โ IndirectArrays
508.0 ms โ StatsAPI
663.9 ms โ PolygonOps
786.2 ms โ AbstractFFTs
626.1 ms โ Contour
676.2 ms โ TriplotBase
558.6 ms โ InverseFunctions
704.5 ms โ EnumX
1591.9 ms โ Format
1721.9 ms โ FillArrays
1412.2 ms โ Grisu
619.1 ms โ StableRNGs
1001.9 ms โ AbstractTrees
506.5 ms โ PtrArrays
612.9 ms โ RoundingEmulator
833.1 ms โ NaNMath
923.3 ms โ TranscodingStreams
2139.8 ms โ IrrationalConstants
591.9 ms โ Ratios
716.4 ms โ LazyModules
3939.4 ms โ MacroTools
677.4 ms โ Inflate
643.4 ms โ Adapt
797.2 ms โ ConstructionBase
924.2 ms โ Statistics โ SparseArraysExt
2761.8 ms โ AdaptivePredicates
882.8 ms โ SuiteSparse
999.1 ms โ WoodburyMatrices
1161.9 ms โ ProgressMeter
881.6 ms โ DocStringExtensions
891.1 ms โ Animations
660.0 ms โ SignedDistanceFields
883.6 ms โ Graphite2_jll
745.8 ms โ Libmount_jll
2126.3 ms โ ChainRulesCore
2180.0 ms โ UnicodeFun
968.4 ms โ LLVMOpenMP_jll
946.3 ms โ Rmath_jll
874.5 ms โ libfdk_aac_jll
756.3 ms โ Imath_jll
858.4 ms โ LAME_jll
842.7 ms โ CRlibm_jll
877.1 ms โ Ogg_jll
925.2 ms โ oneTBB_jll
827.3 ms โ x265_jll
872.0 ms โ x264_jll
884.7 ms โ LZO_jll
803.9 ms โ Opus_jll
1034.9 ms โ libaom_jll
733.2 ms โ Libffi_jll
794.6 ms โ FFTW_jll
809.7 ms โ OpenSpecFun_jll
953.5 ms โ isoband_jll
810.4 ms โ Libuuid_jll
764.4 ms โ FriBidi_jll
903.9 ms โ OpenBLASConsistentFPCSR_jll
1026.1 ms โ libsixel_jll
1634.9 ms โ PkgVersion
1849.8 ms โ FilePathsBase
967.1 ms โ FreeType2_jll
2538.3 ms โ JSON
5856.5 ms โ ColorSchemes
1967.6 ms โ QuadGK
7876.0 ms โ FileIO
4214.5 ms โ ImageBase
2086.9 ms โ IntelOpenMP_jll
1930.4 ms โ Packing
2835.9 ms โ ShaderAbstractions
1375.0 ms โ Gettext_jll
1106.0 ms โ Xorg_libXrender_jll
1549.7 ms โ AxisArrays
15892.3 ms โ SIMD
866.0 ms โ InverseFunctions โ InverseFunctionsTestExt
2124.7 ms โ AbstractFFTs โ AbstractFFTsTestExt
609.0 ms โ InverseFunctions โ InverseFunctionsDatesExt
774.9 ms โ FillArrays โ FillArraysStatisticsExt
915.1 ms โ FillArrays โ FillArraysSparseArraysExt
738.4 ms โ Showoff
926.3 ms โ AliasTables
952.6 ms โ Graphics
1020.2 ms โ Ratios โ RatiosFixedPointNumbersExt
1841.9 ms โ SimpleTraits
1341.1 ms โ Adapt โ AdaptStaticArraysExt
8099.8 ms โ PNGFiles
883.8 ms โ OffsetArrays โ OffsetArraysAdaptExt
1066.0 ms โ Adapt โ AdaptSparseArraysExt
682.8 ms โ ConstructionBase โ ConstructionBaseLinearAlgebraExt
736.2 ms โ ConstructionBase โ ConstructionBaseIntervalSetsExt
1252.8 ms โ ConstructionBase โ ConstructionBaseStaticArraysExt
14025.5 ms โ GridLayoutBase
1296.0 ms โ PDMats
1411.1 ms โ AxisAlgorithms
1398.5 ms โ LogExpFunctions
755.9 ms โ AbstractFFTs โ AbstractFFTsChainRulesCoreExt
1170.6 ms โ StaticArrays โ StaticArraysChainRulesCoreExt
1316.1 ms โ ChainRulesCore โ ChainRulesCoreSparseArraysExt
976.7 ms โ Pixman_jll
1113.3 ms โ libvorbis_jll
1495.7 ms โ Rmath
712.0 ms โ Isoband
1376.9 ms โ OpenEXR_jll
977.1 ms โ FilePathsBase โ FilePathsBaseMmapExt
1547.1 ms โ FilePaths
2396.7 ms โ FilePathsBase โ FilePathsBaseTestExt
1419.3 ms โ Fontconfig_jll
2189.7 ms โ FreeType
1280.8 ms โ ColorBrewer
6682.4 ms โ IntervalArithmetic
41765.3 ms โ Unitful
5170.1 ms โ Sixel
2584.1 ms โ QOI
6272.1 ms โ JpegTurbo
1325.2 ms โ Glib_jll
3551.4 ms โ WebP
2913.1 ms โ ImageAxes
6603.2 ms โ MKL_jll
1285.2 ms โ StructArrays
1091.6 ms โ FillArrays โ FillArraysPDMatsExt
743.6 ms โ LogExpFunctions โ LogExpFunctionsInverseFunctionsExt
2580.6 ms โ LogExpFunctions โ LogExpFunctionsChainRulesCoreExt
5302.4 ms โ SpecialFunctions
4535.9 ms โ StatsBase
22634.3 ms โ PlotUtils
2777.2 ms โ OpenEXR
4371.9 ms โ Interpolations
1214.1 ms โ IntervalArithmetic โ IntervalArithmeticIntervalSetsExt
1239.9 ms โ Unitful โ ConstructionBaseUnitfulExt
1078.0 ms โ Unitful โ InverseFunctionsUnitfulExt
4676.4 ms โ FreeTypeAbstraction
1656.1 ms โ Cairo_jll
2437.3 ms โ ImageMetadata
781.7 ms โ StructArrays โ StructArraysAdaptExt
24891.8 ms โ Automa
1397.0 ms โ StructArrays โ StructArraysSparseArraysExt
1338.6 ms โ StructArrays โ StructArraysStaticArraysExt
986.3 ms โ StructArrays โ StructArraysLinearAlgebraExt
9693.1 ms โ ExactPredicates
1025.9 ms โ ColorVectorSpace โ SpecialFunctionsExt
1818.1 ms โ HypergeometricFunctions
3060.8 ms โ SpecialFunctions โ SpecialFunctionsChainRulesCoreExt
979.3 ms โ HarfBuzz_jll
1739.3 ms โ Interpolations โ InterpolationsUnitfulExt
3316.5 ms โ Netpbm
3463.7 ms โ StatsFuns
1385.9 ms โ libass_jll
1314.4 ms โ Pango_jll
1063.6 ms โ StatsFuns โ StatsFunsInverseFunctionsExt
10255.5 ms โ DelaunayTriangulation
12737.1 ms โ MathTeXEngine
2791.4 ms โ StatsFuns โ StatsFunsChainRulesCoreExt
20894.2 ms โ FFTW
1389.7 ms โ FFMPEG_jll
1906.7 ms โ Cairo
6602.4 ms โ Distributions
1351.1 ms โ Distributions โ DistributionsChainRulesCoreExt
1409.1 ms โ Distributions โ DistributionsTestExt
1322.5 ms โ KernelDensity
82983.4 ms โ TiffImages
963.7 ms โ ImageIO
130031.5 ms โ Makie
40801.5 ms โ CairoMakie
162 dependencies successfully precompiled in 305 seconds. 110 already precompiled.
1 dependency had output during precompilation:
โ MKL_jll
โ Downloading artifact: IntelOpenMP
โ
Precompiling ParsersExt...
413.1 ms โ InlineStrings โ ParsersExt
1 dependency successfully precompiled in 0 seconds. 9 already precompiled.
Precompiling SerializationExt...
335.3 ms โ LRUCache โ SerializationExt
1 dependency successfully precompiled in 0 seconds. 2 already precompiled.
Precompiling IntervalArithmeticRecipesBaseExt...
662.7 ms โ IntervalArithmetic โ IntervalArithmeticRecipesBaseExt
1 dependency successfully precompiled in 1 seconds. 33 already precompiled.
Precompiling ArchGDALMakieExt...
2101.3 ms โ ArchGDAL โ ArchGDALMakieExt
1 dependency successfully precompiled in 3 seconds. 306 already precompiled.
Precompiling GeoMakie...
528.5 ms โ SortTileRecursiveTree
939.5 ms โ GeometryOpsCore
991.9 ms โ CoordinateTransformations
2357.9 ms โ Geodesy
2585.6 ms โ Proj
4088.6 ms โ GeometryOps
1186.5 ms โ GeometryOps โ GeometryOpsProjExt
24586.5 ms โ GeoJSON
1074.2 ms โ NaturalEarth
1321.4 ms โ GeoJSON โ GeoJSONMakieExt
8679.3 ms โ GeoMakie
11 dependencies successfully precompiled in 35 seconds. 276 already precompiled.
1.1.1 Raster from scratch
In this section, we are going to demonstrate the creation of rasters from scratch. We will construct two small rasters, elev and grain, which we will use in examples later in the book. Unlike creating a vector layer (see ?sec-vector-layer-from-scratch), creating a raster from scratch is rarely needed in practice because aligning a raster with the proper spatial extent is challenging to do programmatically (โgeoreferencingโ tools in GIS software are a better fit for the job). Nevertheless, the examples will be helpful to become more familiar with the Rasters.jl data structures.
usingRastersimportGeoFormatTypes as GFT
Precompiling Rasters...
668.8 ms โ Interfaces
673.1 ms โ FieldMetadata
830.2 ms โ ArrayInterface
1153.4 ms โ CFTime
803.5 ms โ Flatten
638.4 ms โ ArrayInterface โ ArrayInterfaceStaticArraysCoreExt
1562.1 ms โ Setfield
848.8 ms โ ArrayInterface โ ArrayInterfaceSparseArraysExt
1397.5 ms โ CommonDataModel
14260.9 ms โ DimensionalData
754.7 ms โ DimensionalData โ DimensionalDataDiskArraysExt
5360.0 ms โ Rasters
12 dependencies successfully precompiled in 22 seconds. 58 already precompiled.
Precompiling ArrayInterfaceChainRulesCoreExt...
364.4 ms โ ArrayInterface โ ArrayInterfaceChainRulesCoreExt
1 dependency successfully precompiled in 0 seconds. 11 already precompiled.
Precompiling DimensionalDataMakie...
806.6 ms โ DimensionalData โ DimensionalDataStatsBase
6423.3 ms โ DimensionalData โ DimensionalDataMakie
2 dependencies successfully precompiled in 7 seconds. 277 already precompiled.
Precompiling RastersMakieExt...
1292.0 ms โ Rasters โ RastersStatsBaseExt
6214.7 ms โ Rasters โ RastersMakieExt
2 dependencies successfully precompiled in 7 seconds. 291 already precompiled.
Precompiling RastersProjExt...
1225.8 ms โ Rasters โ RastersCoordinateTransformationsExt
1340.7 ms โ Rasters โ RastersProjExt
2 dependencies successfully precompiled in 1 seconds. 92 already precompiled.
Precompiling RastersArchGDALExt...
2226.8 ms โ Rasters โ RastersArchGDALExt
1 dependency successfully precompiled in 2 seconds. 165 already precompiled.
Conceptually, a raster is an array combined with georeferencing information, whereas the latter comprises:
Lookup vectors for the axes, encoding the spatial coordinates for each grid cell. These take the form of the X and Y dimensions in the raster that youโll see below.
A coordinate reference system (CRS) definition, specifying the association of the rasterโs coordinates with the surface of the earth.
Therefore, to create a raster, we first need to have an array with the values, and then supplement it with the georeferencing information. Letโs create the arrays elev and grain. The elev array is a \(6 \times 6\) array with sequential values from 1 to 36. It can be created as follows using base Julia functions.
The grain array represents a categorical raster with values 0, 1, 2, corresponding to categories โclayโ, โsiltโ, โsandโ, respectively. We will create it from a specific arrangement of pixel values, using reshape.
Note that in both cases, we are using the uint8 (unsigned integer in 8 bits, i.e., 0-255) data type, which is sufficient to represent all possible values of the given rasters (see ?tbl-numpy-data-types). This is the recommended approach for a minimal memory footprint.
What is missing now is the georeferencing information (see ?sec-using-rasters-jl). In this case, since the rasters are arbitrary, we also set up arbitrary dimension lookups for the x and y axes, where:
The origin (\(x_{min}\), \(y_{max}\)) is at -1.5,1.5
The raster resolution (\(delta_{x}\), \(delta_{y}\)) is 0.5,-0.5
We can add this information using rasterio.transform.from_origin, and specifying west, north, xsize, and ysize parameters. The resulting transformation matrix object is hereby named new_transform.
We can now construct a Raster object, from the elev array and the dimensions new_x and new_y.
We assign to it a CRS of EPSG:4326 (which encodes that the coordinate system is longitude/latitude on the โstandardโ WGS84 definition of the Earthโs curvature).
Here, we use the GFT.EPSG(code) constructor to create an object that encodes a reference code under the European Petroleum Survey Group (EPSG) authorityโs database of coordinate reference systems.
The raster can now be plotted in its coordinate system, passing the array elev along with the transformation matrix new_transform to rasterio.plot.show (Figure 1.1).
plot(elev_raster)
Figure 1.1: Plot of the elev raster, a minimal example of a continuous raster, created from scratch
The grain raster can be plotted the same way, as we are going to use the same transformation matrix for it as well (Figure 1.2).
Figure 1.2: Plot of the grain raster, a minimal example of a categorical raster, created from scratch
At this point, we have two rasters, each composed of an array and related dimension lookups. We can work with the raster using Rasters.jl by:
Keeping in mind that any other layer we use in the analysis is in the same CRS
Finally, to export the raster for permanent storage, along with the spatial metadata, we need to go through the following steps:
Create a raster file (where we set the lookups and the CRS, among other settings)
Write the array with raster values into the connection
Close the connection
Donโt worry if the code below is unclear; the concepts related to writing raster data to file will be explained in ?sec-data-output-raster. For now, for completeness, and also to use these rasters in subsequent chapters without having to re-create them from scratch, we just provide the code for exporting the elev and grain rasters into the output directory. In the case of elev, we do it as follows with the Rasters.write functions and methods of the Rasters.jl package.
write("output/elev.tif", elev_raster; force =true)
"output/elev.tif"
Note that the CRS we (arbitrarily) set for the elev raster is WGS84, defined using crs=4326 according to the EPSG code.
Exporting the grain raster is done in the same way, with the only differences being the file name and the array we write into the connection.
write("output/grain.tif", Raster(grain, (new_x, new_y); crs = GFT.EPSG(4326)); force =true)
"output/grain.tif"
As a result, the files elev.tif and grain.tif are written into the output directory. We are going to use these small raster files later on in the examples (for example, ?sec-raster-subsetting).
Note that the transform matrices and dimensions of elev and grain are identical. This means that the rasters are overlapping, and can be combined into one two-band raster, processed in raster algebra operations (?sec-map-algebra), etc.