# Random Cities with a Non-Missing Property

Posted 1 year ago
2303 Views
|
2 Replies
|
3 Total Likes
|
 I would like to fetch four random city entities from the curated database that have a value in a specified property (not Missing[]). The end result would look something like this if I used the property "Area": {{"Los Angeles", Quantity[468.6701619038, ("Miles")^2]},{"Miami", Quantity[35.871043820, ("Miles")^2]},{"Twin Falls", Quantity[18.103053374, ("Miles")^2]},{"Canton", Quantity[25.462368239, ("Miles")^2]}} So far everything I've tried has been too slow to be useful, on the order of 20 minutes per query. I admit though that I don't understand EntityClass, EntityFunction, etc. very well. The problem seems to be in the large size of the database that contains the "city" entities and the relatively few entities that have values for most of the properties. Usable times for my purpose would be less than 15 seconds or so.Any help would be appreciated.Mark
2 Replies
Sort By:
Posted 1 year ago
 How about this? RandomEntity[ EntityClass["City", "Area" -> Quantity[Interval[{0, Infinity}], "Miles"*"Miles"]], 4] // EntityValue[#, {"Area"}, "EntityAssociation"] & //AbsoluteTiming (* {1.70067, <|Entity["City", {"Westminster", "Colorado", "UnitedStates"}] -> {Quantity[31.550416264, ("Miles")^2]}, Entity["City", {"Belvue", "Kansas", "UnitedStates"}] -> {Quantity[0.115757288, ("Miles")^2]}, Entity["City", {"Lewisville", "Indiana", "UnitedStates"}] -> {Quantity[0.253491511, ("Miles")^2]}, Entity["City", {"Lehighton", "Pennsylvania", "UnitedStates"}] -> {Quantity[1.623076949,("Miles")^2]}|>} *)