protected GISDataset readShapes(Envelope inEnvelope) throws Exception {
// ensure there is an overlap
if (!inEnvelope.overlaps(readEnvelope())) return new GISDataset();
// create the new file, in nonprogressive mode.
JNCSFile tempECWFile = new JNCSFile(getFileLocation(), false);
// trim the envelope to the one in view.
Envelope tempEnvelope = inEnvelope.getOverlap(readEnvelope());
// figure out how big this image needs to be (the JNCSFile does not do subsampling);
int width = getImageWidth();
int height = getImageHeight();
// find the required width and height.
if (tempECWFile.cellIncrementX > (tempEnvelope.getWidth()/width)){
width = (int) (tempEnvelope.getWidth()/tempECWFile.cellIncrementX);
}
if (Math.abs(tempECWFile.cellIncrementY) > (tempEnvelope.getHeight()/height)){
height = (int) (tempEnvelope.getHeight()/Math.abs(tempECWFile.cellIncrementY));
}
// go about generating the data
double dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY;
int bandlist[];
int line, pRGBArray[] = null;
// Create an image of the ecw file.
BufferedImage ecwImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
pRGBArray = new int[width];
// Setup the view parameters for the ecw file.
bandlist = new int[tempECWFile.numBands];
for (int i=0; i< tempECWFile.numBands; i++) {
bandlist[i] = i;
}
dWorldTLX = tempEnvelope.getMinX();
dWorldTLY = tempEnvelope.getMaxY();
dWorldBRX = tempEnvelope.getMaxX();
dWorldBRY = tempEnvelope.getMinY();
// Set the view
tempECWFile.setView(tempECWFile.numBands, bandlist, dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, width, height);
// Read the scan lines
for (line=0; line < height; line++) {
tempECWFile.readLineRGBA(pRGBArray);
ecwImage.setRGB(0, line, width, 1, pRGBArray, 0, width);
}
// close the file
tempECWFile.close(true);
// return the graphics object
RasterShape tempShape = new RasterShape(tempEnvelope, ecwImage);
Record tempRecord = new Record();