/** * 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"); }
/** * 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"); }
/** * 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; }
rec = reader.nextRecord(); tree.insert(cnt++, new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY));
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; } }
@Override public boolean hasNext() throws IOException { while (nextFeature == null && filesHaveMore()) { Record record = shp.nextRecord(); Geometry geometry = getGeometry(record); if (geometry != SKIP) { // also grab the dbf row Row row; if (dbf != null) { row = dbf.readRow(); if (row.isDeleted()) { continue; } } else { row = null; } nextFeature = buildFeature(record.number, geometry, row, record.envelope()); } else { if (dbf != null) { dbf.skip(); } } } return nextFeature != null; }
public void next() throws IOException { record = shp.nextRecord(); if (dbf != null) { row = dbf.readRow(); } }
/** * 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"); }
/** * 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"); }
public ShapefileReader.Record next() throws IOException { if (!hasNext()) throw new IndexOutOfBoundsException( "No more features in reader"); if (this.goodRecs != null) { Long l = (Long) next.getValue(1); ShapefileReader.Record record = shp.recordAt(l.intValue()); next = null; return record; } recno++; return shp.nextRecord(); }
/** * 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"); }
public ShapefileReader.Record next() throws IOException { if( !hasNext() ) throw new IndexOutOfBoundsException("No more features in reader"); if (this.goodRecs != null) { Long l = (Long) next.getValue(1); ShapefileReader.Record record = shp.recordAt(l.intValue()); next=null; return record; } recno++; return shp.nextRecord(); }
public static void main(String[] args) throws Exception { FileChannel channel = new FileInputStream(args[0]).getChannel(); ShapefileReader reader = new ShapefileReader(channel, new Lock()); System.out.println(reader.getHeader()); while (reader.hasNext()) { System.out.println(reader.nextRecord().shape()); } reader.close(); }
/** * 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(); } }
int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY); tree.insert(node, shapeId, env, extraLevels); int offset = index.getOffsetInBytes(shapeId); reader.goTo(offset); Record rec = reader.nextRecord(); Envelope env = new Envelope(rec.minX, rec.maxX, rec.minY, rec.maxY); bounds.expandToInclude(env);
/** * 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; }