Skip to content

Listing polygon properties

This page gives an overview of the methods to get access to additional information stored in the polygon data.

julia
using SpeciesDistributionToolkit

We will select the Countries dataset from NaturalEarth as our example:

julia
polydata = PolygonData(NaturalEarth, Countries)
PolygonData{NaturalEarth, Countries}()

These data can be retrieved with getpolygon:

julia
pol = getpolygon(polydata)
FeatureCollection with 258 features, each with 4 properties

This returns the complete dataset, which is almost always a lot more polygons that we want. To figure out which polygons are relevant, we need to inspect the properties attached to each:

julia
keys(uniqueproperties(pol))
KeySet for a Dict{String, Vector} with 4 entries. Keys:
  "Population"
  "Subregion"
  "Name"
  "Region"

Note that by default, the Name key can be used directly:

julia
pol["Ghana"]
Polygon Feature
├ Region => Africa
├ Subregion => Western Africa
├ Name => Ghana
└ Population => 30417856

We will look at which regions are available here:

julia
uniqueproperties(pol)["Region"]
6-element Vector{String}:
 "Asia"
 "Americas"
 "Africa"
 "Europe"
 "Oceania"
 "Antarctica"

Getting the countries for Africa is therefore:

julia
pol["Region" => "Africa"]
FeatureCollection with 62 features, each with 4 properties

We can apply the uniqueproperties function to the object that is returned here, for example to list all available sub-regions:

julia
uniqueproperties(pol["Region" => "Africa"])["Subregion"]
6-element Vector{String}:
 "Eastern Africa"
 "Northern Africa"
 "Middle Africa"
 "Southern Africa"
 "Western Africa"
 "Seven seas (open ocean)"

We can now get all of the polygons in the region of Africa that are in the sub-region of Eastern Africa with:

julia
eastern_afr = pol["Region" => "Africa"]["Subregion" => "Eastern Africa"]
FeatureCollection with 19 features, each with 4 properties

Missing docstring.

Missing docstring for uniqueproperties. Check Documenter's build log for details.

Missing docstring.

Missing docstring for getpolygon. Check Documenter's build log for details.

SimpleSDMPolygons.PolygonData Type
julia
PolygonData
source