Group Abstract Group Abstract

Message Boards Message Boards

Is GeoHistogram allowing bspec defined as a GeoVariants entities list?

Posted 8 years ago

Hi everyone, I wanted to plot a GeoHistogram at World Range with a different color for every country. Everything works fine as long as I set as bspec (bin specification) the entity "Country". The problem is, for instance, that the "UnitedStates" country does not include Alaska and Hawaii, but I know that you can define an entity that includes them like this

GeoVariant[CountryData["UnitedStates"],"PrincipalArea"]

So I tried to define a bspec list of this GeoVariant entities for plotting, but it doesn't work. Does anyone know a workaround to solve this problem?

POSTED BY: Gianluca Teza
3 Replies
Posted 8 years ago

I almost got it. The idea scheme is:

  1. Find the maximum and minimum values of the data you have;
  2. Normalize the values in a range within 0 and 1;
  3. Create a list of color with the ColorData function starting from the normalized values;
  4. Thread the countries list over the color list to obtain a "country->color" list;
  5. Plot with GeoRegionalValuePlot.

For instance, with the same data used in the example of the previous post we have:

countries = {CountryData[012], CountryData[024], CountryData[304], 
   GeoVariant[CountryData[840], "PrincipalArea"]};
values = {1.4, 2.6, 2.8, 3.5};
maxv = Max[values];
minv = Min[values];
normvalues = (values - minv)/(maxv - minv);
colors = ColorData["Rainbow", "ColorFunction"][#] & /@ normvalues;
data = Thread[countries -> colors];
GeoRegionValuePlot[data]

enter image description here

The only thing missing now is a legend of the color scheme with the original (non-normalized) values. Is it possible to add it manually?

Thanks again, best regards

Gianluca

POSTED BY: Gianluca Teza
Posted 8 years ago
POSTED BY: Gianluca Teza

Hi,

That is a bug and we are working on a better parsing. We actually support FilledCurves bins or a list of Polygons, but not mixed. Thanks for noticing it.

The USA GeoVariant includes 15 objects (Polygons and FilledCurves). For some reason the last polygon gives problems and most of the USA area is covered by FilledCurves, so we can convert those FilledCurves into Polygons (excluding gaps) and from there we can feed GeoHistogram with Polygonal bins only.

First, say you have this set of points:

pts = GeoPosition[
   Table[{lat, lon}, {lat, -60, 70}, {lon, -180, -35}]];

Now, if you plot those points you get:

enter image description here

As I mentioned, you can get the main USA area by:

USPolygons = 
  Cases[EntityValue[
     GeoVariant[CountryData["UnitedStates"], "PrincipalArea"], 
     "Polygon"], 
   FilledCurve[{{Line[g_]}, ___}] :> Polygon[g]];

And other countries polygons are:

otherCountries = 
  Table[Polygon /@ 
    GeoPosition /@ 
     First[First[
       EntityValue[CountryData[country], 
        "Polygon"]]], {country, {"Mexico", "Canada", "Brazil", "Peru",
      "Argentina", "Chile"}}];

Then use GeoHistogram by combining the polygons from USA and the polygons from other countries:

GeoHistogram[pts, {USPolygons, Sequence @@ otherCountries}]

enter image description here

I hope this is helpful.

Best regards, Emmanuel

POSTED BY: Emmanuel Garces
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard