Finding the top left extent of rasters in a folder and subfolders
You need to change the path in the code to your local path. The top left coordinates are printed out to the command window. See the following code:
[Java]
static double minx = 100000000000d;
static double maxy = - 100000000000d;
static void printTopLeft()throws Exception{
String path = "C:\\Program Files\\ArcGIS\\java\\samples\\data\\3dmodel_texture";
getTopLeft(path);
System.out.println("Left is:" + minx);
System.out.println("Top is:" + maxy);
}
static void getTopLeft(String path)throws Exception{
//Get top left most point from rasters in a folder and its subfolders.
//Initialize geoprocessor.
GeoProcessor geoprocessor = new GeoProcessor();
GetRasterProperties getRasterProperties = new GetRasterProperties();
GPUtilities gpUtil = new GPUtilities();
//Get subdirectories.
File dir = new File(path);
FileFilter directoryFilter = new FileFilter(){
public boolean accept(File file){
return file.isDirectory();
}
};
File[] subDirs = dir.listFiles(directoryFilter);
//Set environment.
geoprocessor.setEnvironmentValue("workspace", dir.getAbsolutePath());
IGpEnumList files = geoprocessor.listRasters("", "");
//Get first raster.
String raster = files.next();
while (raster != null && !raster.trim().equals("")){
System.out.println(dir.getAbsolutePath() + "\\" + raster);
getRasterProperties.setInRaster(raster);
//Get xmin.
getRasterProperties.setPropertyType("LEFT");
geoprocessor.execute(getRasterProperties, null);
double x = getRasterProperties.getProperty();
if (x < minx)
minx = x;
//Get ymax.
getRasterProperties.setPropertyType("TOP");
geoprocessor.execute(getRasterProperties, null);
double y = getRasterProperties.getProperty();
if (y > maxy)
maxy = y;
//Get next raster.
raster = files.next();
}
if (subDirs != null && subDirs.length > 0){
for (File file: subDirs)
getTopLeft(file.getAbsolutePath());
}
}
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |