Class ShapeSpatialIndex

java.lang.Object
ca.spatial.table.ShapeSpatialIndex
All Implemented Interfaces:
SpatialIndex

public class ShapeSpatialIndex extends Object implements SpatialIndex
Encapsulate access to a shapefile spatial index. This class performs optimistic indexing. The set of records that are returned will include at least the selection. The records will be tested using a fast but approximate criteria, and some boundary records may be included. Routines that use this class should perform additional refinement on this list.
  • Constructor Details

    • ShapeSpatialIndex

      public ShapeSpatialIndex(ShapeStore grs, boolean universe)
      Create a spatial index from the features in an existing data set
      Parameters:
      grs - The reference to the spatial data set
      universe - Indicates if an additional universe polygon index record should be added. This is required for building indexes on polygon coverage data sets. It is never required for shapefiles.
    • ShapeSpatialIndex

      public ShapeSpatialIndex(String fileName, String indexName, Extent2D parentExtent) throws IOException
      Read an existing spatial index
      Parameters:
      fileName - The name of the file containing the spatial index records. For shapefiles this is the sbn file.
      indexName - The name of the file that indexes the spatial index records. For shapefiles this is the sbx file.
      Throws:
      IOException
  • Method Details

    • close

      public void close()
    • exportToShapefile

      public void exportToShapefile(String name) throws IOException
      Export the indexing structure to a shapefile. This is diagnostic aid to help troubleshoot problems with spatial index encoding and decoding.
      Parameters:
      name - The nameof the shapefile to create. The file will contain polygons for each indexed feature showing their coverage in the index.
      Throws:
      IOException - Will throw a IOException if there is trouble while creating the shapefile.
    • getExtent

      public Extent2D getExtent()
      The extent of the index. Note that this is the bounding box of all features in single precision floating point
      Specified by:
      getExtent in interface SpatialIndex
    • getDepth

      public int getDepth()
      The depth of partitions in this index
    • getRecordCount

      public int getRecordCount()
      Get the number of feature in this index
    • getSelection

      public BitSet getSelection(Extent2D e)
      Retrieve a spatial selection. The selection is fast and optimistic, including records that are likely to be in the selection. The returned set may include additional boudary records and so should be checked using a more refined test to see if the records actually match.

      This method is equivalent to

       getselection(e, 0);
       
      Specified by:
      getSelection in interface SpatialIndex
      Parameters:
      e - The rectangle that represents the spatial query
    • getSelection

      public BitSet getSelection(Extent2D e, int offset)
      Retrieve a spatial selection. The selection is fast and optimistic, including records that are likely to be in the selection. The returned set may include additional boudary records and so should be checked using a more refined test to see if the records actually match.
      Specified by:
      getSelection in interface SpatialIndex
      Parameters:
      e - The rectangle that represents the spatial query
      offset - This parameter indicates how records in the index relate to records in the data set. Most data sets have a one-to-one relationship and this parameter should be zero. Polygon coverages have a universe polygon which is ignored, so in this case specify an offset of 1.
    • dump

      public void dump(PrintStream out)
      Print the index to the output stream
      Specified by:
      dump in interface SpatialIndex
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • saveIndex

      public void saveIndex(String dataName, String indexName, int magic1, int magic2) throws Exception
      Save this index to permanent files. The index is saved in two parts:
      • The index data, containing the search tree
      • The index to the index, containing direct access record pointers.
      In addition the index must contain special magic numbers to identify the type of spatial index. Known index names and magic numbers are:
      Spatial file magic numbers
      Data set typeData nameIndex name Magic1Magic2
      Any shapefilefilename.sbn filename.sbx9994-400
      Point coveragecoverage/xbn.adf coverage/xbx.adf9994-46
      Line coveragecoverage/abn.adf coverage/abx.adf9994-47
      Polygon coveragecoverage/pbn.adf coverage/pbx.adf9994-48
      Parameters:
      dataName - The name of the file to store the index data in to
      indexName - The name of the file to store the direct access pointers in to.
      magic1 - The first magic number
      magic2 - The second magic number
      Throws:
      Exception