Skip to content

Commit b816214

Browse files
committed
Comm
1 parent a7c75af commit b816214

File tree

7 files changed

+113
-18
lines changed

7 files changed

+113
-18
lines changed

documentation/all_docs_ref/all_refs.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ its use requires resorting to the \myreflink{Monolithic} mode.
6565
| \myreflink{cubeplot} | \myreflink{coastlinesproj} | \myreflink{cubeslice} | \myreflink{date2doy} | \myreflink{delrows!} | \myreflink{doy2date} | \myreflink{findpeaks} | \myreflink{gadm} |
6666
| \myreflink{geocoder} | \myreflink{geodetic2enu} | \myreflink{getbyattrib} | \myreflink{gmtread} | \myreflink{gmtwrite} | \myreflink{graticules} | \myreflink{gridit} | \myreflink{gunique} |
6767
| \myreflink{hampel} | \myreflink{imagesc} | \myreflink{inpolygon} | \myreflink{inwhichpolygon} | \myreflink{image_alpha!} | \myreflink{image_cpt!} | \myreflink{imshow} | \myreflink{ind2rgb} |
68-
| \myreflink{info} | \myreflink{isnodata} | \myreflink{isoutlier} | \myreflink{lazread} | \myreflink{lazwrite} | \myreflink{lelandshade} | \myreflink{linearfitxy} | \myreflink{magic} |
69-
| \myreflink{mat2ds} | \myreflink{mat2grid} | \myreflink{mat2img} | \myreflink{mosaic} | \myreflink{ODE2ds} | \myreflink{orbits} | \myreflink{pca} | \myreflink{plotgrid!} |
70-
| \myreflink{plotyy} | \myreflink{pol2cart} | \myreflink{polygonlevels} | \myreflink{rasterzones!} | \myreflink{regiongeog} | \myreflink{remotegrid} | \myreflink{rescale} | \myreflink{slicecube} |
71-
| \myreflink{sph2cart} | \myreflink{stackgrids} | \myreflink{ter2cart} | \myreflink{theme} | \myreflink{uniqueind} | \myreflink{vecangles} | \myreflink{whereami} | \myreflink{worldrectgrid} |
72-
| \myreflink{worldrectcoast} | \myreflink{worldrectangular} | \myreflink{xyzw2cube} | \myreflink{yeardecimal} | \myreflink{zonal_stats} | | | |
68+
| \myreflink{info} | \myreflink{isnodata} | \myreflink{isoutlier} | \myreflink{lazread} | \myreflink{lazwrite} | \myreflink{leepacific} | \myreflink{lelandshade} | \myreflink{linearfitxy} |
69+
| \myreflink{magic} | \myreflink{mat2ds} | \myreflink{mat2grid} | \myreflink{mat2img} | \myreflink{mosaic} | \myreflink{ODE2ds} | \myreflink{orbits} | \myreflink{pca} |
70+
| \myreflink{plotgrid!} | \myreflink{plotyy} | \myreflink{pol2cart} | \myreflink{polygonlevels} | \myreflink{rasterzones!} | \myreflink{regiongeog} | \myreflink{remotegrid} | \myreflink{rescale} |
71+
| \myreflink{slicecube} | \myreflink{sph2cart} | \myreflink{stackgrids} | \myreflink{ter2cart} | \myreflink{theme} | \myreflink{uniqueind} | \myreflink{vecangles} | \myreflink{whereami} |
72+
| \myreflink{worldrectgrid} | \myreflink{worldrectcoast} | \myreflink{worldrectangular} | \myreflink{xyzw2cube} | \myreflink{yeardecimal} | \myreflink{zonal_stats} | | |
7373

7474
## Solids functions
7575

documentation/modules/coast.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,31 @@ painted and no land fill is set then the land-areas will be transparent. A map p
4141
The resolution drops off by 80% between data sets. The default is **res=:auto**, which chooses
4242
to automatically select the best resolution given the chosen map scale.
4343

44-
- **E** or **DCW** : -- *DCW=code1,code2,...* **|** *DCW=(country=code, continent=code, pen=pen, fill=fill, file=fname, inside=true, outside=false, adjust_r=??, , adjust_R=??, , adjust_e=??, headers=false)*\
45-
Select painting country polygons from the Digital Chart of the World. This is another dataset independent of GSHHG and hence the **area** and **resolution** options do not apply. **DCW="+l"** just list the countries and their codes [plotting takes place] and **DCW="+L"** shows states/territories for Argentina, Australia, Brazil, Canada, and the US. *country* or **name=code(s)**, where **code(s)** is a one or more comma-separated countries using the 2-character ISO 3166-1 alpha-2 convention. To select a state of a country (if available), append .state, e.g, US.TX for Texas. To specify a whole continent, use **continent=code**, with continent codes AF (Africa),AN (Antarctica), AS (Asia), EU (Europe), OC (Oceania), NA (North America), or SA (South America). Use **pen=pen** (see \myreflink{Pen attributes}) to draw polygon outlines and **fill=fill** (see \myreflink{Fill color/pattern}) to fill them [default is no fill]. At least one of these must be specified unless **dump** is in effect, in which case only one **DCW** option can be given. It is also possible to specify the parameters using simple Tuples. For example: **DCW=("PT", (0.5,"red","--"), "blue")** plots the polygon *PT* with a 0.5p red dashed line and filled with blue and **DCW=:PT** uses a default pen of 0.5. **DCW=(:PT, :blue)** fills with blue. You may repeat **DCW** to give different groups of items their own *pen/fill* settings. However, since we cannot repeat a keyword, the solution to setting different groupes is to use a tuple of tuples. An example would be *DCW=((country=:PT, pen=(2,:red), fill=:blue), (country=:ES, pen=(2,:blue)) )*. If neither **proj** nor **dump** are set then we just print the **region**. The **file=fname** is a option to let users select alternative DCW files. Available options by default are: *ODS*, *NE10m* or *NE110m*. For example: `DCW=(country=:CH, file=:ODS)` extracts the Swiss polygon from (small) `ODS.nc` file. The **inside=true** (the default) means that data is ket _inside_ the clipping polygon. Use **outside=true** if want the reverse. **adjust_r=??** adjusts the region boundaries to be multiples of the steps indicated by _inc_ or _xinc/yinc_ or _winc/einc/sinc/ninc_. **adjust_R=??** adjusts the region boundaries adding the amounts specified by _inc_ or _xinc/yinc_ or _winc/einc/sinc/ninc_. **headers=true** place the country code in the segment headers via _-Zcode_ settings (for use with the **dump** option).
44+
- **E** or **DCW** : -- *DCW=code1,code2,...* **|** *DCW=(country=code, continent=code, states=code, pen=pen, fill=fill, file=fname, inside=true, outside=false, adjust_r=??, , adjust_R=??, , adjust_e=??, headers=false)*\
45+
Select painting country polygons from the Digital Chart of the World. This is another dataset independent
46+
of GSHHG and hence the **area** and **resolution** options do not apply. **DCW="+l"** just list the countries
47+
and their codes [plotting takes place] and **DCW="+L"** shows states/territories for Argentina (AR), Australia (AU),
48+
Brazil (BR), Canada (CA), China (CN), Great Britan (GB), India (IR), Russia (RU), and the US (US).
49+
*country* or **name=code(s)**, where **code(s)** is a one or more comma-separated countries using the 2-character
50+
ISO 3166-1 alpha-2 convention. To select a state of a country (if available), append .state, e.g, US.TX for Texas.
51+
To get all states in a country, use **states=code** or `DCW=+code` (only available for AR, AU, BR, CA, CN, GB, IN,
52+
NO, RU, and US). To specify a whole continent, use **continent=code**,
53+
with continent codes AF (Africa), AN (Antarctica), AS (Asia), EU (Europe), OC (Oceania), NA (North America),
54+
or SA (South America). Use **pen=pen** (see \myreflink{Pen attributes}) to draw polygon outlines and **fill=fill**
55+
(see \myreflink{Fill color/pattern}) to fill them [default is no fill]. At least one of these must be specified
56+
unless **dump** is in effect, in which case only one **DCW** option can be given. It is also possible to specify
57+
the parameters using simple Tuples. For example: **DCW=("PT", (0.5,"red","--"), "blue")** plots the polygon *PT*
58+
with a 0.5p red dashed line and filled with blue and **DCW=:PT** uses a default pen of 0.5. **DCW=(:PT, :blue)**
59+
fills with blue. You may repeat **DCW** to give different groups of items their own *pen/fill* settings. However,
60+
since we cannot repeat a keyword, the solution to setting different groupes is to use a tuple of tuples. An example
61+
would be *DCW=((country=:PT, pen=(2,:red), fill=:blue), (country=:ES, pen=(2,:blue)) )*. If neither **proj** nor
62+
**dump** are set then we just print the **region**. The **file=fname** is a option to let users select alternative
63+
DCW files. Available options by default are: *ODS*, *NE10m* or *NE110m*. For example: `DCW=(country=:CH, file=:ODS)`
64+
extracts the Swiss polygon from (small) `ODS.nc` file. The **inside=true** (the default) means that data is kept
65+
_inside_ the clipping polygon. Use **outside=true** if want the reverse. **adjust_r=??** adjusts the region boundaries
66+
to be multiples of the steps indicated by _inc_ or _xinc/yinc_ or _winc/einc/sinc/ninc_. **adjust_R=??** adjusts
67+
the region boundaries adding the amounts specified by _inc_ or _xinc/yinc_ or _winc/einc/sinc/ninc_. **headers=true**
68+
place the country code in the segment headers via _-Zcode_ settings (for use with the **dump** option).
4669

4770
- **getR** or **getregion** or **get_region** : -- *getR=code1,code2,...*\
4871
Return the region corresponding to the code/list-of-codes passed in as argument. The code(s) are the same

documentation/utilities/coastlinesproj.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coastlinesproj
22

33
```julia
4-
cl = coastlinesproj(proj="?", res="crude", coastlines=nothing)
4+
cl = coastlinesproj(proj="?", res="crude", coastlines=nothing, limits=Float64[])
55
```
66

77
Extract the coastlines from GMT's GSHHG database and project them using PROJ (NOT the GMT projection machinery).
@@ -21,7 +21,7 @@ This allows the use of many of the PROJ projections that are not available from
2121
Returns
2222
-------
2323

24-
A Vector of \myreflink{GMTdataset} containing the projected (or not) world GSHHG coastlines at resolution `res`.
24+
A Vector of \myreflink{GMTdataset} containing the projected world GSHHG coastlines at resolution `res`.
2525

2626

2727
Example

documentation/utilities/getbyattrib.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ NOTE: Instead of ``getbyattrib`` one can use instead ``filter`` (..., `index=fal
2323
means select all elements from ``Antioquia`` and ``Caldas`` that have the attribute `feature_id` = 0.
2424

2525
A second set of attributes can be used to select elements by region, number of polygon vertices and area.
26-
For that, name the keyword with a leading underscore, e.g. `_region`, `_nps`, `_area`. Their values are
26+
For that, name the keyword with a leading underscore, e.g. `_region`, `_nps`, `_area`, `_unique`. Their values are
2727
passed respectively a 4 elements tuple and numbers. E.g. `_region=(-8.0, -7.0, 37.0, 38.0)`, `_nps=100`, `_area=10`.
28-
Areas are in square km when input is in geographic coordinates, otherwise squre data unites.
28+
Areas are in square km when input is in geographic coordinates, otherwise squre data unites. The `_unique` case is
29+
a bit special and is meant to be used when more than one polygon share the same attribute value (_e.g._ countries with islands).
30+
In that case, set the value of `_unique` to the name of the attribute that is shared by the polygons (_e.g._ `_unique="NAME"`).
31+
By default (_e.g._ `_unique=true`), the attribute name is `Feature_ID` which is the one used by GMT when creating unique
32+
IDs for polygons read from OGR formats (.shp, .geojson, etc). If this attrib name is not found, we search for `CODE` which is
33+
the one assigned by GMT when extracting polygons from the internal GMT coasts database. If none of these is found,
34+
it is users responsibility to provide a valid attribute name. The uniqueness is determined by selecting the polygon
35+
with the largest area.
2936

3037
- `attrib` or `att`: (OLD SYNTAX) A NamedTuple with the attribname, attribvalue as in `att=(NAME_2="value",)`.
3138
Use more elements if wishing to do a composite match. E.g. `att=(NAME_1="val1", NAME_2="val2")` in which

documentation/utilities/polygonlevels.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ or
88
zvals = polygonlevels(D::GDtype, idvals::GMTdataset; kw...) -> Vector{Float64}
99
```
1010

11-
Creates a vector with `zvals` to use in `plot` and where length(zvals) == length(D)
12-
The elements of `zvals` are made up from the `vals`.
11+
Creates a vector with `zvals` to use in `plot` when creating choropleth maps and where length(zvals) == length(D).
1312

1413
- `ids`: is a string Vector or Matrix with the ids (attribute names) of the \myreflink{GMTdataset} D.
1514
If a Matrix (2 columns only) then the `att` bellow must also have the two names (string vector
@@ -27,6 +26,10 @@ The elements of `zvals` are made up from the `vals`.
2726
- `nocase` or `insensitive`: a keyword from `kw`. Perform a case insensitive comparision between the contents of
2827
`ids` and the attribute specified with `attrib`. Default compares as case sensistive.
2928

29+
- `starts,ends,contains`: Sometimes the attribute value is only part of the string in `ids`.
30+
Use one of these options to specify how to match. E.g. `ends=true` selects all attributes
31+
that ends with a match in `ids`. Default is the exact match.
32+
3033
- `repeat`: keyword to replicate the previously known value until it finds a new segment ID for the case
3134
when a polygon have no attributes (may happen for the islands in a country).
3235

documentation/utilities/worldrectangular.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# worldrectangular
22

33
```julia
4-
GI[,coast] = worldrectangular(GI; proj::String="+proj=vandg", pm=0, latlim=:auto, coast=false)
4+
GI[,coast] = worldrectangular(fname::String|GI::GItype; proj::String="+proj=vandg", pm=0, latlim=:auto, coast=false)
55
```
66

77
Try to create a rectangular map out miscellaneous and not cylindrical projections. We say *try* because
@@ -45,5 +45,5 @@ viz(G)
4545
See Also
4646
--------
4747

48-
\myreflink{coastlinesproj}, \myreflink{graticules}, \myreflink{plotgrid!}, \myreflink{worldrectgrid}, \myreflink{worldrectcoast},
48+
\myreflink{coastlinesproj}, \myreflink{graticules}, \myreflink{leepacific}, \myreflink{plotgrid!}, \myreflink{worldrectgrid}, \myreflink{worldrectcoast},
4949
\myreflink{Best rectangular world map projection}

tutorials/choropleths/choropleths.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
### What color is your State?
44

5-
This example shows an adaptation of the [Average color of World](https://erdavis.com/2021/06/26/average-colors-of-the-world/) examples.
6-
It differs slightly for the also shown US case likely due to the different data used. Here we retrieve
7-
the image data (Sentinel 2) from the [EOX WMS server](https://eox.at/) and use the year 2020.
5+
This example shows an adaptation of the [Average color of World](https://erdavis.com/2021/06/26/average-colors-of-the-world/)
6+
examples. It differs slightly for the also shown US case likely due to the different data used. Here we retrieve
7+
the image data (Sentinel 2) from the [EOX WMS server](https://eox.at/) and use the year 2020. And, as a side note, realize
8+
how incredibly simpler this example is as comparing to the codes used to generate the figures in that blog.
89

910
Note how the sates polygons are read directly from source, without any previous download, uncompressing file format conversions, etc...
1011
We will also filter the states polygons to use only those inside the US continental zone and limit them by number
@@ -82,3 +83,64 @@ viz(D, region=(-125,-66,24,50), level=zvals, cmap=C, proj=:guess,
8283
plot=(data=D,lw=0), title="Population (Millions)", colorbar=true)
8384
```
8485
\end{examplefig}
86+
87+
### Choropleths by symbol color
88+
89+
To avoid the perceptual problem of over-enphasize the polygon's are we can alternatively use colored
90+
symbols (or symbols of different sizes). That can be done with the `bubblechart` program. One issue,
91+
though, that we have to deal in this case is that a state can have multiple polygons (for example
92+
Hawaii has many islands, and Michigan has two main landmasses). So, we need to calculate the largest
93+
polygon of each state and its centroid to place the symbol there.
94+
95+
\begin{examplefig}{}
96+
```julia
97+
using GMT # Hide
98+
D = gmtread("/vsizip//vsicurl/https://www2.census.gov/geo/tiger/GENZ2024/shp/cb_2024_us_state_500k.zip"); # Hide
99+
100+
Df = filter(D, _region=(-125,-66,24,50), _unique=true); # Keep only the largest polygon per state
101+
102+
pop = gmtread(TESTSDIR * "assets/uspop.csv");
103+
zvals = polygonlevels(Df, pop, att="NAME") / 1e6;
104+
C = makecpt(zvals, auto=:r, reverse =true, cmap=:bamako);
105+
106+
bubblechart(Df, labels="attrib=STUSPS", proj=:guess, zcolor=zvals,
107+
cmap=C, colorbar=true, show=true)
108+
```
109+
\end{examplefig}
110+
111+
112+
In all the examples above we have used the US states polygons from a downloaded file, but we actually no not
113+
need that as the internal GMT coasts database has the US states polygons. So, we can use the `coast` function
114+
to get extract the states polygons and use them in the same way as above. Here is an example that would
115+
produce the exactly same image. But note how attribute names are different now as state names are stored
116+
under the "CODE" attribute.
117+
118+
```julia
119+
using GMT # Hide
120+
121+
D = coast(DCW=(states="US",)) # Or simply D = coast(DCW="+US");
122+
Df = filter(D, _region=(-125,-66,24,50), _unique=true);
123+
124+
pop = gmtread(TESTSDIR * "assets/uspop.csv");
125+
zvals = polygonlevels(Df, pop, att="NAME", contains=true) / 1e6;
126+
C = makecpt(zvals, auto=:r, reverse =true, cmap=:bamako);
127+
128+
bubblechart(Df, labels="attrib=CODE", proj=:guess, zcolor=zvals,
129+
cmap=C, colorbar=true, show=true)
130+
```
131+
132+
Note the `contains=true` option in the `polygonlevels` function call. That is needed because the state
133+
names in the `Df` dataset are like "Alabama (United States)" while in the `pop` table they are simply
134+
"Alabama". So, to do the joining operation, we had to be more relaxed and not impose an quality comparions
135+
(like the cases above) but to satisfy that the name in `pop` is contained in the name in `Df`.
136+
137+
```
138+
Df
139+
140+
Attribute table
141+
┌─────┬──────┬──────────────────────────────────────┐
142+
│ Row │ CODE │ NAME │
143+
├─────┼──────┼──────────────────────────────────────┤
144+
│ 1 │ AL │ Alabama (United States) │
145+
│ 2 │ AR │ Arkansas (United States) │
146+
```

0 commit comments

Comments
 (0)