Function Repository Resource:

GeoGraphicsCases

Source Notebook

Select parts of a GeoGraphics object using geo feature type

Contributed by: Jon McLoone

ResourceFunction["GeoGraphicsCases"][gr,form]

returns a GeoGraphics containing only features that match patt.

ResourceFunction["GeoGraphicsCases"][gr,{form1,form2,}]

returns a GeoGraphics containing only features that match any of the formi.

ResourceFunction["GeoGraphicsCases"][gr,Except[form]]

returns a GeoGraphics removing features that match form.

ResourceFunction["GeoGraphicsCases"][gr]

returns a list of feature types appropriate for formi present in GeoGraphics gr.

Details and Options

ResourceFunction["GeoGraphicsCases"] can only be applied to maps with vector backgrounds.

Examples

Basic Examples (3) 

Find the feature types present in a map of the Colosseum:

In[1]:=
gr = GeoGraphics[Entity["Building", "Colosseum::pq39x"], GeoRange -> Quantity[500, "Feet"]]
Out[1]=
In[2]:=
ResourceFunction["GeoGraphicsCases"][gr]
Out[2]=

Show only the "landcover" elements:

In[3]:=
ResourceFunction["GeoGraphicsCases"][gr, {__, "landcover"}]
Out[3]=

Show land cover and the buildings:

In[4]:=
ResourceFunction[
 "GeoGraphicsCases"][gr, {{__, "landcover"}, {_, "building", _}}]
Out[4]=

Scope (3) 

Wrapping the pattern or list of patterns with Except, removes those features and returns all others:

In[5]:=
gr = GeoGraphics[Entity["Building", "OCristoRedentor::fp39c"], GeoRange -> Quantity[1, "Kilometers"]]
Out[5]=
In[6]:=
ResourceFunction["GeoGraphicsCases"][gr, Except[{"fill", __}]]
Out[6]=

Remove labels:

In[7]:=
ResourceFunction["GeoGraphicsCases"][gr, Except[{"symbol", __}]]
Out[7]=

Remove filled regions and labels:

In[8]:=
ResourceFunction["GeoGraphicsCases"][gr, Except[{{"fill", __}, {_, "building", _}}]]
Out[8]=

Options (2) 

Some GeoGraphics also contain textured backgrounds. For example, selecting the transportation network for the UK also displays a landtype bitmap background:

In[9]:=
uk = GeoGraphics[Entity["Country", "UnitedKingdom"], GeoZoomLevel -> 7];
In[10]:=
ResourceFunction["GeoGraphicsCases"][uk, {__, "transportation"}]
Out[10]=

The option "RemoveTextures" can be used to remove bitmap textured polygons:

In[11]:=
ResourceFunction["GeoGraphicsCases"][uk, {__, "transportation"}, "RemoveTextures" -> True]
Out[11]=

Possible Issues (3) 

GeoGraphicsCases works only on GeoGraphics with vector backgrounds:

In[12]:=
ResourceFunction["GeoGraphicsCases"][
 GeoGraphics[Entity["Building", "Colosseum::pq39x"], GeoRange -> Quantity[500, "Feet"], GeoBackground -> "Satellite"]]
Out[12]=

Sometimes GeoGraphics elements are only visible because they are expected to have contrasting elements behind them:

In[13]:=
ResourceFunction["GeoGraphicsCases"][
 GeoGraphics[Entity["Building", "Colosseum::pq39x"], GeoRange -> Quantity[500, "Feet"]], {_, "path_area_cycleway", "transportation"}]
Out[13]=

You may need to replace colors to make them visible:

In[14]:=
ResourceFunction["GeoGraphicsCases"][
  GeoGraphics[Entity["Building", "Colosseum::pq39x"], GeoRange -> Quantity[500, "Feet"]], {_, "path_area_cycleway", "transportation"}] /. RGBColor[1., 1., 1.] -> Gray
Out[14]=

Neat Examples (2) 

Create an interactive feature selector:

In[15]:=
gr = GeoGraphics[Entity["Building", "Colosseum::pq39x"], GeoRange -> Quantity[500, "Feet"], ImageSize -> 400];
With[{choices = ResourceFunction["GeoGraphicsCases"][gr]},
 DynamicModule[{select = choices},
  Grid[{{Dynamic[ResourceFunction["GeoGraphicsCases"][gr, select]], CheckboxBar[Dynamic[select], choices, Appearance -> "Vertical"]}}]
  ]
 ]
Out[9]=

Decompose a map into features:

In[16]:=
GraphicsGrid[
 Partition[
  Rasterize[
     ResourceFunction["GeoGraphicsCases"][gr, #] /. RGBColor[1., 1., 1.] -> Gray] & /@ ResourceFunction["GeoGraphicsCases"][gr], 6, 6, 1, ""]]
Out[16]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 01 August 2025

Related Resources

License Information