Amusement Parks Adventure

By Simeon Buttery

Where in the world are there amusement parks?

Today, we will be exploring amusement parks around the world through entities.

Getting Started

Lets review entities quickly. If we press control =, we get an entity input.
In this, we can type something, like a dog, and then hit regular enter.
This then gives us the entity of a dog. 
Entities can act like functions, so if we ask for an image of the dog, the string “Image” is inside brackets after the entity. 
Then we can evaluate this to get a cute doggo picture.

LinguisticAssistant["Image"]

Ok, so to start this activity, we need a list of all the entities of amusement parks.
So we want an EntityList of all the amusement parks.
Before we evaluate this, lets set it to a variable called allparks.

allparks=EntityList["AmusementPark"]

So how many parks are there around the world?
We can find the length of allparks to find that.

Length[allparks]

Why are entities special? What properties do they have? Lets find out.

EntityValue["AmusementPark","Properties"]

Lets explore some of these properties. I’ll focus in on Legoland because its great and local.

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Properties"]

Lets try the position of Legoland.
I’ll be using command/control L to get the last line of code.

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Position"]

Is there a way to graphically show this geo data?
Yes! GeoGraphics!

GeoGraphics[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])]

Nice! A map! Where’s Legoland? I don’t know this off the top of my head, so we need a point.
Well then, lets add a point around Legoland.

GeoGraphics[Point[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])]]

Oh its there... That’s kinda hard to see though so lets make it easier to see.

GeoGraphics[{Red,PointSize[Large],Point[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])]}]

Multiple Parks

Now that we can make a point at one of the parks, lets make points at a lot of parks!
First, we need a random sample of parks.

someparks=RandomSample[allparks,20]

Now, we can just replace legoland with someparks, and it should work!

GeoGraphics[{Red,PointSize[Large],Point[someparks]}]

Now, this may work for you, but some of these parks don’t have position data, so they can’t be plotted with GeoGraphics. 
For example, Planet FunFun doesn’t have a known position in the Wolfram Language. It’s actually Planet SadSad for us.

LinguisticAssistant["Position"]

In order to find if an entity has a position, we can apply the position argument through a list of the entities.
To do this, we’ll use Through.

Through[{f,g,h}[x]]

Through[someparks["Position"]]

Now that we have the raw data, we can delete the missing points.

DeleteMissing[Through[someparks["Position"]]]

And then, we can plot all of these points that are not missing.

GeoGraphics[{Red,PointSize[Large],Point[DeleteMissing[Through[someparks["Position"]]]]}]

Labeling

Now, a map is cool and all, but which parks are these? The dots need to be labeled.
Lets try to only show the name if we hover over it, otherwise it will get a bit crowded.

To do this, we’ll use tooltips.
In order to use tooltips though, we need a list of points rather than a list of coordinates.
Lets use map and pure functions to do this.
If we have a function, we can map it and over at the list of variables.

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

So if we have a function that gets the point of the position, we can map it and over at this list of parks.

Point[#["Position"]]&/@someparks

Now that we have our points, we can make our tooltip.

Tooltip[point,name]

In this same way, our point is the point of the position of the park, and our name is the name of the park.
Then, we can map this tooltip function and over at our list of parks.

Tooltip[Point[#["Position"]],#["Name"]]&/@someparks

Next, we want to delete any missing points.

DeleteMissing[Tooltip[Point[#["Position"]],#["Name"]]&/@someparks]

Uhh, that didn’t work. Well this is because the points are a few layers deep into the raw data.
We’ll go through some of the layers with  ,1,2 at the end to properly accomplish this.

DeleteMissing[Tooltip[Point[#["Position"]],#["Name"]]&/@someparks,1,2]

Perfect. Now that we have out points, we can plot them with GeoGraphics.

GeoGraphics[{Red,PointSize[Large],DeleteMissing[Tooltip[Point[#["Position"]],#["Name"]]&/@someparks,1,2]}]

Fancy Time

This... works, but its a bit boring. Lets make it fancy!

First, we need to organize our code a bit. Basically, we want to isolate what the tooltip shows.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
#["Name"]
]&/@someparks,1,2]}]

Next, we want to make a column with the name, the city, and the country.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
#["Name"],
#["City"],
#["Country"]
}]
]&/@someparks,1,2]}]

Now that we have the basic structure, we can make it very fancy.
Lest go back to LegoLand.

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Name"]

Style[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Name"],Bold,14]

That will be the name of the park. For the city and country, they’re entities, so we need to make them names.

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["City"]

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["City"]["Name"]

Now, the country is in a list. To get it out, we can just ask for the first element in that list before we get the name.

(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Country"]

First[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Country"]]

First[(Entity["Legoland California", Entity["AmusementPark","LegolandCalifornia::Carlsbad::1999"], "Entity[\"AmusementPark\", \"LegolandCalifornia::Carlsbad::1999\"]", "amusement park"])["Country"]]["Name"]

Now that we have the components, lets put then in.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
Style[#["Name"],Bold,14],
#["City"]["Name"],
First[#["Country"]]["Name"]
}]
]&/@someparks,1,2]}]

It seems some of the parks don’t have cities, so lets delete the missing ones with the layered delete missing.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
Style[#["Name"],Bold,14],
DeleteMissing[{#["City"]["Name"]},1,2],
First[#["Country"]]["Name"]
}]
]&/@someparks,1,2]}]

Oh but now we have an empty list...
How about me make in if statement.
If our city, which we’ll define as the name, equals and empty list, then do nothing, but if not, then display it without the list.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
Style[#["Name"],Bold,14],
If[city=DeleteMissing[{#["City"]["Name"]},1,2];
city=={},Nothing,First[city]],
First[#["Country"]]["Name"]
}]
]&/@someparks,1,2]}]

This is really cool. Oh! What if we add an image!
Oh, but a lot of them don’t have images, so we’ll do the same if statement as the city.

GeoGraphics[{Red,PointSize[Large],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
Style[#["Name"],Bold,14],
If[city=DeleteMissing[{#["City"]["Name"]},1,2];
city=={},Nothing,First[city]],
First[#["Country"]]["Name"],
If[img=DeleteMissing[{#["Image"]},1,2];
img=={},Nothing,First[img]]
}]
]&/@someparks,1,2]}]

An now for the optional final step...
We want to do this for all the amusement parks.
First, make the points smaller. Say 0.006.
Then, replace someparks at the end with all parks.

GeoGraphics[{Red,PointSize[0.006],
DeleteMissing[Tooltip[Point[#["Position"]],
Column[{
Style[#["Name"],Bold,14],
If[city=DeleteMissing[{#["City"]["Name"]},1,2];
city=={},Nothing,First[city]],
First[#["Country"]]["Name"],
If[img=DeleteMissing[{#["Image"]},1,2];
img=={},Nothing,First[img]]
}]
]&/@allparks,1,2]}]

Something to note:
I left this evaluating for two hours on my 2017 mac book pro, and the computer just crashed. You have been warned.

Credits

This activity is based on “Playing with Amusement Parks” by Abby Brown in 2019.
www.abbymath.com

These notes were written for CT@TP: Computational Thinking at Torrey Pines Club January 2021.