Message Boards Message Boards

1
|
9467 Views
|
4 Replies
|
6 Total Likes
View groups...
Share
Share this post:

How do I remove certain results from CityData[{Large, "city"}]

Posted 13 years ago
Following plots the population for cities above 100,000 residents. 

Graphics[{Gray, CountryData["USA", "Polygon"], Opacity[0.5, Blue],
  Tooltip[Disk[Reverse[CityData[#, "Coordinates"]],
      CityData[#, "Population"]/10.^6], {CityData[#, "Name"],
      CityData[#, "Population"]}] & /@ CityData[{Large, "USA"}]},
ImageSize -> 900]


How can I remove certain cities from the result? 
(trying to delete the data from Anchorage and Honolulu, pointed by the two arrows in the above picture) 

Also, is there a way to change the threshold for the CityData[{Large,"USA"}]? The option "Large" is set to 100,000.

Thank you in advance!
POSTED BY: Jeremy Lee
4 Replies
{Large, country} syntax used by CityData has a fixed threashold of 100,000 people. Also, notice that
CountryData["USA", "LargestCities"]
is fixed at the top 100 cities by population.

To use your own population threshold, apply a filter to the list of fully quilified city names. Then use that new list for pulling up all the other properties. This particular approch is not the only way and it is not paritcularly fancy, but it does the job in stages, so we can see what is going on.
usCities = CityData[{All, "UnitedStates"}];
allUSPop = CityData[#, "Population"] & /@ usCities;
togehter = Transpose@{usCities, allUSPop};
threshold = 200000;
filterPop = Select[togehter, (#[[2]] >= threshold &)];
filterUSCities = filterPop[[All, 1]];

Either of these approches can be combined with the "Alaska" | "Hawaii" exclusion list given by Brett, directly in your existing code,
DeleteCases[CountryData["USA", "LargestCities"], {_, "Alaska" | "Hawaii", _}]
DeleteCases[filterUSCities, {_, "Alaska" | "Hawaii", _}]
I have two approaches:

The first (and I think best) is to replace 
CityData[{Large, "USA"}]
with 
DeleteCases[CityData[{Large, "USA"}], {_, "Alaska" | "Hawaii", _}]
to ignore cities in Alaska and Hawaii.

The second is to give a specific plot range to the graphic, such as:
PlotRange -> {{-127, -65}, {23, 51}}
that will roughly encompass the continental United States (plus the size of the disks.)
POSTED BY: Brett Champion
Posted 13 years ago
I realized I have not thanked you for the solution(s)!!

Thank you so much! emoticon
POSTED BY: Jeremy Lee
Posted 13 years ago
merely clicking the entity to delete and pressing the delete button is a one-time workaround.  XD

But I'm looking for a solution that I could include in the code.

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

Group Abstract Group Abstract