5
$\begingroup$

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]

enter image description here

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.

$\endgroup$
2
  • 1
    $\begingroup$ This bug is reproducible in 13.1 on Windows 10. $\endgroup$
    – user64494
    Oct 16, 2022 at 16:53
  • $\begingroup$ 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". $\endgroup$
    – user64494
    Oct 16, 2022 at 17:01

2 Answers 2

6
$\begingroup$

Notice how the Amritsar region touches the border to Pakistan:

GeoGraphics[{Red, EdgeForm[Blue], 
 Polygon[Entity["City", {"Amritsar", "Punjab", "India"}]]}, 
 PlotRangePadding -> Scaled[.25]
]

enter image description here

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]

enter image description here


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
$\endgroup$
3
  • $\begingroup$ Thanks @GregHurst. I learned something new. So it is not a bug? How do I know when to use this option? $\endgroup$
    – Syed
    Oct 17, 2022 at 12:50
  • $\begingroup$ 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"]. $\endgroup$
    – Greg Hurst
    Oct 17, 2022 at 12:55
  • 1
    $\begingroup$ 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. $\endgroup$
    – Greg Hurst
    Oct 17, 2022 at 12:57
2
$\begingroup$

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"]
$\endgroup$

Your Answer

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

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