GeoGraphics Introduction

Just the Maps

First we call up a list of all the states. We can do this simple through Entities by using ctrl+= “States of the US”. If we leave it at this we just get a single entity block so to get the full list we and EntityList to the front with the @ or “prefix” shortcut.

states =EntityList@LinguisticAssistant

We can see what entity properties each of the states in out list has. As an example we can use California (which is in the 5th position) using the [[]] shortcut for “part”.

states[[5]]["Properties"]

states[[5]]["CapitalCity"]

To get the properties of a state for each state in our list we can map a pure function to each element in the states list using the &/@ shortcut. This generates a new list of all the state capitals

f[#]&/@{x,y,z}

capitals = #["CapitalCity"]&/@ states

Length[states]

We can use GeoPosition to get the coordinates for an entity (in latitude and longitude) then use GeoListPlot to plot a list of these coordinates.

cali =GeoPosition[LinguisticAssistant]

GeoListPlot[cali, GeoRange->"Country"]

We can even get the coordinates for some historical locations

LinguisticAssistant

GeoPosition[LinguisticAssistant]

GeoListPlot[{LinguisticAssistant, LinguisticAssistant}]

Instead of plotting thing like a state or empire with a point, it may be more accurate to represent them as an entire region. We can do this using GeoGraphics. Geographics is a lot like traditional graphics; it contains a list of primitives with there directives formatted in the same way as normal graphics except we can say Polygon[*some place*] to get the shape of that place. We use Edge Form to modify the border and FaceForm to modify the filling of the Polygon. GeoBackground lets us change the type of map we use in the background and GeoGridLines lets us put of Latitude and Longitude lines.

GeoGraphics[{{EdgeForm[Black],FaceForm[Red],Polygon[LinguisticAssistant]},{EdgeForm[Black],FaceForm[Red], Polygon[LinguisticAssistant]}},GeoBackground->"ReliefMap",GeoGridLines->Automatic]

We can make a manipulate that iterates through our list of states, highlighting one state at a time and displaying an area of 1000 miles around that state using the GeoRange (similar to plot range). This is slow because each time we are calling the polygon property of a state and generating a new relief map for each state.

Manipulate[GeoGraphics[{EdgeForm[Black],FaceForm[Red],Polygon[state]},GeoBackground->"CountryBorders",GeoGridLines->Automatic, GeoRange->Quantity[1000,"Miles"]],{state,states}]

To make it smoother we can use a different map: the “CountryBoards” style and select a fixed GeoRange with specific lat and long to keep the scope of the map constant.

Manipulate[GeoGraphics[{EdgeForm[Black],FaceForm[Green],Polygon[state]},GeoBackground->"CountryBorders",GeoGridLines->Automatic, GeoRange->{{0,70},{-170,-40}}],{state,states}]

Geo Styling

Let’s start off with some basic GeoStyling functions.

Although you can outline a country using Polygon[Area you specified], you can make the chosen area on the map more succinct by using GeoStyling.

GeoGraphics[{EdgeForm[Blue],GeoStyling[Red],Polygon[LinguisticAssistant]}]

You can even see the Satellite image of the area you specified.

GeoGraphics[{EdgeForm[Blue],GeoStyling["Satellite"],Polygon[LinguisticAssistant]}]

Here are some cool examples of what you can do with GeoStyling. Using GeoStyling[Automatic], you can control the opacity of the polygon.

GeoGraphics[{
GeoStyling[Automatic],Purple,Opacity[0.8],Polygon[LinguisticAssistant],
GeoStyling[{"Image",LinguisticAssistant["Flag"]}],
GeoStyling["ReliefMap"],Polygon[LinguisticAssistant],
GeoStyling["Satellite"],Polygon[LinguisticAssistant],
GeoStyling["OutlineMap"],Polygon[LinguisticAssistant],
GeoStyling["ContourMap"],Polygon[LinguisticAssistant],
GeoStyling["Satellite"],Polygon[LinguisticAssistant]}]

Image Processing functions still apply when doing GeoGraphics i.e. EdgeDetect, ImageMultiply, etc.

worldedge=EdgeDetect[GeoGraphics["World",GeoBackground->GeoStyling["Coastlines"],GeoProjection->"Mollweide"] ]

world=GeoGraphics["World",GeoBackground->GeoStyling[{"Coastlines","Land"->Green,"Ocean"->Blue,"Border"->Red}],GeoProjection->"Mollweide"]

coolworld=ImageMultiply[worldedge,world]

Map images based on each country. Hover over the point on San Diego to blow up an image.

GeoGraphics[{
Polygon[LinguisticAssistant],{GeoStyling["ReliefMap"]},
Red,PointSize[Large],Tooltip[Point[LinguisticAssistant], ],
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]},
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]},
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]} ,
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]},
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]} ,
{GeoStyling[{"GeoImage",}], Polygon[LinguisticAssistant]}}]

Coloring the States based on Statistics

To do this we need to select some numerical property each state entity has. Strangely, average rainfall is not a property of states entities so we’ll just use average SAT score. Relax, these are all with the Old SAT (out of 2400)

(Entity["California, United States", Entity["AdministrativeDivision",{"California","UnitedStates"}], "Entity[\"AdministrativeDivision\", {\"California\", \"UnitedStates\"}]", "administrative division"])["AverageTotalSATScore"]

The next thing we need to do is pick a color scheme. Mathematica has a good amount of built in color scheme so feel free to pick your own. All these schemes are gradients that vary continuously, indexed from 0 to 1. You can select a specific color by selecting a value between 0 and 1.

ColorData["TemperatureMap",0.3]

ColorData["AvocadoColors"]

We can assign a score to a color by getting the  score and dividing by the highest possible score so a score of 2400 (full score) correlates to the 1 value in our color scheme.

ColorData["TemperatureMap",N@LinguisticAssistant["AverageTotalSATScore"]/2400]

Instead of using a manipulate we use table within GeoGraphics to draw all the polygons for the states at once.

GeoGraphics[Table[{EdgeForm[Black],GeoStyling[Green],Polygon[states[[state]]]},{state,1,51}],GeoBackground->"CountryBorders",GeoGridLines->Automatic, GeoRange->{{0,70},{-170,-40}}]

Now, finally, we insert the color for each state into the FaceForm function to color each polygon the right color.

scores = Table[N@states[[n]]["AverageTotalSATScore"],{n,1,Length[states]}];
GeoGraphics[Table[{EdgeForm[Black],GeoStyling[ColorData["TemperatureMap",scores[[n]]/2400]],Polygon[states[[n]]]},{n,1,51}],GeoBackground->"Coastlines",GeoGridLines->Automatic, GeoRange->{{0,70},{-170,-40}}]

scores = Table[N@states[[n]]["Earnings"],{n,1,Length[states]}];
min =Min[scores];
scoresshifted = scores - min;
max =Max[scoresshifted];
normscores =scoresshifted/max;
GeoGraphics[Table[{EdgeForm[Black],GeoStyling[ColorData["AvocadoColors",normscores[[n]]]],Polygon[states[[n]]]},{n,1,51}],GeoBackground->"Coastlines",GeoGridLines->Automatic, GeoRange->{{0,70},{-170,-40}}]

eucountries =EntityList@ LinguisticAssistant

scores = Table[N@eucountries[[n]]["Population"],{n,1,Length[eucountries]}];
GeoGraphics[Table[{EdgeForm[Black],GeoStyling[ColorData["TemperatureMap",scores[[n]]/Max[scores]]],Polygon[eucountries[[n]]]},{n,1,51}],GeoBackground->"Coastlines",GeoGridLines->Automatic, GeoRange->LinguisticAssistant, GeoProjection->"LambertAzimuthal"]

More Map Stuff

GeoBackground has function “CountryBorders” that helps you visualize the borders at a certain date.

GeoGraphics[Polygon[LinguisticAssistant],GeoBackground->"CountryBorders"]

GeoGraphics[Polygon[LinguisticAssistant],GeoBackground->Dated["CountryBorders",1700]]

The United States is a bit boring when it comes to boundaries, so let’s take a look at Europe

Table[GeoGraphics[Polygon[LinguisticAssistant],GeoBackground->Dated["CountryBorders",n], ImageSize->Large],{n,{1700,1800,1900}}]

GeoZoom & GeoRangePadding

GeoGraphics[{Polygon[LinguisticAssistant]},GeoRangePadding->90LinguisticAssistant]

You can take the area that you don’t want out of the picture, using Geo Range Padding, and you can zoom in to an image using different factors in geo zoom level.

Manipulate[GeoGraphics[GeoCenter->LinguisticAssistant,GeoZoomLevel->zoom],{zoom,{1,5,8,11,15,18}}]

Credits

Spencer Shroff and Joshua Chung
CT@TP: Computational Thinking at Torrey Pines High School
Advanced Topics in Math II
Fall 2018

Some examples were taken and modified from the Wolfram Documentation.