<story><title>Spatial Data Structures for Better Map Interactions</title><url>http://chairnerd.seatgeek.com/spatial-data-structures-for-better-map-interactions/</url></story><parent_chain></parent_chain><comment><author>ryandrake</author><text>Spatial data structures are great, and heavily used in all kinds of mapping applications. Most of the systems I&amp;#x27;ve worked with used the more constrained quadtree structure, where the map is divided into uniformly-sized tiles, and a level-of-detail hierarchy is built. This is good for raster data, where each tile is a picture and the whole world is covered by tiles. The R-tree has great advantages when the complexity is not uniformly distributed across the map, for example, vector road data, where vast areas on earth have no data, and most of the data is concentrated in small urban areas.&lt;p&gt;I believe PostGIS, which adds spatial operations to Postgres, uses an R-tree as its spatial index.&lt;p&gt;An improvement on the R-tree, the R(star)-tree, uses a different node splitting algorithm and includes re-insertions (similar to balancing a B-tree), reducing both coverage and overlap. The insertion complexity is greater, but in general, R(star)-tree query performance tends to be a bit better for mapping applications. Generally, maps don&amp;#x27;t change that often, so building the tree tends to happen far less often than querying it.&lt;p&gt;There are many more specialized spatial data structures available, for example, Kd-trees, which can be perfectly balanced and are useful for storing point data.&lt;p&gt;If you&amp;#x27;re really interested in this stuff, the holy bibles for spacial data structures (which I keep in a special place on my bookshelf) are a pair of books written by H. Samet: The Design and Analysis of Spatial Data Structures, and Applications of Spatial Data Structures: Computer Graphics, Image Processing, and GIS.&lt;p&gt;EDIT: Formatting, and apparently you can&amp;#x27;t write the asterisk character on HN&lt;p&gt;R-Tree paper (1984): &lt;a href=&quot;http://postgis.org/support/rtree.pdf&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;postgis.org&amp;#x2F;support&amp;#x2F;rtree.pdf&lt;/a&gt;&lt;p&gt;R(star)-Tree (1990): &lt;a href=&quot;http://epub.ub.uni-muenchen.de/4256/1/31.pdf&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;epub.ub.uni-muenchen.de&amp;#x2F;4256&amp;#x2F;1&amp;#x2F;31.pdf&lt;/a&gt;&lt;p&gt;PostGIS: &lt;a href=&quot;http://postgis.net&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;postgis.net&lt;/a&gt;&lt;p&gt;H.Samet textbooks: &lt;a href=&quot;http://www.cs.umd.edu/~hjs/design.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.cs.umd.edu&amp;#x2F;~hjs&amp;#x2F;design.html&lt;/a&gt;</text></comment>
<story><title>Spatial Data Structures for Better Map Interactions</title><url>http://chairnerd.seatgeek.com/spatial-data-structures-for-better-map-interactions/</url></story><parent_chain></parent_chain><comment><author>adam-a</author><text>The other way to do this, which is common in (older?) 3d video games, is to render your scene twice, once normally and once with each object shaded in a unique flat colour. Then sample your second bitmap at the mouse position and map the pixel value back to your list of objects. This is very fast and only falls over when you start to have transparent objects, in which case ray-casting and r-trees become appropriate.</text></comment>