5

I have an entity city. For example, I run {city} = GeoNearest["City", GeoPosition[{41.8, -87.7}]] and then I got The entity "Chicago" as my output of city.

I want to have the string "Chicago" instead entity "Chicago" as output.

How can I convert city from entity to string?

Many thanks!

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
H42
  • 3,469
  • 7
  • 17

2 Answers2

7

Every Entity should have a "Name" property that returns a string,

enter image description here

If you have city defined as an entity, these three give the same result

city @ "Name"
EntityValue[city, "Name"]
EntityProperty["City", "Name"] @ city
Jason B.
  • 68,381
  • 3
  • 139
  • 286
  • Keeping in mind that GeoNearest returns a list, if you want to define your variable in one line, you can use this: city=First[GeoNearest["City", GeoPosition[{41.8, -87.7}]]]["Name"] – kickert Jul 02 '18 at 16:01
3

You can also use the functions CanonicalName, which gives the InputForm of the city's name, and CommonName, which gives the following. an example of the application of CanonicalName and CommonName on a sample geographic entity

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Peter Burbery
  • 1,695
  • 4
  • 15