/** @param recBuf */ public SHPPolyLine3D(byte[] recBuf) { super(recBuf); int pointsStart = 0; int sumPoints = 0; envelope = ShapeUtils.readBox(recBuf, 4); numParts = ByteUtils.readLEInt(recBuffer, 36); numPoints = ByteUtils.readLEInt(recBuffer, 40); pointsStart = ShapeConst.PARTS_START + (numParts * 4); points = new SHPPoint[numParts][]; for (int j = 0; j < numParts; j++) { int firstPointNo = 0; int nextFirstPointNo = 0; int offset = 0; int lnumPoints = 0; // get number of first point of current part out of ESRI shape Record: firstPointNo = ByteUtils.readLEInt(recBuffer, ShapeConst.PARTS_START + (j * 4)); // calculate offset of part in bytes, count from the beginning of recordbuffer offset = pointsStart + (firstPointNo * 16); // get number of first point of next part ... if (j < numParts - 1) { // ... usually out of ESRI shape Record nextFirstPointNo = ByteUtils.readLEInt(recBuffer, ShapeConst.PARTS_START + ((j + 1) * 4)); } // ... for the last part as total number of points else if (j == numParts - 1) { nextFirstPointNo = numPoints; } // calculate number of points per part due to distance and // calculate some checksum for the total number of points to be worked lnumPoints = nextFirstPointNo - firstPointNo; sumPoints += lnumPoints; // allocate memory for the j-th part points[j] = new SHPPoint[lnumPoints]; int zPos = pointsStart + 16 * numPoints + 16; // create the points of the j-th part from the buffer for (int i = 0; i < lnumPoints; i++) { double z = ByteUtils.readLEDouble(recBuffer, zPos); zPos += 8; SHPPoint dummyPoint = new SHPPoint(recBuf, offset + (i * 16)); points[j][i] = new SHPPoint3D(dummyPoint.x, dummyPoint.y, z); } } }
/** * Reads and parses the header of the file. Values from the header<br> * are stored in the fields of this class.<br> */ private void readHeader() throws IOException { header = new byte[ShapeConst.SHAPE_FILE_HEADER_LENGTH]; /* * Make sure we're at the beginning of the file */ rafShp.seek(0); rafShp.read(header, 0, ShapeConst.SHAPE_FILE_HEADER_LENGTH); int fileCode = ByteUtils.readBEInt(header, 0); if (fileCode != ShapeConst.SHAPE_FILE_CODE) { throw new IOException("Invalid file code, " + "probably not a shape file"); } fileVersion = ByteUtils.readLEInt(header, 28); if (fileVersion != ShapeConst.SHAPE_FILE_VERSION) { throw new IOException("Unable to read shape files with version " + fileVersion); } fileLength = ByteUtils.readBEInt(header, 24); /* * convert from 16-bit words to 8-bit bytes */ fileLength *= 2; fileShapeType = ByteUtils.readLEInt(header, 32); /* * read ESRIBoundingBox and convert to SHPEnvelope */ fileMBR = new SHPEnvelope(ShapeUtils.readBox(header, 36)); }