title: Distance between 2 POINTs in Postgis in srid 4326 in metres
body: <p>This is probably a simple question, but I'm not very good at PostGIS and don't fully grok all of this.</p>
  
  <p>Basically I have a table (<code>nodes</code>) with a POINT column (<code>point</code>). I have created an index on this column </p>
  
  <pre><code>create index nodes__points on nodes using gist (point)
  </code></pre>
  
  <p>The column was created with </p>
  
  <pre><code>select addgeometrycolumn('nodes', 'points', 'POINT', 4326, 2)
  </code></pre>
  
  <p>I am using srid 4326 because I'm adding data that's in the form (latitude, longitude). (i.e. the co-ordinate system where the position of Dublin, Ireland is  lat=53.353 lon=-6.264 (which I've added with <code>GeomFromText('POINT(-6.264 53.535)')</code>)).</p>
  
  <p>For each point, I want to find all points that are roughly within a 1km box centred on that point (so <code>selcet a.id, count(*) from nodes as a, nodes as b where SOME_DISTANCE_FUNCTION_HERE(a.point, b.point, 1000) group by a.id;</code>. It doesn't have to be exact, just a rough hueristic figure. a 1km bbox is fine, a 1km circle is fine. It doesn't have to be exactly 1km, just that order of magnitude.</p>
  
  <p>The <code>ST_Distance</code>/<code>ST_DWithin</code>/etc. all use the units of the SRID, which for 4326/WGS64 is degrees (so 1 = 1 degree of lattitude/longitude). But I want to use metres. </p>
  
  <p>I tried <code>ST_distance_sphere</code> and <code>st_dwithin</code> which can use metres, but if I do that, the <code>explain</code> shows that the index isn't being used.</p>
  
  <p>How can I get roughly what I want, <em>and</em> use the geographical index?</p>
  
  <p><strong>UPDATE</strong>: This is on PostgreSQL 9.1 and PostGIS 2.0 svn build.</p>