/** * Sets the current location of the byteStream to offset and returns the next record. Usually * used in conjuctions with the shx file or some other index file. Mind that: * * <ul> * <li>it's your responsibility to ensure the offset corresponds to the actual beginning of a * shape struct * <li>once you call this, reading with hasNext/next on sparse shapefiles will be broken (we * don't know anymore at which shape we are) * </ul> * * @param offset If using an shx file the offset would be: 2 * (index.getOffset(i)) * @return The record after the offset location in the bytestream * @throws IOException thrown in a read error occurs * @throws UnsupportedOperationException thrown if not a random access file */ public Record recordAt(int offset) throws IOException, UnsupportedOperationException { if (randomAccessEnabled) { this.goTo(offset); return nextRecord(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * Parses the shpfile counting the records. * * @return the number of non-null records in the shapefile */ public int getCount(int count) throws DataSourceException { try { if (channel == null) return -1; count = 0; long offset = this.currentOffset; try { goTo(100); } catch (UnsupportedOperationException e) { return -1; } while (hasNext()) { count++; nextRecord(); } goTo((int) offset); } catch (IOException ioe) { count = -1; // What now? This seems arbitrarily appropriate ! throw new DataSourceException("Problem reading shapefile record", ioe); } return count; }
/** * Returns the shape at the specified byte distance from the beginning of the file. Mind that: * * <ul> * <li>it's your responsibility to ensure the offset corresponds to the actual beginning of a * shape struct * <li>once you call this, reading with hasNext/next on sparse shapefiles will be broken (we * don't know anymore at which shape we are) * </ul> * * @param offset * @throws IOException * @throws UnsupportedOperationException */ public Object shapeAt(int offset) throws IOException, UnsupportedOperationException { disableShxUsage(); if (randomAccessEnabled) { this.goTo(offset); return nextRecord().shape(); } throw new UnsupportedOperationException("Random Access not enabled"); }
public boolean hasNext() throws IOException { while (nextFeature == null && this.goodRecs.hasNext()) { next = goodRecs.next(); Long l = (Long) next.getValue(1); shp.goTo((int) l.longValue()); Record record = shp.nextRecord(); // read the geometry, so that we can decide if this row is to be skipped or not Geometry geometry = getGeometry(record); if (geometry == SKIP) { continue; } // read the dbf only if the geometry was not skipped Row row; if (dbf != null) { ((IndexedDbaseFileReader) dbf).goTo(record.number); row = dbf.readRow(); } else { row = null; } nextFeature = buildFeature(record.number, geometry, row, record.envelope()); } return nextFeature != null; } }
/** * Sets the current location of the byteStream to offset and returns the * next record. Usually used in conjuctions with the shx file or some other * index file. * * @param offset * If using an shx file the offset would be: 2 * * (index.getOffset(i)) * @return The record after the offset location in the bytestream * @throws IOException * thrown in a read error occurs * @throws UnsupportedOperationException * thrown if not a random access file */ public Record recordAt(int offset) throws IOException, UnsupportedOperationException { if (randomAccessEnabled) { this.goTo(offset); return nextRecord(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * Sets the current location of the byteStream to offset and returns the * next record. Usually used in conjuctions with the shx file or some other * index file. Mind that: * <ul> * <li>it's your responsibility to ensure the offset corresponds to the * actual beginning of a shape struct</li> * <li>once you call this, reading with hasNext/next on sparse shapefiles * will be broken (we don't know anymore at which shape we are)</li> * </ul> * * * * @param offset * If using an shx file the offset would be: 2 * * (index.getOffset(i)) * @return The record after the offset location in the bytestream * @throws IOException * thrown in a read error occurs * @throws UnsupportedOperationException * thrown if not a random access file */ public Record recordAt(int offset) throws IOException, UnsupportedOperationException { if (randomAccessEnabled) { this.goTo(offset); return nextRecord(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * TODO needs better java docs!!! What is offset? * * @param offset * @throws IOException * @throws UnsupportedOperationException */ public Object shapeAt(int offset) throws IOException, UnsupportedOperationException { if (randomAccessEnabled) { this.goTo(offset); return nextRecord().shape(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * Sets the current location of the byteStream to offset and returns the * next record. Usually used in conjuctions with the shx file or some other * index file. Mind that: * <ul> * <li>it's your responsibility to ensure the offset corresponds to the * actual beginning of a shape struct</li> * <li>once you call this, reading with hasNext/next on sparse shapefiles * will be broken (we don't know anymore at which shape we are)</li> * </ul> * * * * @param offset * If using an shx file the offset would be: 2 * * (index.getOffset(i)) * @return The record after the offset location in the bytestream * @throws IOException * thrown in a read error occurs * @throws UnsupportedOperationException * thrown if not a random access file */ public Record recordAt(int offset) throws IOException, UnsupportedOperationException { if (randomAccessEnabled) { this.goTo(offset); return nextRecord(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * Parses the shpfile counting the records. * * @return the number of non-null records in the shapefile */ public int getCount(int count) throws DataSourceException { try { if (channel == null) return -1; count = 0; long offset = this.currentOffset; try { goTo(100); } catch (UnsupportedOperationException e) { return -1; } while (hasNext()) { count++; nextRecord(); } goTo((int) offset); } catch (IOException ioe) { count = -1; // What now? This seems arbitrarily appropriate ! throw new DataSourceException("Problem reading shapefile record", ioe); } return count; }
/** * Parses the shpfile counting the records. * * @return the number of non-null records in the shapefile */ public int getCount(int count) throws DataSourceException { try { if (channel == null) return -1; count = 0; long offset = this.currentOffset; try { goTo(100); } catch (UnsupportedOperationException e) { return -1; } while (hasNext()) { count++; nextRecord(); } goTo((int) offset); } catch (IOException ioe) { count = -1; // What now? This seems arbitrarily appropriate ! throw new DataSourceException("Problem reading shapefile record", ioe); } return count; }
/** * Returns the shape at the specified byte distance from the beginning of * the file. Mind that: * <ul> * <li>it's your responsibility to ensure the offset corresponds to the * actual beginning of a shape struct</li> * <li>once you call this, reading with hasNext/next on sparse shapefiles * will be broken (we don't know anymore at which shape we are)</li> * </ul> * * * @param offset * @throws IOException * @throws UnsupportedOperationException */ public Object shapeAt(int offset) throws IOException, UnsupportedOperationException { disableShxUsage(); if (randomAccessEnabled) { this.goTo(offset); return nextRecord().shape(); } throw new UnsupportedOperationException("Random Access not enabled"); }
/** * Returns the shape at the specified byte distance from the beginning of * the file. Mind that: * <ul> * <li>it's your responsibility to ensure the offset corresponds to the * actual beginning of a shape struct</li> * <li>once you call this, reading with hasNext/next on sparse shapefiles * will be broken (we don't know anymore at which shape we are)</li> * </ul> * * * @param offset * @throws IOException * @throws UnsupportedOperationException */ public Object shapeAt(int offset) throws IOException, UnsupportedOperationException { disableShxUsage(); if (randomAccessEnabled) { this.goTo(offset); return nextRecord().shape(); } throw new UnsupportedOperationException("Random Access not enabled"); }
public void next() throws IOException { if( !hasNext() ) throw new IndexOutOfBoundsException("No more features in reader"); if (this.goodRecs != null) { this.recno = ((Integer) next.getValue(0)).intValue(); if (dbf != null) { dbf.goTo(this.recno); } Long l = (Long) next.getValue(1); shp.goTo((int) l.longValue()); next=null; } else { this.recno++; } record = shp.nextRecord(); if (dbf != null) { row = dbf.readRow(); } }
final int shapeId = shapeIds[i]; int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY); final int shapeId = shapeIds[i]; int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY);
for (Iterator iter = records.iterator(); iter.hasNext();) { Data data = (Data) iter.next(); reader.goTo(((Long) data.getValue(1)).intValue()); Record record = reader.nextRecord(); ret.expandToInclude(new Envelope(record.minX, record.maxX,
for (Iterator iter = records.iterator(); iter.hasNext();) { Data data = (Data) iter.next(); reader.goTo(((Long) data.getValue(1)).intValue()); Record record = reader.nextRecord(); ret.expandToInclude(new Envelope(record.minX, record.maxX,
for (Iterator iter = records.iterator(); iter.hasNext();) { Data data = (Data) iter.next(); reader.goTo(((Long)data.getValue(1)).intValue()); Record record = reader.nextRecord(); ret.expandToInclude(new Envelope(record.minX, record.maxX, record.minY, record.maxY));
shp.goTo((int) l.longValue());
shp.goTo((int) l.longValue());
final int shapeId = shapeIds[i]; int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY); final int shapeId = shapeIds[i]; int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY);