public PointHandler(ShapeType type, GeometryFactory gf) throws ShapefileException { if ((type != ShapeType.POINT) && (type != ShapeType.POINTM) && (type != ShapeType.POINTZ)) { // 2d, 2d+m, 3d+m throw new ShapefileException( "PointHandler constructor: expected a type of 1, 11 or 21"); } shapeType = type; this.geometryFactory = gf; }
/** * Get the offset of the record (in real bytes, not 16-bit words). * * @param index The index, from 0 to getRecordCount - 1 * @return The offset in bytes. * @throws IOException */ public int getOffsetInBytes(int index) throws IOException { return this.getOffset(index) * 2; }
ShapeType getShapeType() { return shp.getHeader().getShapeType(); }
public Object getSimplifiedShape(ScreenMap sm) { if (type.isPointType()) { return shape(); } Class geomType = Geometry.class; if (type.isLineType()) { geomType = MultiLineString.class; } else if (type.isMultiPointType()) { geomType = MultiPoint.class; } else if (type.isPolygonType()) { geomType = MultiPolygon.class; } return sm.getSimplifiedShape(minX, minY, maxX, maxY, geometryFactory, geomType); } }
private int writeNonNullGeometry(Geometry g) { int length = handler.getLength(g); // must allocate enough for shape + header (2 ints) checkShapeBuffer(length + 8); length /= 2; shapeBuffer.order(ByteOrder.BIG_ENDIAN); shapeBuffer.putInt(++cnt); shapeBuffer.putInt(length); shapeBuffer.order(ByteOrder.LITTLE_ENDIAN); shapeBuffer.putInt(type.id); handler.write(shapeBuffer, g); return length; }
public void read(ByteBuffer file, boolean strict) throws java.io.IOException { file.order(ByteOrder.BIG_ENDIAN); fileCode = file.getInt(); checkMagic(strict); // skip 5 ints... file.position(file.position() + 20); fileLength = file.getInt(); file.order(ByteOrder.LITTLE_ENDIAN); version = file.getInt(); checkVersion(strict); shapeType = ShapeType.forID(file.getInt()); minX = file.getDouble(); minY = file.getDouble(); maxX = file.getDouble(); maxY = file.getDouble(); // skip remaining unused bytes file.order(ByteOrder.BIG_ENDIAN); // well they may not be unused // forever... file.position(file.position() + 32); }
/** * If there exists another record. Currently checks the stream for the presence of 8 more bytes, * the length of a record. If this is true and the record indicates the next logical record * number, there exists more records. * * @throws IOException * @return True if has next record, false otherwise. */ public boolean hasNext() throws IOException { return this.hasNext(true); }
/** * Disables .shx file usage. By doing so you drop support for sparse shapefiles, the .shp will * have to be without holes, all the valid shapefile records will have to be contiguous. * * @throws IOException */ public void disableShxUsage() throws IOException { if (shxReader != null) { shxReader.close(); shxReader = null; } currentShape = UNKNOWN; }
/** * Get the number of records in this index. * * @return The number of records. */ public int getRecordCount() { return (header.getFileLength() * 2 - 100) / 8; }
private int getNextOffset() throws IOException { if (currentShape >= 0) { return shxReader.getOffsetInBytes(currentShape); } else { return record.end; } }
private MultiPolygon createMulti(LinearRing single) { return createMulti(single, java.util.Collections.EMPTY_LIST); }
/** * Get the offset of the record (in 16-bit words). * * @param index The index, from 0 to getRecordCount - 1 * @return The offset in 16-bit words. * @throws IOException */ public int getOffset(int index) throws IOException { int ret = -1; if (this.channel != null) { if (this.lastIndex != index) { this.readRecord(index); } ret = this.recOffset; } else { ret = content[2 * index]; } return ret; }
/** * Allocate internal buffers and position the channels to the beginning or the record section of * the shapefile. The headers MUST be rewritten after this operation, or the file may be * corrupt... */ public void skipHeaders() throws IOException { if (shapeBuffer == null) allocateBuffers(); shpChannel.position(100); shxChannel.position(100); }
protected int writeNullGeometry() throws IOException { // two for the headers + the null shape mark int length = 4; checkShapeBuffer(8 + length); length /= 2; shapeBuffer.order(ByteOrder.BIG_ENDIAN); shapeBuffer.putInt(++cnt); shapeBuffer.putInt(length); shapeBuffer.order(ByteOrder.LITTLE_ENDIAN); shapeBuffer.putInt(ShapeType.NULL.id); return length; }
/** * Determine the min and max "z" values in an array of Coordinates. * * @param cs The array to search. * @return An array of size 2, index 0 is min, index 1 is max. * @deprecated use zMinMax(CoordinateSequence) */ public static final double[] zMinMax(final Coordinate[] cs) { double[] result = {Double.NaN, Double.NaN}; zMinMax(new CoordinateArraySequence(cs), result); return result; }
void disableShxUsage() throws IOException { this.shp.disableShxUsage(); }
public MultiPointHandler(ShapeType type, GeometryFactory gf) throws ShapefileException { if ((type != ShapeType.MULTIPOINT) && (type != ShapeType.MULTIPOINTM) && (type != ShapeType.MULTIPOINTZ)) { throw new ShapefileException( "Multipointhandler constructor - expected type to be 8, 18, or 28"); } shapeType = type; this.geometryFactory = gf; }
/** @see java.lang.Object#finalize() */ protected void finalize() throws Throwable { this.close(); super.finalize(); }
public PolygonHandler(ShapeType type, GeometryFactory gf) throws ShapefileException { if ((type != ShapeType.POLYGON) && (type != ShapeType.POLYGONM) && (type != ShapeType.POLYGONZ)) { throw new ShapefileException( "PolygonHandler constructor - expected type to be 5, 15, or 25."); } shapeType = type; this.geometryFactory = gf; }
/** * Create a MultiLineHandler for one of: <br> * ShapeType.ARC,ShapeType.ARCM,ShapeType.ARCZ * * @param type The ShapeType to use. * @throws ShapefileException If the ShapeType is not correct (see constructor). */ public MultiLineHandler(ShapeType type, GeometryFactory gf) throws ShapefileException { if ((type != ShapeType.ARC) && (type != ShapeType.ARCM) && (type != ShapeType.ARCZ)) { throw new ShapefileException( "MultiLineHandler constructor - expected type to be 3,13 or 23"); } shapeType = type; this.geometryFactory = gf; }