Geo search in Leopard Spotlight

Spotlight has been in Mac OS X for quite awhile now, but in general, I haven't found it very useful. However, when this tip came across at Mac OSX Hints on how to use operators for ranges in Spotlight metadata I got some ideas about doing geo-searches on my desktop machines.

To summarize, Spotlight is a system-wide metadata storage engine. Mac OS X provides a nominal vocabulary of metadata you can store, but you can also extend this to add your own metadata. Various applications like Yojimbo add metadata keys to store tags and other info with files. What's especially great is that by applications using Spotlight, it means you can tie into this underlying metadata without having to use the application itself.

Using simple command-line parameters, you can do search for words, or specific metadata such as file type:

  • mdfind -s "Hawaii"
  • mdfind -interpret "keyword kind:image"

Great, but what about the range queries and Geo search? One of the default metadata items stored are kMDItemLatitude and kMDItemLongitude. In fact, you can use mdimport -A to get a list and description of all available metadata items.

Spotlight Geo Search

You can then do geographic queries like: latitude:<20 longitude:>20 and get all files you've created (such as photos or documents) while in Hawaii. You can also do better bounding box searches. To play with this I wrote a small RubyCocoa app to do geographic queries and display the location on a map.

GeoSpotlight allows you to search without a box and add other Spotlight predicates to search by, say, keyword, title, city, time, etc. Check out the Query Expression Syntax for details on how to do this.

GeoSpotlight

This was a quick mock-up and I'll probably extend it to do bounding box specifying using the map interface and also locating documents via drag and drop.

About this article

written on
posted in Technology Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.