I have the following codes:-

First@GeoNearest["AdministrativeDivision", GeoPosition[{38.6, -90.2}]]
First@GeoNearest["AdministrativeDivision", GeoPosition[{32.3, -106.8}]]


Entity["AdministrativeDivision", {"StLouisIndependentCity", "Missouri", "UnitedStates"}]
Entity["AdministrativeDivision", {"DonaAnaCounty", "NewMexico", "UnitedStates"}]

In fact, my desired output are the input-string StLouisIndependentCity and DonaAnaCounty. I tried to use Entity["AdministrativeDivision", {"StLouisIndependentCity", "Missouri", "UnitedStates"}]["Name"] (similar to Dona), but the output are the name-string St. Louis (independent city) and Doña Ana County, which are not what I want.

How can I get it done? Many thanks!


2 Answers 2


You can use any method that you would normally use to extract data from an expression. Consider that you had this expression:

{"AdministrativeDivision", {"StLouisIndependentCity", "Missouri", "UnitedStates"}}

How would you extract "StLouisIndependentCity" from this? Then do the same for your entity. Here are two suggestions:

entity = Entity["AdministrativeDivision", {"StLouisIndependentCity", "Missouri", "UnitedStates"}];


Another one:

getIdentifier[Entity["AdministrativeDivision", {id_, _, _}]] := id



You might want to look at the CanonicalName accessor.

entity = First@GeoNearest["AdministrativeDivision", GeoPosition[{38.6, -90.2}]]
(* Entity["AdministrativeDivision", {"StLouisIndependentCity", "Missouri", "UnitedStates"}] *)

(* {"StLouisIndependentCity", "Missouri", "UnitedStates"} *)

name[entity_Entity] :=
  Replace[CanonicalName[entity], {en_String, ___} :> en];
(* StLouisIndependentCity *)

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.