UNPKG

terraformer

Version:

A Geo-toolkit built in Javascript.

210 lines (189 loc) 9.57 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> <title>Terraformer</title> <link href="/assets/css/terraformer-02847305.css" media="screen" rel="stylesheet" type="text/css" /> </head> <body class="geostore geostore_alternate-indexes geostore_alternate-indexes_index" id="wrap"> <nav> <ul> <li> <a href="/" class="">Terraformer</a> </li> <li> <a href="https://github.com/search?q=%40Esri+terraformer" class="">GitHub</a> </li> <li> <a href="/install" class="">Install</a> </li> <li> <a href="/" data-direction="active-top" class="toggle" id="close-drawer">Docs</a> </li> </ul> </nav> <div class="drawer" id="drawer"> <div class="doctoc drawer-nav drawer-top"> <div class="container"> <ul> <h3>Terraformer Documentation</h3> <li><a href="/getting-started/">Getting Started</a></li> <li><a href="/core/">Terraformer Core</a></li> <li class="indent"><a href="/core/#terraformerprimitive">Primitives</a></li> <li class="indent"><a href="/core/#terraformertools">Tools</a></li> <li><a href="/geostore/">GeoStores</a></li> <li class="indent"><a href="/geostore/data-stores/">DataStores</a></li> <li class="indent"><a href="/geostore/spatial-indexes/">Spatial Indexes</a></li> <li><a href="/arcgis-parser/">ArcGIS Parser</a></li> <li><a href="/wkt-parser/">WKT Parser</a></li> <li><a href="/glossary/">Glossary</a></li> </ul> </div> </div> </div> <main class="docs main-content" id="main-content"> <h1>GeoStore Alternate Indexes</h1> <p>Alternate Indexes are a very powerful way to apply additional filters to your searches on <code>properties</code> of a <code>Feature</code>.</p> <h2> <a id='using-alternate-indexes' class='section-link'></a> <a href='#using-alternate-indexes' class='header-link'>Link</a> Using Alternate Indexes <a href='#' class='back-to-top-link'>Back to Top</a> </h2> <p>Alternate Indexes can be added to an existing GeoStore very easily:</p> <pre class="highlight javascript"><code><span class="c1">// create an index on the properties.street value</span> <span class="nx">gs</span><span class="p">.</span><span class="nx">addIndex</span><span class="p">({</span> <span class="na">property</span><span class="p">:</span> <span class="s2">"street"</span><span class="p">,</span> <span class="na">index</span><span class="p">:</span> <span class="k">new</span> <span class="nx">BTree</span><span class="p">()</span> <span class="p">});</span> <span class="c1">// create an index on the properties.crime value</span> <span class="nx">gs</span><span class="p">.</span><span class="nx">addIndex</span><span class="p">({</span> <span class="na">property</span><span class="p">:</span> <span class="s2">"crime"</span><span class="p">,</span> <span class="na">index</span><span class="p">:</span> <span class="k">new</span> <span class="nx">BTree</span><span class="p">()</span> <span class="p">});</span> </code></pre> <p>Queries against Alternate Indexes are very specific to the index, but the basic syntax of a query is straightforward:</p> <pre class="highlight javascript"><code><span class="nx">gs</span><span class="p">.</span><span class="nx">within</span><span class="p">(</span> <span class="nx">geojson</span><span class="p">,</span> <span class="p">{</span> <span class="s2">"name"</span><span class="p">:</span> <span class="p">{</span> <span class="s2">"equals"</span><span class="p">:</span> <span class="s2">"Main"</span> <span class="p">},</span> <span class="s2">"crime"</span><span class="err">:</span> <span class="p">{</span> <span class="s2">"equals"</span><span class="err">:</span> <span class="s2">"Arson"</span> <span class="p">}</span> <span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// node.js style callback</span> <span class="p">}</span> <span class="p">);</span> </code></pre> <p>In this example, first every <code>Feature</code> that is within the GeoJSON is found in the Spatial Index, then each of those entries are searched for in the B-Tree indexes. Only those entries that have a <code>properties.street</code> of &ldquo;Main&rdquo; and a <code>properties.crime</code> of &ldquo;Arson&rdquo; are returned.</p> <h3> <a id='indexable-data' class='section-link'></a> <a href='#indexable-data' class='header-link'>Link</a> Indexable Data <a href='#' class='back-to-top-link'>Back to Top</a> </h3> <p>Only data that is available in <code>properties</code> is indexable. When a <code>Feature</code> is added to the GeoStore, the list of Alternate Indexes is scanned, and any property that is found is added to that Alternate Index.</p> <p>Alternate Indexes are asyncronous and use Node.js style callbacks.</p> <h3> <a id='existing-alternate-indexes' class='section-link'></a> <a href='#existing-alternate-indexes' class='header-link'>Link</a> Existing Alternate Indexes <a href='#' class='back-to-top-link'>Back to Top</a> </h3> <p>Terraformer currently ships with a single alternate index, with more coming soon.</p> <ul> <li><a href="https://github.com/JerrySievert/terraformer-geostore-index-btree">B-Tree</a> - A B-Tree index </li> </ul> <h2> <a id='writing-an-alternate-index' class='section-link'></a> <a href='#writing-an-alternate-index' class='header-link'>Link</a> Writing an Alternate Index <a href='#' class='back-to-top-link'>Back to Top</a> </h2> <p>Alternate Indexes rely on two methods to be exposed to the GeoStore to add and remove data. Additional methods can be added for querying and are introspected for searching.</p> <p>For instance, when a <code>equals</code> query is made against an Alternate Index, if the <code>equals</code> method is on the index, then it is called with all arguments from the <code>contains</code> or <code>within</code>.</p> <h3> <a id='indexadd' class='section-link'></a> <a href='#indexadd' class='header-link'>Link</a> Index.add(value, id, callback) <a href='#' class='back-to-top-link'>Back to Top</a> </h3> <p>Add a value to the Alternate Index by <code>id</code>.</p> <table><thead> <tr> <th>Option</th> <th>Value</th> <th>Description</th> </tr> </thead><tbody> <tr> <td>value</td> <td><code>String</code> <em>or</em> <code>Number</code></td> <td>The value to add to the index</td> </tr> <tr> <td>id</td> <td><code>String</code> <em>or</em> <code>Number</code></td> <td>The <code>id</code> of the <code>Feature</code> to be added</td> </tr> <tr> <td>callback</td> <td><code>function</code></td> <td>Callback to be fired when the <code>add</code> has been completed</td> </tr> </tbody></table> <p><em>Example:</em></p> <pre class="highlight javascript"><code><span class="nx">idx</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">id</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// Node.js style callback</span> <span class="p">});</span> </code></pre> <h3> <a id='indexremove' class='section-link'></a> <a href='#indexremove' class='header-link'>Link</a> Index.remove(value, id, callback) <a href='#' class='back-to-top-link'>Back to Top</a> </h3> <p>Add a value to the Alternate Index by <code>id</code>.</p> <table><thead> <tr> <th>Option</th> <th>Value</th> <th>Description</th> </tr> </thead><tbody> <tr> <td>value</td> <td><code>String</code> <em>or</em> <code>Number</code></td> <td>The value to remove from the index</td> </tr> <tr> <td>id</td> <td><code>String</code> <em>or</em> <code>Number</code></td> <td>The <code>id</code> of the <code>Feature</code> to be removed</td> </tr> <tr> <td>callback</td> <td><code>function</code></td> <td>Callback to be fired when the <code>remove</code> has been completed</td> </tr> </tbody></table> <p><em>Example:</em></p> <pre class="highlight javascript"><code><span class="nx">idx</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">id</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// Node.js style callback</span> <span class="p">});</span> </code></pre> </main> <footer> <p> Terraformer is an open source project from the <a href="http://pdx.esri.com/">Esri Portland R&amp;D Center</a> </p> </footer> <script src="/assets/javascripts/modernizr.custom-cadc78a2.js" type="text/javascript"></script> <script src="/assets/javascripts/classie-b6db1f70.js" type="text/javascript"></script> <script src="/assets/javascripts/drawer-3a1490eb.js" type="text/javascript"></script> </body> </html>