Consider the following code that generates an entity association for the top ten most populous cities in WV:

Entity["AdministrativeDivision", {"WestVirginia", "UnitedStates"}],"City"],
"Population", "EntityAssociation"], 10]

With output:

enter image description here

Cumberland is near the border of WV but is in Maryland. The question I have is how to manually get the correct results in spite of the apparent bug?

  • $\begingroup$ What is the question about Wolfram Language programming? $\endgroup$
    – rhermans
    Commented Nov 16, 2022 at 17:38
  • 1
    $\begingroup$ Similar to this. $\endgroup$
    – Syed
    Commented Nov 16, 2022 at 17:42
  • $\begingroup$ As shown in the link provided by @Syed, use the option "FullyContained" -> True in GeoEntities $\endgroup$
    – Bob Hanlon
    Commented Nov 16, 2022 at 18:41

1 Answer 1


(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)


wva = Entity["AdministrativeDivision", {"WestVirginia", "UnitedStates"}];

list1 = TakeLargest[
  EntityValue[GeoEntities[wva, "City"], "Population", "EntityAssociation"], 

enter image description here

Excluding border cities that "spill into" WVA

list2 = Pick[
  list1, #[[1]]["AdministrativeDivision"] === wva & /@ (list1 // Normal)]

enter image description here

Using the option "FullyContained"->True excludes border cities that "spill into" WVA; however, it also excludes border cities that "spill out" of WVA

list3 = TakeLargest[
  EntityValue[GeoEntities[wva, "City", "FullyContained" -> True], 
   "Population", "EntityAssociation"], 10]

enter image description here

Items from list2 that are excluded from list3, i.e., "spilled out"

Complement[list2, list3]

enter image description here

Taking top ten from combined list2 and list3

list4 = Join[list2, list3][[;; 10]]

enter image description here

  • $\begingroup$ @ Bob Hanlon I tried "FullyContained"-> True and lost Wheeling, Huntington, and Weirton as you did. Your explanation of spilling into and out of WV was great. $\endgroup$
    – JEM
    Commented Nov 16, 2022 at 21:57

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