Precompiling GeoDataFrames...
460.6 ms โ IteratorInterfaceExtensions
504.3 ms โ LaTeXStrings
468.8 ms โ CEnum
621.5 ms โ GeoFormatTypes
713.5 ms โ TensorCore
694.9 ms โ Statistics
596.2 ms โ Observables
1019.8 ms โ OrderedCollections
787.6 ms โ Requires
396.2 ms โ DataValueInterfaces
643.1 ms โ Reexport
1581.3 ms โ OffsetArrays
683.1 ms โ Extents
752.6 ms โ IntervalSets
702.1 ms โ InvertedIndices
1078.0 ms โ InlineStrings
506.8 ms โ DataAPI
723.4 ms โ LRUCache
619.4 ms โ StaticArraysCore
841.5 ms โ MappedArrays
828.4 ms โ MPIPreferences
851.7 ms โ OpenSSL_jll
1762.5 ms โ boost_jll
1091.7 ms โ Bzip2_jll
1287.5 ms โ Qhull_jll
1128.2 ms โ Lz4_jll
2390.7 ms โ SentinelArrays
833.7 ms โ Xorg_libXau_jll
929.5 ms โ ICU_jll
924.0 ms โ libaec_jll
787.8 ms โ Hwloc_jll
1066.1 ms โ libpng_jll
844.9 ms โ Giflib_jll
828.1 ms โ LERC_jll
869.4 ms โ SQLite_jll
875.5 ms โ EarCut_jll
949.6 ms โ JpegTurbo_jll
839.8 ms โ snappy_jll
999.3 ms โ XZ_jll
959.9 ms โ Xorg_libXdmcp_jll
919.5 ms โ brotli_jll
850.8 ms โ Zstd_jll
837.8 ms โ Expat_jll
863.2 ms โ MicrosoftMPI_jll
825.3 ms โ Xorg_xtrans_jll
783.0 ms โ Libgpg_error_jll
905.2 ms โ GEOS_jll
871.6 ms โ Kerberos_krb5_jll
774.1 ms โ Xorg_libpthread_stubs_jll
473.4 ms โ TableTraits
1270.1 ms โ XML2_jll
873.1 ms โ StackViews
2514.2 ms โ RecipesBase
851.9 ms โ PaddedViews
981.8 ms โ IntervalSets โ IntervalSetsRandomExt
566.1 ms โ IntervalSets โ IntervalSetsStatisticsExt
3851.7 ms โ StringManipulation
3211.9 ms โ DataStructures
917.1 ms โ PooledArrays
1005.3 ms โ Missings
4528.8 ms โ FixedPointNumbers
1922.6 ms โ GeoInterface
1891.8 ms โ DiskArrays
1016.5 ms โ Thrift_jll
1998.1 ms โ MPItrampoline_jll
1158.4 ms โ HDF4_jll
1895.8 ms โ OpenMPI_jll
1096.2 ms โ Blosc_jll
2015.0 ms โ MPICH_jll
1052.0 ms โ libzip_jll
1126.7 ms โ Libtiff_jll
763.2 ms โ Libgcrypt_jll
1074.1 ms โ LibPQ_jll
735.7 ms โ IntervalSets โ IntervalSetsRecipesBaseExt
738.2 ms โ MosaicViews
1271.3 ms โ Tables
987.7 ms โ SortingAlgorithms
880.4 ms โ GeoInterfaceRecipes
1020.6 ms โ Arrow_jll
1091.5 ms โ LittleCMS_jll
1563.6 ms โ PROJ_jll
1122.8 ms โ XSLT_jll
2836.8 ms โ HDF5_jll
4104.6 ms โ ColorTypes
1048.1 ms โ OpenJpeg_jll
1349.4 ms โ libgeotiff_jll
2542.9 ms โ Xorg_libxcb_jll
2521.4 ms โ NetCDF_jll
13033.4 ms โ StaticArrays
1091.6 ms โ Xorg_libX11_jll
1226.4 ms โ StaticArrays โ StaticArraysStatisticsExt
4197.0 ms โ ColorVectorSpace
788.1 ms โ Xorg_libXext_jll
959.3 ms โ Libglvnd_jll
1098.4 ms โ libwebp_jll
7416.5 ms โ Colors
2997.4 ms โ GDAL_jll
5162.3 ms โ GDAL
18889.2 ms โ GeometryBasics
6751.5 ms โ MakieCore
32358.0 ms โ PrettyTables
1823.1 ms โ GeoInterfaceMakie
27098.4 ms โ ImageCore
11467.1 ms โ ArchGDAL
43532.3 ms โ DataFrames
2693.0 ms โ GeoDataFrames
106 dependencies successfully precompiled in 99 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...
514.3 ms โ RangeArrays
598.8 ms โ PolygonOps
608.5 ms โ IndirectArrays
607.7 ms โ StatsAPI
728.7 ms โ AbstractFFTs
552.7 ms โ Contour
582.2 ms โ TriplotBase
776.5 ms โ InverseFunctions
594.3 ms โ EnumX
1530.4 ms โ FillArrays
1267.2 ms โ Grisu
2002.1 ms โ Format
719.7 ms โ StableRNGs
1100.5 ms โ AbstractTrees
855.3 ms โ RoundingEmulator
785.8 ms โ PtrArrays
913.8 ms โ TranscodingStreams
1890.4 ms โ IrrationalConstants
922.8 ms โ NaNMath
637.7 ms โ LazyModules
732.3 ms โ Ratios
764.2 ms โ Inflate
757.0 ms โ ConstructionBase
4568.8 ms โ MacroTools
733.9 ms โ Adapt
2656.5 ms โ AdaptivePredicates
1077.5 ms โ Statistics โ SparseArraysExt
912.7 ms โ SuiteSparse
909.1 ms โ WoodburyMatrices
1231.4 ms โ ProgressMeter
991.5 ms โ DocStringExtensions
1022.6 ms โ Animations
688.8 ms โ SignedDistanceFields
1092.1 ms โ Graphite2_jll
2013.6 ms โ ChainRulesCore
920.4 ms โ Libmount_jll
2303.5 ms โ UnicodeFun
1037.4 ms โ LLVMOpenMP_jll
951.5 ms โ Rmath_jll
862.2 ms โ libfdk_aac_jll
766.2 ms โ Imath_jll
892.7 ms โ CRlibm_jll
787.7 ms โ Ogg_jll
1084.5 ms โ LAME_jll
1092.9 ms โ oneTBB_jll
790.5 ms โ x264_jll
943.1 ms โ x265_jll
909.0 ms โ libaom_jll
871.9 ms โ LZO_jll
847.2 ms โ Opus_jll
943.0 ms โ Libffi_jll
1042.8 ms โ isoband_jll
803.6 ms โ FFTW_jll
748.9 ms โ Libuuid_jll
1194.5 ms โ OpenSpecFun_jll
811.6 ms โ libsixel_jll
864.1 ms โ FriBidi_jll
808.4 ms โ OpenBLASConsistentFPCSR_jll
1925.6 ms โ FilePathsBase
2056.7 ms โ PkgVersion
986.9 ms โ FreeType2_jll
2549.9 ms โ JSON
6571.9 ms โ ColorSchemes
1725.3 ms โ QuadGK
7784.5 ms โ FileIO
4376.8 ms โ ImageBase
2246.3 ms โ IntelOpenMP_jll
2038.0 ms โ Packing
2484.5 ms โ ShaderAbstractions
1172.5 ms โ Gettext_jll
1299.8 ms โ Xorg_libXrender_jll
1555.8 ms โ AxisArrays
16597.9 ms โ SIMD
775.5 ms โ InverseFunctions โ InverseFunctionsTestExt
2787.9 ms โ AbstractFFTs โ AbstractFFTsTestExt
748.7 ms โ InverseFunctions โ InverseFunctionsDatesExt
773.4 ms โ FillArrays โ FillArraysStatisticsExt
1287.3 ms โ FillArrays โ FillArraysSparseArraysExt
1059.1 ms โ Showoff
797.5 ms โ AliasTables
1088.0 ms โ Graphics
977.7 ms โ Ratios โ RatiosFixedPointNumbersExt
988.9 ms โ ConstructionBase โ ConstructionBaseIntervalSetsExt
1000.4 ms โ ConstructionBase โ ConstructionBaseLinearAlgebraExt
1683.5 ms โ ConstructionBase โ ConstructionBaseStaticArraysExt
1949.4 ms โ SimpleTraits
9808.8 ms โ PNGFiles
1211.4 ms โ Adapt โ AdaptStaticArraysExt
856.6 ms โ OffsetArrays โ OffsetArraysAdaptExt
15439.0 ms โ GridLayoutBase
1141.8 ms โ Adapt โ AdaptSparseArraysExt
1190.4 ms โ AxisAlgorithms
1391.7 ms โ PDMats
1205.2 ms โ LogExpFunctions
1180.7 ms โ ChainRulesCore โ ChainRulesCoreSparseArraysExt
972.4 ms โ AbstractFFTs โ AbstractFFTsChainRulesCoreExt
1308.0 ms โ StaticArrays โ StaticArraysChainRulesCoreExt
1285.6 ms โ Pixman_jll
1780.7 ms โ Rmath
1374.5 ms โ OpenEXR_jll
1053.8 ms โ Isoband
1523.4 ms โ libvorbis_jll
984.8 ms โ FilePathsBase โ FilePathsBaseMmapExt
1564.8 ms โ FilePaths
2544.0 ms โ FilePathsBase โ FilePathsBaseTestExt
2246.1 ms โ FreeType
1471.5 ms โ Fontconfig_jll
1573.6 ms โ ColorBrewer
41931.2 ms โ Unitful
6765.1 ms โ IntervalArithmetic
2533.6 ms โ QOI
4719.9 ms โ Sixel
5805.5 ms โ JpegTurbo
1195.4 ms โ Glib_jll
4137.8 ms โ WebP
1244.9 ms โ StructArrays
6408.7 ms โ MKL_jll
3488.4 ms โ ImageAxes
886.2 ms โ FillArrays โ FillArraysPDMatsExt
722.8 ms โ LogExpFunctions โ LogExpFunctionsInverseFunctionsExt
2326.0 ms โ LogExpFunctions โ LogExpFunctionsChainRulesCoreExt
5463.5 ms โ SpecialFunctions
4836.4 ms โ StatsBase
21684.5 ms โ PlotUtils
2264.3 ms โ OpenEXR
4098.9 ms โ Interpolations
1331.7 ms โ Unitful โ ConstructionBaseUnitfulExt
1232.2 ms โ Unitful โ InverseFunctionsUnitfulExt
1076.9 ms โ IntervalArithmetic โ IntervalArithmeticIntervalSetsExt
1596.1 ms โ Cairo_jll
4536.9 ms โ FreeTypeAbstraction
819.0 ms โ StructArrays โ StructArraysAdaptExt
1375.4 ms โ StructArrays โ StructArraysSparseArraysExt
1525.0 ms โ StructArrays โ StructArraysStaticArraysExt
935.1 ms โ StructArrays โ StructArraysLinearAlgebraExt
2348.5 ms โ ImageMetadata
10217.6 ms โ ExactPredicates
27835.8 ms โ Automa
3458.2 ms โ SpecialFunctions โ SpecialFunctionsChainRulesCoreExt
1183.7 ms โ ColorVectorSpace โ SpecialFunctionsExt
1748.3 ms โ HypergeometricFunctions
1171.2 ms โ HarfBuzz_jll
2079.1 ms โ Interpolations โ InterpolationsUnitfulExt
3090.3 ms โ Netpbm
3624.9 ms โ StatsFuns
1342.7 ms โ libass_jll
1335.8 ms โ Pango_jll
1230.2 ms โ StatsFuns โ StatsFunsInverseFunctionsExt
10670.0 ms โ DelaunayTriangulation
3002.4 ms โ StatsFuns โ StatsFunsChainRulesCoreExt
21483.1 ms โ FFTW
13876.0 ms โ MathTeXEngine
1787.3 ms โ FFMPEG_jll
1473.2 ms โ Cairo
6984.7 ms โ Distributions
916.4 ms โ Distributions โ DistributionsChainRulesCoreExt
1504.7 ms โ Distributions โ DistributionsTestExt
1350.1 ms โ KernelDensity
86039.9 ms โ TiffImages
994.1 ms โ ImageIO
135154.4 ms โ Makie
42593.9 ms โ CairoMakie
162 dependencies successfully precompiled in 317 seconds. 110 already precompiled.
1 dependency had output during precompilation:
โ MKL_jll
โ Downloading artifact: IntelOpenMP
โ
Precompiling ParsersExt...
415.7 ms โ InlineStrings โ ParsersExt
1 dependency successfully precompiled in 0 seconds. 9 already precompiled.
Precompiling SerializationExt...
366.9 ms โ LRUCache โ SerializationExt
1 dependency successfully precompiled in 0 seconds. 2 already precompiled.
Precompiling IntervalArithmeticRecipesBaseExt...
689.1 ms โ IntervalArithmetic โ IntervalArithmeticRecipesBaseExt
1 dependency successfully precompiled in 1 seconds. 33 already precompiled.
Precompiling ArchGDALMakieExt...
2210.4 ms โ ArchGDAL โ ArchGDALMakieExt
1 dependency successfully precompiled in 3 seconds. 306 already precompiled.
Precompiling GeoMakie...
550.6 ms โ SortTileRecursiveTree
975.3 ms โ GeometryOpsCore
1027.4 ms โ CoordinateTransformations
2508.6 ms โ Geodesy
2549.6 ms โ Proj
4202.0 ms โ GeometryOps
1198.1 ms โ GeometryOps โ GeometryOpsProjExt
25797.9 ms โ GeoJSON
1093.7 ms โ NaturalEarth
1359.7 ms โ GeoJSON โ GeoJSONMakieExt
9156.5 ms โ GeoMakie
11 dependencies successfully precompiled in 37 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...
658.2 ms โ Interfaces
673.9 ms โ FieldMetadata
866.3 ms โ ArrayInterface
1203.4 ms โ CFTime
834.6 ms โ Flatten
704.8 ms โ ArrayInterface โ ArrayInterfaceStaticArraysCoreExt
845.9 ms โ ArrayInterface โ ArrayInterfaceSparseArraysExt
1734.5 ms โ Setfield
1346.0 ms โ CommonDataModel
14873.5 ms โ DimensionalData
781.0 ms โ DimensionalData โ DimensionalDataDiskArraysExt
5517.0 ms โ Rasters
12 dependencies successfully precompiled in 23 seconds. 58 already precompiled.
Precompiling ArrayInterfaceChainRulesCoreExt...
368.5 ms โ ArrayInterface โ ArrayInterfaceChainRulesCoreExt
1 dependency successfully precompiled in 0 seconds. 11 already precompiled.
Precompiling DimensionalDataMakie...
806.2 ms โ DimensionalData โ DimensionalDataStatsBase
6820.6 ms โ DimensionalData โ DimensionalDataMakie
2 dependencies successfully precompiled in 7 seconds. 277 already precompiled.
Precompiling RastersMakieExt...
1327.4 ms โ Rasters โ RastersStatsBaseExt
6640.2 ms โ Rasters โ RastersMakieExt
2 dependencies successfully precompiled in 8 seconds. 291 already precompiled.
Precompiling RastersProjExt...
1270.3 ms โ Rasters โ RastersCoordinateTransformationsExt
1392.3 ms โ Rasters โ RastersProjExt
2 dependencies successfully precompiled in 1 seconds. 92 already precompiled.
Precompiling RastersArchGDALExt...
2373.3 ms โ Rasters โ RastersArchGDALExt
1 dependency successfully precompiled in 3 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.