RESULTCODE DemAspectProcessorImpl::Execute() { const char* inSourceName = GetInputDataSource(); const char* inRasterName = GetInputRaster(); const char* inRasterPath = GetInputRasterPath(); const char* outSourceName = GetOutputDataSource(); const char* outRasterName = GetOutputRaster(); const char* outRasterPath = GetOutputRasterPath(); Workspace* pWorkspace = NULL; RasterWorkspace* pinRasterWorkspace = NULL; RasterWorkspace* poutRasterWorkspace = NULL; GError* pError = augeGetErrorInstance(); GLogger* pLogger = augeGetLoggerInstance(); ConnectionManager* pConnManager = augeGetConnectionManagerInstance(); pWorkspace = pConnManager->GetWorkspace(m_user, inSourceName); if(pWorkspace==NULL) { return AG_FAILURE; } pinRasterWorkspace = dynamic_cast<RasterWorkspace*>(pWorkspace); pWorkspace = pConnManager->GetWorkspace(m_user, outSourceName); if(pWorkspace==NULL) { return AG_FAILURE; } poutRasterWorkspace = dynamic_cast<RasterWorkspace*>(pWorkspace); Raster* pinRaster = NULL; RasterFolder* pinFolder = NULL; Raster* poutRaster = NULL; RasterFolder* poutFolder = NULL; pinFolder = pinRasterWorkspace->GetFolder(inRasterPath); if(pinFolder==NULL) { return AG_FAILURE; } pinRaster = pinFolder->GetRasterDataset()->GetRaster(inRasterName); if(pinRaster==NULL) { const char* msg = "无法打开输入栅格数据"; pError->SetError(msg); pinFolder->Release(); return AG_FAILURE; } g_uint band_count = pinRaster->GetBandCount(); if(band_count!=1) { const char* msg = "Dem坡向计算仅支持单波段Dem数据"; pError->SetError(msg); pinFolder->Release(); return AG_FAILURE; } poutRaster = Aspect(pinRaster); if(poutRaster!=NULL) { poutRaster->SetName(outRasterName); } poutFolder = poutRasterWorkspace->GetFolder(outRasterPath); if(poutFolder==NULL) { pinFolder->Release(); poutRaster->Release(); return AG_FAILURE; } RESULTCODE rc = poutFolder->GetRasterDataset()->AddRaster(outRasterName, poutRaster); poutRaster->Release(); pinFolder->Release(); poutFolder->Release(); return rc; }
Raster* RasterMosiacProcessorImpl::Mosiac(char** rasters, g_uint count, const char* poutRasterPath) { if(count==0) { return NULL; } Raster* pinRaster = NULL; Raster* pinRaster0 = NULL; Raster* poutRaster = NULL; Raster** ppinRasters = new Raster*[count]; memset(ppinRasters, 0, sizeof(Raster*)*count); RasterIO* io = augeGetRasterIOInstance(); const char* rpath = NULL; for(g_uint i=0; i<count; i++) { rpath = rasters[i]; if(rpath!=NULL) { pinRaster = io->Read(rpath); ppinRasters[i] = pinRaster; } } if(!MosiacCheck(ppinRasters, count)) { CleanupRasters(ppinRasters, count); return NULL; } pinRaster0 = GetRaster0(ppinRasters, count); if(pinRaster0==NULL) { CleanupRasters(ppinRasters, count); return NULL; } char uuid[AUGE_NAME_MAX]; auge_generate_uuid(uuid, AUGE_NAME_MAX); g_uint srid = pinRaster0->GetSRID(); g_uint bands = pinRaster0->GetBandCount(); const char* format = pinRaster0->GetFormat(); double resolution_x = pinRaster0->GetResolution_X(); double resolution_y = pinRaster0->GetResolution_Y(); augePixelType pixelType = pinRaster0->GetPixelType(); const char* spatialref = pinRaster0->GetSpatialReference(); GEnvelope extent; if(!ComputeMosiacExtent(extent, ppinRasters, count)) { CleanupRasters(ppinRasters, count); return NULL; } g_uint width, height; width = ceil(extent.GetWidth() / fabs(resolution_x)); height= ceil(extent.GetHeight() / fabs(resolution_y)); RasterFactory* pRasterFactory = augeGetRasterFactoryInstance(); { poutRaster = pRasterFactory->CreateRaster("", pixelType, bands, extent, width, height,spatialref); g_uint64 pixelSize = (g_uint64)(pinRaster0->GetPixelSize()); g_uint64 buffer_size = width * height * pixelSize; void* buffer = malloc(buffer_size); g_uint bands = poutRaster->GetBandCount(); for(g_uint i=0; i<bands;i++) { memset(buffer, 0, buffer_size); RasterBand* poutBand = poutRaster->GetBand(i); //for(int j=0; j<count; j++) for(int j=0; j<1; j++) { pinRaster = ppinRasters[j]; RasterBand* pinBand = pinRaster->GetBand(i); CopyBandMem(poutBand, pinBand, poutRaster, buffer); } poutBand->SetData(buffer); } poutRaster->Save(poutRasterPath); free(buffer); } { // //·Ö¿éMosiac // poutRaster = pRasterFactory->CreateRaster("", poutRasterPath,"gtiff", pixelType, bands, extent, width, height,spatialref); // //CreateRaster(const char* name, const char* path, const char* format, augePixelType pixelType, g_uint bands, GEnvelope& extent, g_uint width, g_uint height, const char* spatialRef); // if(poutRaster==NULL) // { // CleanupRasters(ppinRasters, count); // return NULL; // } // for(g_uint i=0; i<count;i++) // //for(g_uint i=0; i<1;i++) // //for(g_uint i=1; i<2;i++) // { // pinRaster = ppinRasters[i]; // Mosiac(poutRaster, pinRaster); // } } CleanupRasters(ppinRasters, count); return poutRaster; }