public ESRIRecord[] locateRecords(double xmin,double ymin,double xmax,double ymax) throws IOException, FormatException {
  boolean gatherBounds=false;
  if (bounds == null) {
    bounds=new ESRIBoundingBox();
    gatherBounds=true;
  }
  if (logger.isLoggable(Level.FINE)) {
    logger.fine("locateRecords:\n\txmin: " + xmin + "; ymin: "+ ymin+ "\n\txmax: "+ xmax+ "; ymax: "+ ymax);
  }
  byte ixRecord[]=new byte[SPATIAL_INDEX_RECORD_LENGTH];
  int recNum=0;
  Vector<ESRIRecord> v=new Vector<ESRIRecord>();
  int sRecordSize=DEFAULT_SHAPE_RECORD_SIZE;
  byte sRecord[]=new byte[sRecordSize];
  if (shpFileName == null) {
    return null;
  }
  BinaryBufferedFile ssx=new BinaryBufferedFile(ssx(shpFileName));
  if (shp == null) {
    shp=getShpFile(shpFileName);
  }
  ssx.seek(32);
  ssx.byteOrder(false);
  int shapeType=ssx.readInteger();
  ssx.seek(100);
  while (true) {
    int result=ssx.read(ixRecord,0,SPATIAL_INDEX_RECORD_LENGTH);
    if (result <= 0) {
      break;
    }
 else {
      recNum++;
      double xmin2=readLEDouble(ixRecord,8);
      double ymin2=readLEDouble(ixRecord,16);
      double xmax2=readLEDouble(ixRecord,24);
      double ymax2=readLEDouble(ixRecord,32);
      if (logger.isLoggable(Level.FINER)) {
        logger.finer("Looking at rec num " + recNum);
        logger.finer("  " + xmin2 + ", "+ ymin2+ "\n  "+ xmax2+ ", "+ ymax2);
      }
      if (gatherBounds) {
        bounds.addPoint(xmin2,ymin2);
        bounds.addPoint(xmax2,ymax2);
      }
      if (intersects(xmin,ymin,xmax,ymax,xmin2,ymin2,xmax2,ymax2)) {
        int offset=readBEInt(ixRecord,0);
        int byteOffset=offset * 2;
        int contentLength=readBEInt(ixRecord,4);
        int recordSize=(contentLength * 2) + 8;
        if (recordSize < 0) {
          logger.warning("SpatialIndex: supposed to read record size of " + recordSize);
          break;
        }
        if (recordSize > sRecordSize) {
          sRecordSize=recordSize;
          if (logger.isLoggable(Level.FINER)) {
            logger.finer("Shapefile SpatialIndex record size: " + sRecordSize);
          }
          sRecord=new byte[sRecordSize];
        }
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("going to shp byteOffset = " + byteOffset + " for record size = "+ recordSize+ ", offset = "+ offset+ ", shape type = "+ shapeType);
        }
        try {
          shp.seek(byteOffset);
          int nBytes=shp.read(sRecord,0,recordSize);
          if (nBytes < recordSize) {
            logger.warning("Shapefile SpatialIndex expected " + recordSize + " bytes, but got "+ nBytes+ " bytes instead.");
          }
          ESRIRecord record=makeESRIRecord(shapeType,sRecord,0);
          v.addElement(record);
        }
 catch (        IOException ioe) {
          logger.warning("SpatialIndex.locateRecords: IOException. ");
          ioe.printStackTrace();
          break;
        }
      }
    }
  }
  if (logger.isLoggable(Level.FINE)) {
    logger.fine("Processed " + recNum + " records");
    logger.fine("Selected " + v.size() + " records");
  }
  int nRecords=v.size();
  ssx.close();
  shp.close();
  shp=null;
  ESRIRecord result[]=new ESRIRecord[nRecords];
  v.copyInto(result);
  return result;
}

public ESRIRecord [ ] locateRecords ( double xmin , double ymin , double xmax , double ymax ) throws IOException , FormatException { boolean gatherBounds = false ; if ( bounds == null ) { bounds = new ESRIBoundingBox ( ) ; gatherBounds = true ; } if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "locateRecords:\n\txmin: " + xmin + "; ymin: " + ymin + "\n\txmax: " + xmax + "; ymax: " + ymax ) ; } byte ixRecord [ ] = new byte [ SPATIAL_INDEX_RECORD_LENGTH ] ; int recNum = 0 ; Vector < ESRIRecord > v = new Vector < ESRIRecord > ( ) ; int sRecordSize = DEFAULT_SHAPE_RECORD_SIZE ; byte sRecord [ ] = new byte [ sRecordSize ] ; if ( shpFileName == null ) { return null ; } BinaryBufferedFile ssx = new BinaryBufferedFile ( ssx ( shpFileName ) ) ; if ( shp == null ) { shp = getShpFile ( shpFileName ) ; } ssx . seek ( 32 ) ; ssx . byteOrder ( false ) ; int shapeType = ssx . readInteger ( ) ; ssx . seek ( 100 ) ; while ( true ) { int result = ssx . read ( ixRecord , 0 , SPATIAL_INDEX_RECORD_LENGTH ) ; if ( result <= 0 ) { break ; } else { recNum ++ ; double xmin2 = readLEDouble ( ixRecord , 8 ) ; double ymin2 = readLEDouble ( ixRecord , 16 ) ; double xmax2 = readLEDouble ( ixRecord , 24 ) ; double ymax2 = readLEDouble ( ixRecord , 32 ) ; if ( logger . isLoggable ( Level . FINER ) ) { logger . finer ( "Looking at rec num " + recNum ) ; logger . finer ( "  " + xmin2 + ", " + ymin2 + "\n  " + xmax2 + ", " + ymax2 ) ; } if ( gatherBounds ) { bounds . addPoint ( xmin2 , ymin2 ) ; bounds . addPoint ( xmax2 , ymax2 ) ; } if ( intersects ( xmin , ymin , xmax , ymax , xmin2 , ymin2 , xmax2 , ymax2 ) ) { int offset = readBEInt ( ixRecord , 0 ) ; int byteOffset = offset * 2 ; int contentLength = readBEInt ( ixRecord , 4 ) ; int recordSize = ( contentLength * 2 ) + 8 ; if ( recordSize < 0 ) { logger . warning ( "SpatialIndex: supposed to read record size of " + recordSize ) ; break ; } if ( recordSize > sRecordSize ) { sRecordSize = recordSize ; if ( logger . isLoggable ( Level . FINER ) ) { logger . finer ( "Shapefile SpatialIndex record size: " + sRecordSize ) ; } sRecord = new byte [ sRecordSize ] ; } if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "going to shp byteOffset = " + byteOffset + " for record size = " + recordSize + ", offset = " + offset + ", shape type = " + shapeType ) ; } try { shp . seek ( byteOffset ) ; int nBytes = shp . read ( sRecord , 0 , recordSize ) ; if ( nBytes < recordSize ) { logger . warning ( "Shapefile SpatialIndex expected " + recordSize + " bytes, but got " + nBytes + " bytes instead." ) ; } ESRIRecord record = makeESRIRecord ( shapeType , sRecord , 0 ) ; v . addElement ( record ) ; } catch ( IOException ioe ) { logger . warning ( "SpatialIndex.locateRecords: IOException. " ) ; ioe . printStackTrace ( ) ; break ; } } } } if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Processed " + recNum + " records" ) ; logger . fine ( "Selected " + v . size ( ) + " records" ) ; } int nRecords = v . size ( ) ; ssx . close ( ) ; shp . close ( ) ; shp = null ; ESRIRecord result [ ] = new ESRIRecord [ nRecords ] ; v . copyInto ( result ) ; return result ; }
locates records in the shape file that intersect with the given rectangle . the spatial index is searched for intersections and the appropriate records are read from the shape file . not really used anymore , except for old code . use esrigraphiclist or esrigraphicfactory instead .
