Group Abstract Group Abstract

Message Boards Message Boards

Why does GeoDistance not work on custom entities?

6 Replies

If anyone is interested, I learned that there are debugging capabilities in the Wolfram language, but that led me into a rabbit hole I'm not sure how to escape from.

I thought a simple

Trace[GeoDistance[c1, c2]]

could show me where exactly the problem is, but it generated a trace larger than 10 MB where I can see internal GeoNearest lookups, caching, a lot of https request to dozens of wolfram backends, encoding of url characters, compresssing, client and server session information, URLs to JSP backends, etc...

I think I'll let it go for now... ;)

Position is defined:

store = EntityStore["USCounty" -> <|
     "Entities" -> countyEntities,
     "Properties" -> <|
       "ParentEntity" -> <|
         "Label" -> "Parent entity"
         |>,
       "FIPSCode" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["FIPSCode"] &),
         "Label" -> "County FIPS code"
         |>,
       "Polygon" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["Polygon"] &),
         "Label" -> "Polygon"
         |>,
       "Position" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["Position"] &),
         "Label" -> "Position"
         |>,
       "Latitude" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["Latitude"] &),
         "Label" -> "Latitude"
         |>,
       "Longitude" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["Longitude"] &),
         "Label" -> "Longitude"
         |>,
       "HasPolygon" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["HasPolygon"] &),
         "Label" -> "Has polygon?"
         |>,
       "Name" -> <|
         "DefaultFunction" -> (#["ParentEntity"]["Name"] &),
         "Label" -> "Name"
         |>
       |>,
     "EntityClasses" -> <|
       "Alaska" -> <|
         "Entities" -> ("ParentEntity" -> (MatchQ[#, 
               Entity[_, {_, "Alaska", _}]] &)),
         "Label" -> Style["Alaska", Bold]
         |>,
       "Hawaii" -> <|
         "Entities" -> ("ParentEntity" -> (MatchQ[#, Entity[_, {_, "Hawaii", _}]] &)),
         "Label" -> Style["Hawaii", Bold]
         |>,
       "Mainland" -> <|
         "Entities" -> ("ParentEntity" -> (MatchQ[#, Entity[_, {_, Except["Alaska" | "Hawaii"], _}]] &)),
         "Label" -> Style["Mainland", Bold]|>
       |>
     |>];

I'm still a learner in this Wolfram thing, but I have a background in object-oriented programming, so I'm always thinking in "interfaces" that needs to be implemented. And that is what I currently don't understand with the Wolfram knowledge framework. Why is the "interface" to do all the geo-stuff not described? Some functions obviously need "Position" (e.g. GeoGraphics), but others need more. But what is this "more"? Or is this not the idea of the framework that everyone can build own EntityStores which gives back entities that can be used together with the existing functions and other Entities?

Christoph: I can confirm Rohit suggested try.

enter image description here

Follow instruction from linked post on custom entities.

c1=RandomEntity["USCounty"]
c2=RandomEntity["USCounty"]
GeoGraphics[GeoMarker[{c1,c2}]]

enter image description here

GeoDistance[c1, c2]

Yields same error enter image description here

But

GeoDistance[c1["Position"], c2["Position"]]

Yields (* Quantity[270.758081689567, "Miles"] *)

POSTED BY: Hans Michel
Posted 3 years ago

Sorry, I missed the use of a custom EntityStore. The error you got suggests that position information is not available for those counties in the custom store. Try evaluating c1["Position"].

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Christoph,

Not sure how you got the GeoGraphics to work because "USCounty" is not a valid type specification for RandomEntity.

c1 = RandomEntity["USCounty"]
(* RandomEntity::ntype: USCounty is not a valid type of Entity or EntityClass. *)

This works

c1 = RandomEntity[EntityClass["AdministrativeDivision", "USCountiesAllCounties"]]
c2 = RandomEntity[EntityClass["AdministrativeDivision", "USCountiesAllCounties"]]
GeoGraphics[GeoMarker[{c1, c2}]]

However, this fails, seems like a bug to me

GeoDistance[c1, c2]

Workaround

GeoDistance[c1["Position"], c2["Position"]]

I am running "13.1.0 for Mac OS X ARM (64-bit) (June 16, 2022)"

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard