# List of large cities in Pakistan

Bug introduced in 12.2.0 or earlier and persisting through 13.1.0

I am using v12.2.0-Win7-x64.

I have been experimenting with Geo* command syntaxes and came across something that is an obvious bug. I have left a Tooltip in the image below. The city of Amritsar is in India.

cities = TakeLargestBy[
EntityValue[GeoEntities[Entity["Country", "Pakistan"], "City"],
"Population", "EntityAssociation"], Value @@@ # &, 20]


I would like to know if this is version dependent or if it can be replicated on other platforms/versions. Thanks for your help in advance.

• This bug is reproducible in 13.1 on Windows 10. Oct 16, 2022 at 16:53
• TakeLargestBy[ EntityValue[GeoEntities[Entity["Country", "Russia"], "City"], "Population", "EntityAssociation"], Value @@@ # &, 10] performs an error "GeoEntities::timeout: A network operation for GeoEntities timed out. Please try again later." The same issue with "Ukraine". Oct 16, 2022 at 17:01

Notice how the Amritsar region touches the border to Pakistan:

GeoGraphics[{Red, EdgeForm[Blue],
Polygon[Entity["City", {"Amritsar", "Punjab", "India"}]]},
]


For this reason I think we need to use the option "FullyContained" -> True in GeoEntities.

TakeLargest[
EntityValue[
GeoEntities[Entity["Country", "Pakistan"], "City", "FullyContained" -> True],
"Population", "EntityAssociation"], 20]


Notice similar behavior in GeoWithinQ:

GeoWithinQ[
Entity["Country", "Pakistan"],
Entity["City", {"Amritsar", "Punjab", "India"}]
]

True

GeoWithinQ[
Entity["Country", "Pakistan"],
Entity["City", {"Amritsar", "Punjab", "India"}],
"FullyContained" -> True
]

False

• Thanks @GregHurst. I learned something new. So it is not a bug? How do I know when to use this option?
– Syed
Oct 17, 2022 at 12:50
• I'm not sure if it's a bug or not... With the same logic since India touches Pakistan one might think it should be returned in this call, which it's not: GeoEntities[Entity["Country", "Pakistan"], "Country"]. Oct 17, 2022 at 12:55
• If I had to guess: this is probably a bug and the "FullyContained" option is mainly meant for features that can span multiple geographic regions, like lakes, rivers, etc. Oct 17, 2022 at 12:57

Seems to be an issue with GeoEntities. EntityClass does not have this issue and can be used as a workaround.

EntityValue[
EntityClass[
"City", {EntityProperty["City", "Country"] -> Entity["Country", "Pakistan"],
EntityProperty["City", "Population"] -> TakeLargest[20]}],
EntityProperty["City", "Population"], "EntityAssociation"]