int tempImageStartY = 0;
int tempImageEndX = 0;
int tempImageEndY = 0;
// save the world coordinates to go with the image coordinates.
EnvelopeBuffer tempWorldBuffer = new EnvelopeBuffer();
// loop through the image retrieving the tiles as necissary.
boolean tempFoundTile = false;
for (int i=0; i<tempPoints.length; i++){
// retrieve the file
File tempFile = new File(myIndex.getFileName(tempResolution, tempPoints[i].x, tempPoints[i].y));
if (tempFile.exists()){
// read the image
System.out.println("Reading Image "+tempFile.getName());
ImageInformation tempImageInformation = ImageReader.readImage(tempFile.getAbsolutePath());
if (tempImageInformation != null){
// draw the tile on the image.
Envelope tempTileEnvelope = myIndex.getWorldCoordinates(tempResolution, tempPoints[i].x, tempPoints[i].y);
tempWorldBuffer.expandToInclude(tempTileEnvelope);
int tempTileStartX = (int) (((tempTileEnvelope.getMinX() - inEnvelope.getMinX())/inEnvelope.getWidth()) * tempWidth);
int tempTileStartY = tempHeight - (int) (((tempTileEnvelope.getMinY() - inEnvelope.getMinY())/inEnvelope.getHeight()) * tempHeight);
int tempTileEndX = (int) (((tempTileEnvelope.getMaxX() - inEnvelope.getMinX())/inEnvelope.getWidth()) * tempWidth);
int tempTileEndY = tempHeight - (int) (((tempTileEnvelope.getMaxY() - inEnvelope.getMinY())/inEnvelope.getHeight()) * tempHeight);
if (i==0) {
tempImageStartX = tempTileStartX;
tempImageStartY = tempTileEndY;
tempImageEndX = tempTileEndX;
tempImageEndY = tempTileStartY;
}
else{
if (tempTileStartX < tempImageStartX) tempImageStartX = tempTileStartX;
if (tempTileEndY < tempImageStartY) tempImageStartY = tempTileEndY;
if (tempTileEndX > tempImageEndX) tempImageEndX = tempTileEndX;
if (tempTileStartY > tempImageEndY) tempImageEndY = tempTileStartY;
}
g2d.drawImage(tempImageInformation.getImage(), tempTileStartX, tempTileEndY, tempTileEndX, tempTileStartY, 0, 0, tempImageInformation.getImageWidth(), tempImageInformation.getImageHeight(), null);
tempFoundTile = true;
}
}
}
if (!tempFoundTile) return new GISDataset();
// create the dataset
String[] tempAttributeNames = {"Name"};
AttributeType[] tempAttributeTypes = {new AttributeType(AttributeType.STRING)};
GISDataset tempGISDataset = new GISDataset(tempAttributeNames, tempAttributeTypes);
// create a new image if necissary.
if (tempImageStartX < 0) tempImageStartX = 0;
if (tempImageStartY < 0) tempImageStartY = 0;
if (tempImageEndX > tempWidth) tempImageEndX = tempWidth;
if (tempImageEndY > tempHeight) tempImageEndY = tempHeight;
if ((tempImageStartX > 0) || (tempImageStartY > 0) || (tempImageEndX < tempWidth) || (tempImageEndY < tempHeight)){
int tempNWidth = tempImageEndX - tempImageStartX;
int tempNHeight = tempImageEndY - tempImageStartY;
BufferedImage tempNewImage = new BufferedImage(tempNWidth, tempNHeight, BufferedImage.TYPE_INT_ARGB);
// fill the background with a transparent color.
Graphics gn = tempNewImage.getGraphics();
gn.setColor(new Color(255,255,255,1));
gn.fillRect(0,0,tempNWidth, tempNHeight);
Graphics2D gn2d = (Graphics2D) gn;
// draw the old image onto the new image.
gn2d.drawImage(tempImage, 0, 0, tempNWidth, tempNHeight,
tempImageStartX, tempImageStartY, tempImageEndX, tempImageEndY,
null);
// create the envelope for this image.
Envelope tempNewEnvelope = tempWorldBuffer.getEnvelope();
double tempWorldMinX = inEnvelope.getMinX()+(((double)tempImageStartX)/(double)tempWidth)*inEnvelope.getWidth();
double tempWorldMinY = inEnvelope.getMaxY()-(((double)tempImageStartY)/(double)tempHeight)*inEnvelope.getHeight();
double tempWorldMaxX = inEnvelope.getMinX()+(((double)tempImageEndX)/(double)tempWidth)*inEnvelope.getWidth();
double tempWorldMaxY = inEnvelope.getMaxY()-(((double)tempImageEndY)/(double)tempHeight)*inEnvelope.getHeight();