Friday, July 31, 2009

ArcObjects Get Raster Extents (Properties)

I wanted to grab a rasters extents and was trying to avoid opening a RasterDataset and going through all the workspace stuffs. Experience has taught me to always look into the DataManagementTools before banging my head. Low and behold, the GetRasterProperties class was found.
Geoprocessor geoprocessor = new Geoprocessor();

GetRasterProperties rasterProperties = new GetRasterProperties();
rasterProperties.in_raster = rasterFilename;
rasterProperties.property_type = "TOP";
geoprocessor.Execute(rasterProperties,null);
double top = rasterProperties.property;

rasterProperties.property_type = "BOTTOM";
geoprocessor.Execute(rasterProperties,null);
double bottom = rasterProperties.property;

rasterProperties.property_type = "LEFT";
geoprocessor.Execute(rasterProperties,null);
double left = rasterProperties.property;

rasterProperties.property_type = "RIGHT";
geoprocessor.Execute(rasterProperties,null);
double right = rasterProperties.property;

I really wish there was a way to return more than one property, seems kindof inefficient doing it this way. Maybe i'll go back and do it the other way, using the IRaster2 interface. Grrr...

No comments: