ArcObjects c++ 获取栅格或矢量图层的范围
double xLeft = 0;
double yBottom = 0;
double xRight = 0;
double yUpper = 0;
if (0 == inputType)
{
//获取矢量图层的范围
CComBSTR srcPath;
srcPath = GeoProcessHander::QString2BSTR(inputPath);
CComBSTR srcName;
srcName = GeoProcessHander::QString2BSTR(inputName);
IWorkspaceFactoryPtr ipWkspFactory(CLSID_ShapefileWorkspaceFactory);
IWorkspacePtr ipWksp;
HRESULT hrw = ipWkspFactory->OpenFromFile(srcPath, 0, &ipWksp);
if (FAILED(hrw) || ipWksp == 0)
{
return false;
}
IFeatureClassPtr ipSrcFeatureClass;
hrw = ((IFeatureWorkspacePtr)ipWksp)->OpenFeatureClass(srcName,
&ipSrcFeatureClass);
if (FAILED(hrw) || ipSrcFeatureClass == 0)
{
return false;
}
IFeatureLayerPtr ipFeatureLayer(__uuidof(FeatureLayer));
ipFeatureLayer->putref_FeatureClass(ipSrcFeatureClass);
IEnvelopePtr ipEnv(CLSID_Envelope);
ipFeatureLayer->get_AreaOfInterest(&ipEnv);
ipEnv->get_XMax(&xRight);
ipEnv->get_YMax(&yUpper);
ipEnv->get_XMin(&xLeft);
ipEnv->get_YMin(&yBottom);
}
else if (1 == inputType)
{
//获取栅格数据范围
CComBSTR srcPath;
srcPath = GeoProcessHander::QString2BSTR(inputPath);
CComBSTR srcName;
srcName = GeoProcessHander::QString2BSTR(inputName);
IWorkspaceFactoryPtr ipWkspFactory(CLSID_RasterWorkspaceFactory);
IWorkspacePtr ipWksp;
HRESULT hr = ipWkspFactory->OpenFromFile(srcPath, 0, &ipWksp);
if (FAILED(hr) || ipWksp == 0)
{
return false;
}
IRasterWorkspacePtr ipRastWork(ipWksp);
IRasterDatasetPtr ipRastDataset;
hr = ipRastWork->OpenRasterDataset(srcName, &ipRastDataset);
if (FAILED(hr) || ipRastDataset == 0)
{
return false;
}
IRasterLayerPtr ipRasterLayer(__uuidof(RasterLayer));
ipRasterLayer->CreateFromDataset(ipRastDataset);
IEnvelopePtr ipEnv(CLSID_Envelope);
ipRasterLayer->get_AreaOfInterest(&ipEnv);
ipEnv->get_XMax(&xRight);
ipEnv->get_YMax(&yUpper);
ipEnv->get_XMin(&xLeft);
ipEnv->get_YMin(&yBottom);
}
转载自:https://blog.csdn.net/retnew/article/details/51228310