Playing with Amusement Parks

Where in the world are there amusement parks?

Getting Started

First let’s download all of the available Amusement Park entities and name this list something we can use later. (Reminder: If you don’t want to see the results, put a semicolon ; at the end of the line of code.)

allparks=EntityList["AmusementPark"]

You may notice that the entities are not completely in alphabetical order. For example, look at the sequence below. If you hover over each entity with your mouse, you can see in the tooltip the full form of the entity and how it is individually encoded. These names are how the list is ordered.

{(Entity["Islamic Heritage Park", Entity["AmusementPark","IslamicHeritagePark::KualaTerengganu"], "Entity[\"AmusementPark\", \"IslamicHeritagePark::KualaTerengganu\"]", "amusement park"]),(Entity["Universal's Islands of Adventure", Entity["AmusementPark","IslandsOfAdventure::Orlando::1999"], "Entity[\"AmusementPark\", \"IslandsOfAdventure::Orlando::1999\"]", "amusement park"]),(Entity["Istralandia", Entity["AmusementPark","Istralandia::6q7cj"], "Entity[\"AmusementPark\", \"Istralandia::6q7cj\"]", "amusement park"])}

InputForm or FullForm will also show this structure.

InputForm[(Entity["Universal's Islands of Adventure", Entity["AmusementPark","IslandsOfAdventure::Orlando::1999"], "Entity[\"AmusementPark\", \"IslandsOfAdventure::Orlando::1999\"]", "amusement park"])]

How many amusement parks are in the whole list?

Length[allparks]

Another way we could get that result, without downloading them all, is the following.

EntityValue["AmusementPark","EntityCount"]

That’s interesting. Why are the counts different? A question for another day . . .

What properties we can look up for a given amusement park?

EntityValue["AmusementPark","Properties"]

Recall that to retrieve a single entity you can try the Ctrl + = (Control and Equal together) input.

LinguisticAssistant

We can use a single entity to view properties. Consider the entity expression like a function such as f in f(x) and the properties as the argument x.

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

To look up a single property for a single entity, we can use this same structure. Where is Legoland California located?

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

GeoGraphics automatically extracts the position from the entity.

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

That image is centered on the location of Legoland California, but where exactly is it? Using the primitive Point around the location within GeoGraphics, we can draw a point at the specific location.

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

Do you see the dot? It’s in the middle. Let’s use directives to style the point to make it easier to see. Note the use of braces { } around the point now to include the Red and PointSize directives.

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

Multiple Parks

Now let’s plot the location of several parks at the same time. Rather than plotting all of them, let’s start with a smaller list and give this smaller list a new name.

parks=RandomSample[allparks,10]

We can replace Legoland California with this entire list of entities.

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

This may have worked for you without an error. Your RandomSample is likely different than mine. However, within my list of parks, at least one of them has missing data for the position.

Through[parks["Position"]]

Recall that Through is a way we can quickly apply multiple functions to the same argument.

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

Explicitly having the position for each entity within Point will help us fix the missing data issue. In the code below, I replaced “parks” with the Through expression.

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

This still produces an error and none of the points are plotted. Hovering over the map will show a tooltip that Missing[NotAvailable] is not an appropriate set of coordinates. We can use the function DeleteMissing to eliminate the missing data. We just won’t see that amusement park on our map.

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

Of course we cannot tell which points are for which amusement parks. We' ll get to that in a moment.

Where in the world are ALL of the amusement parks? Replace the name of the short list with the name of the whole list and change the point size value so the dots are not too big.

GeoGraphics[{Red,PointSize[0.006],Point[DeleteMissing[Through[allparks["Position"]]]]}]

Clearly some regions have higher concentrations of amusement parks than others. We can use GeoRange to zoom into certain areas of the map.

GeoGraphics[{Red,PointSize[0.006],Point[DeleteMissing[Through[allparks["Position"]]]]},GeoRange->LinguisticAssistant]

Try a continent. You may want to change the point size as well.

GeoGraphics[{Red,PointSize[Medium],Point[DeleteMissing[Through[allparks["Position"]]]]},GeoRange->LinguisticAssistant]

Regions can also be states.

GeoGraphics[{Red,PointSize[Medium],Point[DeleteMissing[Through[allparks["Position"]]]]},GeoRange->LinguisticAssistant]

Or a city. (I increased the point size again here too.)

GeoGraphics[{Red,PointSize[Large],Point[DeleteMissing[Through[allparks["Position"]]]]},GeoRange->LinguisticAssistant]

To see Southern California, I listed San Diego and Los Angeles.

GeoGraphics[{Red,PointSize[Large],Point[DeleteMissing[Through[allparks["Position"]]]]},GeoRange->LinguisticAssistant]

Labeling

How can we identify amusement parks within the map? Let’s go back to the shorter list for this task.

parks

One way to do this is to use GeoListPlot with GeoLabels instead of GeoGraphics.

GeoListPlot[parks,GeoLabels->True]

However, this does not work so well when parks are close together. We have more control with GeoGraphics. Below is a copy of what we did earlier to map our short list of parks.

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

We will create labels using Tooltip. However, in order to use Tooltip, we need a list of points (rather than Point of a list of coordinates). Below is what we are currently using.

Point[DeleteMissing[Through[parks["Position"]]]]

Recall that # and & can be used to define a pure function that we can map (using the /@ shortcut) across a list.

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

We will use this structure to create a Point for each GeoPosition. (Note that we could have mapped Point across the result of Through. However as we add on the Tooltip and build that up, it will be more logical to have the pure function structure below.)

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

Tooltip has as its first argument what will be evaluated for regular display. The second argument is what will be inside the tooltip when the mouse is hovered over the output.

Tooltip[a,b]

For each point generated, we will have a tooltip. Put Tooltip around Point and make it part of the pure function that is mapped across parks. For the second argument of Tooltip we will use the name of the amusement park.

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

That output may look the same as above, but if you use your mouse to hover over each point, you will see the tooltip with the name of the amusement park. Now we need to deal with the DeleteMissing again. (Your data may not have this issue depending on your randomly selected parks, but if you want your code to be more adaptable, you should include it now too.)

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

That didn’t work. DeleteMissing has additional arguments that look for Missing within deeper levels of the list. For our purposes DeleteMissing[ . . . , 1, 2] will work for us. (See the Wolfram Documentation about DeleteMissing for more details.)

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

We can incorporate this directly into GeoGraphics where we had the original Point function. Copy/paste the GeoGraphics from earlier, then copy the DeleteMissing code above and paste it on top of the Point function within GeoGraphics. Compare the two below. Evaluate the second one and hover over the points to see the tooltips.

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

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

Let’s create more detailed tooltip labels. First, we’ll add some line returns in the code to organize it a little better. The code below is the same as above.

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

Fancier Labels

Rather than just having the name, we will make a column that includes the name, city, and country of each amusement park.

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

That worked, but we can make it look better. First, let’s replace the entity results with text of their names. For a city we can just ask for its name like below.

(Entity["San Diego", Entity["City",{"SanDiego","California","UnitedStates"}], "Entity[\"City\", {\"SanDiego\", \"California\", \"UnitedStates\"}]", "city"])["Name"]

However, the results for country are a little more complicated since the answers are in a list. (This is because some amusement parks apparently are in two countries.) For country we can pull out the first element in the list and then ask for its name as below.

First[{(Entity["United States", Entity["Country","UnitedStates"], "Entity[\"Country\", \"UnitedStates\"]", "country"])}]["Name"]

And to make it look a little nicer, we will style the name of the amusement park with a larger font and bold.

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

We can incorporate each of these changes as below.

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

For some of them the city is missing. We can use DeleteMissing[ . . . , 1, 2] around the city part, but the city part needs to be inside a list { } for it to work.

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

The missing cities are now replaced with an empty list { }. With a little more work we can eliminate that. I’ve added an If statement. For each city generated, it checks DeleteMissing. We will name this value “city” and the If checks whether city equals an empty list. (Note that assigning the variable name is a single = sign and the checking of whether city is an empty list is a double == sign.) If city is an empty list, then Nothing is displayed. Otherwise, show the first part of city (by using First to get rid of the braces around it).

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

Many of the amusement parks have images that can be retrieved.

LinguisticAssistant["Image"]

We can insert images into our tooltip as well. However, several are missing, so we need to do the same thing that we did for city. I recommend copying the If statement and then inserting it after the country part within the column. Then change “City” to “Image” and delete the [“Name”] after it. Change the variable “city” to “img” in three places. Don’t forget the comma after the country part. (Note that this may take a while to evaluate as it downloads the images.)

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

We can now use our code for a new set of amusement parks. This will take a little time to download the new values when generating the map.

parks=RandomSample[allparks,10]

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

Southern California Amusement Parks

My daughter peeked over my shoulder and asked what I was doing and why there was a picture of Legoland on my computer. I gave her a brief explanation and she then asked, “Are there any theme parks we haven’t been to that we can drive to?” Can we make a map of just Southern California Amusement parks?

There are entities for administrative divisions and amusement parks list them as a property.

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

Using Select and MemberQ we can check the entire list of parks for any that contain an administrative division of California. Make this the new value of parks. (This may take a while to evaluate.)

parks=
Select[allparks,MemberQ[#["AdministrativeDivision"],Entity["AdministrativeDivision","California"]]&]

The same code we have above for GeoGraphics works with this list.

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

Now we can use GeoRange to specify the region to be shown. (Note that “South California” directly gives the geographical region desired.)

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

Volcanos

Amusement parks and volcanos are not necessarily things one considers at the same time, unless perhaps when planning a trip to Hawaii. I mention volcanos here because we can easily adapt our code to map volcanos with nice tooltip labeling.

allvolcanos=EntityList["Volcano"]

Since the list is quite long we see the box with the middle of the output hidden. How many volcanos are in the data?

Length[allvolcanos]

Let’s work with a subset of this list.

volcanos=RandomSample[allvolcanos,20]

Copy the GeoGraphics code from above. We need to make just a few changes.
1) Change “parks” at the end to “volcanos.”
2) Delete GeoRange if you included that from earlier.
3) Delete the whole If statement for “City” (and don’t forget to delete the comma).
4) Change “Country” to “Countries.” (Keep in mind that if you keep First it will only show the first country in any list containing more than one. Additional work could be done to nicely display all countries in a list with more than one.)

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

A quick way to see all volcanos is to use GeoListPlot.

GeoListPlot[allvolcanos]

GeoListPlot also uses GeoRange as an option.

GeoListPlot[allvolcanos,GeoRange->LinguisticAssistant]

However, if you want to edit it some more, use GeoGraphics. (I recommend avoiding the tooltip for this.)

GeoGraphics[{Red,PointSize[0.006],Point[DeleteMissing[Through[allvolcanos["Position"]]]]}]

Add a little pizzazz with a GeoBackground.

GeoGraphics[{Red,PointSize[0.004],Point[DeleteMissing[Through[allvolcanos["Position"]]]]},GeoBackground->"ReliefMap",ImageSize->Large]

Continued in Part II: Entity Exploration

See “Entity Exploration: More Playing with Amusement Parks” for some additional examples of using information contained within entities.

Addendum: My “parks” List

This is the list of amusement parks I used for “parks” and I wanted to save it for reference.

parks={(Entity["Rapids Water Park", Entity["AmusementPark","RapidsWaterPark::WestPalmBeach::1979"], "Entity[\"AmusementPark\", \"RapidsWaterPark::WestPalmBeach::1979\"]", "amusement park"]),(Entity["Wonder World", Entity["AmusementPark","WonderWorld::SanMarcos"], "Entity[\"AmusementPark\", \"WonderWorld::SanMarcos\"]", "amusement park"]),(Entity["Mangyongdae Funfair", Entity["AmusementPark","Mangyongdae::Pyongyang::1982"], "Entity[\"AmusementPark\", \"Mangyongdae::Pyongyang::1982\"]", "amusement park"]),(Entity["Walt Disney Studios Park", Entity["AmusementPark","WaltDisneyStudiosPark::SeineEtMarne::2002"], "Entity[\"AmusementPark\", \"WaltDisneyStudiosPark::SeineEtMarne::2002\"]", "amusement park"]),(Entity["Ontario Place", Entity["AmusementPark","OntarioPlace::Ontario::1971"], "Entity[\"AmusementPark\", \"OntarioPlace::Ontario::1971\"]", "amusement park"]),(Entity["South Florida Fair", Entity["AmusementPark","SouthFloridaFair::595j8"], "Entity[\"AmusementPark\", \"SouthFloridaFair::595j8\"]", "amusement park"]),(Entity["Gilroy Gardens", Entity["AmusementPark","GilroyGardens::Gilroy::2001"], "Entity[\"AmusementPark\", \"GilroyGardens::Gilroy::2001\"]", "amusement park"]),(Entity["Dam Sen Cultural Park", Entity["AmusementPark","DamSenCulturalPark::HoChiMinhCity"], "Entity[\"AmusementPark\", \"DamSenCulturalPark::HoChiMinhCity\"]", "amusement park"]),(Entity["Legoland Florida", Entity["AmusementPark","LegolandFlorida::CypressGardens::2011"], "Entity[\"AmusementPark\", \"LegolandFlorida::CypressGardens::2011\"]", "amusement park"]),(Entity["Blackpool Pleasure Beach", Entity["AmusementPark","PleasureBeachBlackpool::Lancashire::1896"], "Entity[\"AmusementPark\", \"PleasureBeachBlackpool::Lancashire::1896\"]", "amusement park"])};

Abby Brown
CT@TP: Computational Thinking at Torrey Pines High School
www.abbymath.com/CT
San Diego, CA
February 2019