55
66 zvals = polygonlevels(D::GDtype, idvals::GMTdataset; kw...) -> Vector{Float64}
77
8- Create a vector with `zvals` to use in `plot` and where length(zvals) == length(D)
8+ Create a vector with `zvals` to use in `plot` when creating choropleth maps and where length(zvals) == length(D)
99
1010The elements of `zvals` are made up from the `vals`.
1111
@@ -24,6 +24,9 @@ The elements of `zvals` are made up from the `vals`.
2424- `attrib` or `att`: Select which attribute to use when matching with contents of the `ids` strings.
2525- `nocase` or `insensitive`: Perform a case insensitive comparision between the contents of
2626 `ids` and the attribute specified with `attrib`. Default compares as case sensistive.
27+ - `starts,ends,contains`: Sometimes the attribute value is only part of the string in `ids`.
28+ Use one of these options to specify how to match. E.g. `ends=true` selects all attributes
29+ that ends with a match in `ids`. Default is the exact match.
2730- `repeat`: Replicate the previously known value until it finds a new segment ID for the case
2831 when a polygon have no attributes (may happen for the islands in a country).
2932
4851function polygonlevels (D:: Vector{<:GMTdataset} , user_ids:: Vector{<:AbstractString} , vals:: Vector{<:Real} ; kw... ):: Vector{Float64}
4952 @assert ((n_user_ids = length (user_ids)) == length (vals))
5053 ((att = find_in_kwargs (kw, [:att :attrib ])[1 ]) === nothing ) && error (" Must provide the `attribute` NAME." )
51- nocase = (find_in_kwargs (kw, [:nocase :insensitive ])[1 ] === nothing ) ? true : false
52- repeat = (find_in_kwargs (kw, [:repeat ])[1 ] === nothing ) ? false : true
54+ nocase = ! is_in_kwargs (kw, [:nocase :insensitive ]) # i.e. case insensitive
55+ repeat = is_in_kwargs (kw, [:repeat ])
56+ ends = is_in_kwargs (kw, [:ends ])
57+ starts = is_in_kwargs (kw, [:starts ])
58+ contains_ = is_in_kwargs (kw, [:contains ])
59+ fun = starts ? startswith : ends ? endswith : contains_ ? contains : Base.:(== )
60+ exact = ! (starts || ends || contains_)
5361
5462 n_seg = length (D)
5563 zvals = fill (NaN , n_seg)
56- if (nocase)
57- for m = 1 : n_seg
58- isempty (D[m]. attrib) && (repeat && (zvals[m] = zvals[m- 1 ]); continue )
59- for k = 1 : n_user_ids
60- if (D[m]. attrib[att] == user_ids[k])
61- zvals[m] = vals[k]; break
62- end
63- end
64- end
65- else
66- for m = 1 : n_seg
67- isempty (D[m]. attrib) && (repeat && (zvals[m] = zvals[m- 1 ]); continue )
68- t = lowercase (D[m]. attrib[att])
69- for k = 1 : n_user_ids
70- if (t == lowercase (user_ids[k]))
71- zvals[m] = vals[k]; break
72- end
64+
65+ for m = 1 : n_seg
66+ isempty (D[m]. attrib) && (repeat && (zvals[m] = zvals[m- 1 ]); continue )
67+ t = (nocase) ? D[m]. attrib[att] : lowercase (D[m]. attrib[att])
68+ for k = 1 : n_user_ids
69+ to_comp = (nocase) ? user_ids[k] : lowercase (user_ids[k])
70+ condition = (exact) ? (t == to_comp) : fun (t, to_comp)
71+ if (condition)
72+ zvals[m] = vals[k]; break
7373 end
7474 end
7575 end
0 commit comments