3
$\begingroup$

In order to answer this question, first I define a region around the equator.

eq = GeoBoundsRegion[{{-3, 3}, {-180, 180}}]
GeoGraphics[eq]

enter image description here

Next, I wanted to find cities within this band but could not use GeoWithinQ directly. Instead, I used GeoNearest to find three cities that are in close proximity, every 10th longitude along the equator. This takes a good minute of waiting on my machine with every new restart.

cities03 = 
 Union@Flatten@(GeoNearest[Entity["City"], GeoPosition[{0, #}], 3] & /@
      Range[-180, 180, 10])

Now I could locate cities within the band shown above.

cities03Within = Pick[cities03, GeoWithinQ[eq, #] & /@ cities03]

The timing was twice as bad than for the last task but it worked in the end.


EDIT

cities03Within = Select[cities03, GeoWithinQ[eq]]

takes a second to complete. Why?


enter image description here

#["Population"] & /@ cities03Within
Total@%

Quantity[6070496, "People"]

Motivation

Out of the six million people, 2M+ live is in Manaus, Brazil. Other significant populations are in Indonesian cities. I would like to find out population stats for various latitude ranges. An important task, eventually, would be to find the available land area in a latitude band. There isn't that much land near the equator but that would be a different question, if I can't figure it out on my own.


Question

How do I improve this workflow, so that I can locate cities within a GeoBoundsRegion that are above a certain population threshold? Is the number I calculated close to reality or is there a problem with this calculation?

Thanks for your help in advance.

$\endgroup$

1 Answer 1

7
$\begingroup$

An easier way to find the equatorial cities is to use GeoEntities:

eqCities = GeoEntities[eq, "City"]

This takes about a minute on my machine, but it's cleaner and more comprehensive (1015 cities versus 111 cities). Also,

EntityValue[eqCities, "Population"] // Total

returns 69925103 people.

The answer to your question about the time to calculate cities03Within has to do with caching. The first time GeoWithinQ[eq] was evaluated, some entity information was cached, and so the second evaluation was much faster, because Mathematica didn't have to fetch the information.

Selecting for population could be done with (greater than a million in the following case):

Select[eqCities, 1000000 <= QuantityMagnitude[EntityValue[#, "Population"]] &]

Or you could find the largest n (10 in the following case):

MaximalBy[eqCities, EntityValue[#, "Population"] &, 10]

To your question about the accuracy of your method, I think every 10th longitude is a much too sparse search area. For example, your cities03 is missing Singapore, which has a population of over 5 million.

$\endgroup$
1
  • $\begingroup$ Thanks for the order of magnitude correction. It didn't seem right. I thought GeoEntities was for buildings and bridges etc and Entity was for cities and countries. $\endgroup$
    – Syed
    Commented Sep 27, 2022 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.