/// <summary> /// 判断数据库和镶嵌数据集是否存在的,存在就读取,不存在,就创建 /// </summary> /// <param name="filegdb"></param> /// <param name="mosaicDatasetName"></param> /// <returns></returns> public IMosaicDataset CreateMD(string filegdb, string mosaicDatasetName) { ISpatialReference mosaicSrs = null; int mosaicDatasetBands = 0; rstPixelType mosaicDatasetBits = rstPixelType.PT_UNKNOWN; string configKeyword = ""; IWorkspace wk = null; if (System.IO.Directory.Exists(filegdb)) { wk = OpenFileGDB(filegdb); } else { wk = CreateFileGDB(filegdb); } IMosaicDataset theMosaicDataset = null; IWorkspace2 wk2 = wk as IWorkspace2; if (wk2.get_NameExists(esriDatasetType.esriDTMosaicDataset, mosaicDatasetName)) { theMosaicDataset = OpenMosaicDataset(ref wk, mosaicDatasetName); } else { theMosaicDataset = CreateMosaicDataset(ref wk, mosaicDatasetName, mosaicSrs, mosaicDatasetBands, mosaicDatasetBits, configKeyword); } return(theMosaicDataset); }
public bool AddRasterDatesetToMD(IMosaicDataset pMosaicDataset, IRasterDataset pRasteDataset, IRasterType pRasterType) { try { IRasterDatasetCrawler pRasterDatasetCrawler = new RasterDatasetCrawlerClass(); pRasterDatasetCrawler.RasterDataset = pRasteDataset; IDataset pDataset = pRasteDataset as IDataset; ESRI.ArcGIS.esriSystem.IName pName = pDataset.FullName; pRasterDatasetCrawler.DatasetName = pName; IMosaicDatasetOperation pMosaicDatasetOperation = (IMosaicDatasetOperation)pMosaicDataset; IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); AddRastersArgs.Crawler = pRasterDatasetCrawler as IDataSourceCrawler; AddRastersArgs.RasterType = pRasterType; pMosaicDatasetOperation.AddRasters(AddRastersArgs, null); return true; } catch (System.Exception ex) { return false; } }
public bool AddRasterDatesetToMD(IMosaicDataset pMosaicDataset, IRasterDataset pRasteDataset, IRasterType pRasterType) { try { IRasterDatasetCrawler pRasterDatasetCrawler = new RasterDatasetCrawlerClass(); pRasterDatasetCrawler.RasterDataset = pRasteDataset; IDataset pDataset = pRasteDataset as IDataset; ESRI.ArcGIS.esriSystem.IName pName = pDataset.FullName; pRasterDatasetCrawler.DatasetName = pName; IMosaicDatasetOperation pMosaicDatasetOperation = (IMosaicDatasetOperation)pMosaicDataset; IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); AddRastersArgs.Crawler = pRasterDatasetCrawler as IDataSourceCrawler; AddRastersArgs.RasterType = pRasterType; pMosaicDatasetOperation.AddRasters(AddRastersArgs, null); return(true); } catch (System.Exception ex) { return(false); } }
public bool LoadRasters2MosaicDataset(string fgdbfile, string mosaicDatasetName, string rasterTypeName, string dataSource) { try { string fgdbName = System.IO.Path.GetFileName(fgdbfile); string fgdbParentFolder = System.IO.Path.GetDirectoryName(fgdbfile); //string rasterTypeName = "Raster Dataset"; string rasterTypeProductFilter = ""; string rasterTypeProductName = "Pansharpen;Multispectral"; string dataSourceFilter = ""; bool buildOverviews = true; string filegdbname = fgdbParentFolder + "\\" + fgdbName; IMosaicDataset theMosaicDataset = CreateMD(filegdbname, mosaicDatasetName); IRasterType theRasterType = PreparingRasterType(rasterTypeName, rasterTypeProductFilter, rasterTypeProductName); IDataSourceCrawler theCrawler = PreparingDataSourceCrawler(ref theRasterType, dataSourceFilter, dataSource); AddRasters(ref theMosaicDataset, ref theRasterType, ref theCrawler); ComputePixelSizeRanges(ref theMosaicDataset); BuildingBoundary(ref theMosaicDataset); //BuildOverview(ref theMosaicDataset, buildOverviews); return(true); } catch (System.Exception exc) { return(false); } }
/// <summary> /// 每次都创建新的数据库和新的镶嵌数据集的例子 /// </summary> /// <param name="filegdb"></param> /// <param name="mosaicDatasetName"></param> /// <returns></returns> public IMosaicDataset OpenMosaicDataset(string filegdb, string mosaicDatasetName) { IWorkspace wk = OpenFileGDB(filegdb); IMosaicDataset theMosaicDataset = OpenMosaicDataset(ref wk, mosaicDatasetName); return(theMosaicDataset); }
public void CanOpenMosaicDataset() { IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle(); IMosaicDataset dataset = DatasetUtils.OpenMosaicDataset(workspace, "TOPGIS_TLM.TLM_DTM_MOSAIC"); Assert.NotNull(dataset); }
public void CanGetRasterFileFromMosaicDatasetUsingSpatialQuery() { IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle(); IMosaicDataset mosaicDataset = DatasetUtils.OpenMosaicDataset(workspace, "TOPGIS_TLM.TLM_DTM_MOSAIC"); IFeatureClass rasterCatalog = mosaicDataset.Catalog; IEnvelope winterthur = GeometryFactory.CreateEnvelope( 2690000, 1254000, 2707500, 1266000, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)); winterthur.Expand(-0.1, -0.1, false); IQueryFilter spatialFilter = GdbQueryUtils.CreateSpatialFilter(rasterCatalog, winterthur); IStringArray stringArray; Stopwatch watch = Stopwatch.StartNew(); int count = 0; foreach (IFeature catalogFeature in GdbQueryUtils.GetFeatures( rasterCatalog, spatialFilter, false)) { // Method 1 (slow): var rasterCatalogItem = (IRasterCatalogItem)catalogFeature; IRasterDataset rasterDataset = rasterCatalogItem.RasterDataset; var itemPaths = (IItemPaths)rasterDataset; stringArray = itemPaths.GetPaths(); Marshal.ReleaseComObject(rasterDataset); Assert.AreEqual(1, stringArray.Count); string resultPathViaRasterDataset = stringArray.Element[0]; // Method 2 (fast): var itemPathsQuery = (IItemPathsQuery)mosaicDataset; if (itemPathsQuery.QueryPathsParameters == null) { itemPathsQuery.QueryPathsParameters = new QueryPathsParametersClass(); } stringArray = itemPathsQuery.GetItemPaths(catalogFeature); Assert.AreEqual(1, stringArray.Count); string resultPathViaItemPathsQuery = stringArray.Element[0]; Assert.AreEqual(resultPathViaRasterDataset, resultPathViaItemPathsQuery); count++; } Console.WriteLine("Successfully extracted {0} raster paths in {1}s", count, watch.Elapsed.TotalSeconds); }
public IMosaicDataset OpenMosaicDataset(ref IWorkspace fgdbWorkspace, string mosaicDatasetName) { IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace); Console.WriteLine("Opening Mosaic Dataset"); IMosaicDataset theMosaicDataset = mosaicExt.OpenMosaicDataset(mosaicDatasetName); return(theMosaicDataset); }
public void ComputePixelSizeRanges(ref IMosaicDataset theMosaicDataset) { IMosaicDatasetOperation theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); Console.WriteLine("Computing Pixel Size Ranges"); // Create a calculate cellsize ranges parameters object. ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass(); // Use the mosaic dataset operation interface to calculate cellsize ranges. theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); }
public void BuildingBoundary(ref IMosaicDataset theMosaicDataset) { IMosaicDatasetOperation theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); Console.WriteLine("Building Boundary"); // Create a build boundary parameters object. IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass(); // Set flags that control boundary generation. boundaryArgs.AppendToExistingBoundary = true; // Use the mosaic dataset operation interface to build boundary. theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null); }
public IMosaicDataset CreateMosaicDataset(ref IWorkspace fgdbWorkspace, string mosaicDatasetName, ISpatialReference mosaicSrs, int mosaicDatasetBands, rstPixelType mosaicDatasetBits, string configKeyword) { IMosaicDataset theMosaicDataset = null; try { Console.WriteLine("Create Mosaic Dataset: " + mosaicDatasetName); if (mosaicSrs == null) { ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass(); //ISpatialReference mosaicSrs = spatialrefFactory.CreateProjectedCoordinateSystem( // (int)(esriSRProjCSType.esriSRProjCS_World_Mercator)); mosaicSrs = spatialrefFactory.CreateGeographicCoordinateSystem( (int)(esriSRGeoCSType.esriSRGeoCS_WGS1984)); } // 创建镶嵌数据集创建参数对象 ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass(); // 设置镶嵌数据集band数量. // 0 为默认设置 if (mosaicDatasetBands != 0) { creationPars.BandCount = mosaicDatasetBands; } // 设置象元类型. // 默认为 unknown if (mosaicDatasetBits != rstPixelType.PT_UNKNOWN) { creationPars.PixelType = mosaicDatasetBits; } //创建栅格数据库扩展帮助类 IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); // 查找扩展 IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace); // 使用扩展创建新的镶嵌数据集, 需要提供空间参考和创建参数。 theMosaicDataset = mosaicExt.CreateMosaicDataset(mosaicDatasetName, mosaicSrs, creationPars, configKeyword); } catch (Exception exc) { Console.WriteLine("Exception Caught while creating Mosaic Dataset: " + exc.Message); Console.WriteLine("Shutting down."); Console.WriteLine("Press any key..."); Console.ReadKey(); } return(theMosaicDataset); }
public static void OpenMosaicDataset(AxMapControl MapControl, IMosaicDatasetName pMdName, ListView listview1) { MapControl.ClearLayers(); MapControl.SpatialReference = null; listview1.Items.Clear(); listview1.Columns.Clear(); IDatasetName pDsName = pMdName as IDatasetName; string sName = pDsName.Name; IName pName = pMdName as IName; IMosaicDataset pMds = pName.Open() as IMosaicDataset; IFeatureClass pFc = pMds.Catalog; listview1.Items.Clear(); listview1.Columns.Clear(); LoadListView(pFc, listview1); IFeatureCursor pCursor = pFc.Search(null, false); IFeature pfea = pCursor.NextFeature(); int j = 0; while (pfea != null) { ListViewItem lv = new ListViewItem(); for (int i = 0; i < pfea.Fields.FieldCount; i++) { string sFieldName = pfea.Fields.get_Field(i).Name; lv.SubItems.Add(FeatureHelper.GetFeatureValue(pfea, sFieldName).ToString()); } lv.Tag = pfea; if (j % 2 == 0) { lv.BackColor = System.Drawing.Color.GreenYellow; } listview1.Items.Add(lv); pfea = pCursor.NextFeature(); j++; } LSGISHelper.OtherHelper.ReleaseObject(pCursor); IMosaicLayer pML = new MosaicLayerClass(); pML.CreateFromMosaicDataset(pMds); MapControl.AddLayer(pML as ILayer); MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public bool ExistRow(IMosaicDataset pMosaic, string pValue) { ITable pTable = GetMosicTable(pMosaic); IQueryFilter pQueryFileter = new QueryFilterClass(); //sevp_aoc_rdcp_sldas_ebref_achn_l88_pi_201212050010 pQueryFileter.SubFields = "Name"; pQueryFileter.WhereClause = "Name =" + pValue; if (pTable.RowCount(pQueryFileter) > 0) { return(true); } return(false); }
public static bool AddWatermarkDataToMD(string MDWorkspaceFolder, string MDName, string watermarkImagePath, double blendPercentage, esriWatermarkLocation watermarklocation, bool clearFunctions) { try { // Open MD Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory mdWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace mdWorkspace = mdWorkspaceFactory.OpenFromFile(MDWorkspaceFolder, 0); IRasterWorkspaceEx workspaceEx = (IRasterWorkspaceEx)(mdWorkspace); IMosaicDataset mosaicDataset = (IMosaicDataset)workspaceEx.OpenRasterDataset( MDName); if (clearFunctions) // Clear functions already added to MD. { mosaicDataset.ClearFunction(); } // Create Watermark Function IRasterFunction rasterFunction = new CustomFunction.WatermarkFunction(); // Create the Watermark Function Arguments object IWatermarkFunctionArguments rasterFunctionArguments = new WatermarkFunctionArguments(); // Set the WatermarkImagePath rasterFunctionArguments.WatermarkImagePath = watermarkImagePath; // the blending percentage, rasterFunctionArguments.BlendPercentage = blendPercentage; // and the watermark location. rasterFunctionArguments.WatermarkLocation = watermarklocation; // Add function to MD. // This function takes the name of the property corresponding to the Raster // property of the Arguments object (in this case is it called Raster itself: // rasterFunctionArguments.Raster) as its third argument. mosaicDataset.ApplyFunction(rasterFunction, rasterFunctionArguments, "Raster"); Console.WriteLine("Added Watermark to MD: " + MDName + "."); Console.WriteLine("Success."); return(true); } catch (Exception exc) { Console.WriteLine("Exception Caught while adding watermark to MD: " + exc.Message); Console.WriteLine("Failed."); return(false); } }
public void AddRasters(ref IMosaicDataset theMosaicDataset, ref IRasterType theRasterType, ref IDataSourceCrawler theCrawler) { IMosaicDatasetOperation theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); Console.WriteLine("Adding Rasters"); // Create a AddRaster parameters object. IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); // Specify the data crawler to be used to crawl the data. AddRastersArgs.Crawler = theCrawler; // Specify the raster type to be used to add the data. AddRastersArgs.RasterType = theRasterType; // Use the mosaic dataset operation interface to add // rasters to the mosaic dataset. theMosaicDatasetOperation.AddRasters(AddRastersArgs, null); }
public void CanGetRasterFromMosaicDataset() { IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle(); IMosaicDataset dataset = DatasetUtils.OpenMosaicDataset(workspace, "TOPGIS_TLM.TLM_DTM_MOSAIC"); IRaster raster = ((IMosaicDataset3)dataset).GetRaster(string.Empty); Assert.NotNull(dataset); IRasterCursor rasterCursor = raster.CreateCursor(); IPixelBlock rasterCursorPixelBlock = rasterCursor.PixelBlock; Assert.NotNull(rasterCursorPixelBlock); }
public void Construct(IPropertySet props) { _configProps = props; IImageServerInit3 imageServer = (IImageServerInit3)_serverObjectHelper.ServerObject; IName mosaicName = imageServer.ImageDataSourceName; if (mosaicName is IMosaicDatasetName) { IMosaicDataset md = (IMosaicDataset)mosaicName.Open(); _mosaicCatalog = md.Catalog; _supportRasterItemAccess = true; } else { _supportRasterItemAccess = false; } }
public ITable GetMosaicDatasetTable(IMosaicDataset pMosaicDataset) { ITable pTable = null; IEnumName pEnumName = pMosaicDataset.Children; pEnumName.Reset(); ESRI.ArcGIS.esriSystem.IName pName; while ((pName = pEnumName.Next()) != null) { pTable = pName.Open() as ITable; int i = pTable.Fields.FieldCount; if (i >= 21) { break; } }//镶嵌数据集属性表默认23个字段 } return(pTable); }
public IMosaicDataset OpenMosaicDataset(IWorkspace pWorks, string pMosaicDatasetName) { IMosaicDataset pMosicDataset = null; IMosaicWorkspaceExtensionHelper pMosaicWsExHelper = new MosaicWorkspaceExtensionHelperClass(); IMosaicWorkspaceExtension pMosaicWsExt = pMosaicWsExHelper.FindExtension(pWorks); if (pMosaicWsExt != null) { try { pMosicDataset = pMosaicWsExt.OpenMosaicDataset(pMosaicDatasetName); } catch (Exception ex) { return(pMosicDataset); } } return(pMosicDataset); }
public static void OpenMosaicDataset(AxMapControl MapControl, IMosaicDatasetName pMdName, DataTable dt = null) { MapControl.ClearLayers(); MapControl.SpatialReference = null; IDatasetName pDsName = pMdName as IDatasetName; string sName = pDsName.Name; IName pName = pMdName as IName; IMosaicDataset pMds = pName.Open() as IMosaicDataset; if (null != dt) { IFeatureClass pFc = pMds.Catalog; InitDataTable(pFc, dt); IFeatureCursor pCursor = pFc.Search(null, false); IFeature pfea = pCursor.NextFeature(); int j = 0; while (pfea != null) { DataRow dataRow = dt.NewRow(); for (int i = 0; i < pfea.Fields.FieldCount; i++) { dataRow[i] = pfea.get_Value(i).ToString(); } dt.Rows.Add(dataRow); pfea = pCursor.NextFeature(); j++; } ComReleaser.ReleaseCOMObject(pCursor); } IMosaicLayer pML = new MosaicLayerClass(); pML.CreateFromMosaicDataset(pMds); MapControl.AddLayer(pML as ILayer); MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public void BuildOverview(ref IMosaicDataset theMosaicDataset, bool buildOverviews) { IMosaicDatasetOperation theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); if (buildOverviews) { #region Defining Overviews Console.WriteLine("Defining overviews"); // Create a define overview parameters object. IDefineOverviewsParameters defineOvArgs = new DefineOverviewsParametersClass(); // Use the overview tile parameters interface to specify the overview factor // used to generate overviews. ((IOverviewTileParameters)defineOvArgs).OverviewFactor = 3; // Use the mosaic dataset operation interface to define overviews. theMosaicDatasetOperation.DefineOverviews(defineOvArgs, null); #endregion #region Compute Pixel Size Ranges Console.WriteLine("Computing Pixel Size Ranges"); // Calculate cell size ranges to update the Min/Max pixel sizes. ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass(); theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); #endregion #region Generating Overviews Console.WriteLine("Generating Overviews"); // Create a generate overviews parameters object. IGenerateOverviewsParameters genPars = new GenerateOverviewsParametersClass(); // Set properties to control overview generation. IQueryFilter genQuery = new QueryFilterClass(); ((ISelectionParameters)genPars).QueryFilter = genQuery; genPars.GenerateMissingImages = true; genPars.GenerateStaleImages = true; // Use the mosaic dataset operation interface to generate overviews. theMosaicDatasetOperation.GenerateOverviews(genPars, null); #endregion } }
public bool RebuildMosaicDataset(string mosaicDatasetName) { IMosaicDataset pMosaicDataset = OpenMosaicDataset(GetRastersDBPath(), mosaicDatasetName); IGeoProcessor2 pGP = new GeoProcessorClass(); pGP.AddToolbox(GetToolboxPath()); IVariantArray gpParameters = new VarArrayClass(); gpParameters.Add(pMosaicDataset); IGeoProcessorResult pGeoProcessorResult = pGP.Execute("ReseeBuildMosaicDataset", gpParameters, null); if (pGeoProcessorResult.Status == esriJobStatus.esriJobSucceeded) { return(true); } return(false); }
static void Main(string[] args) { #region Initialize ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null; try { Console.WriteLine("Obtaining license"); ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); aoInit = new AoInitialize(); esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); Console.WriteLine("Ready with license."); } catch (Exception exc) { // If it fails at this point, shutdown the test and ignore any subsequent errors. Console.WriteLine(exc.Message); } #endregion try { // Input database and Mosaic Dataset string MDWorkspaceFolder = @"e:\md\Samples\GetSetKP\RasterSamples.gdb"; string MDName = @"LAC"; // Command line setting of above input if provided. string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.GetLength(0) > 1) { MDWorkspaceFolder = commandLineArgs[1]; MDName = commandLineArgs[2]; } // Open MD Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory mdWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace mdWorkspace = mdWorkspaceFactory.OpenFromFile(MDWorkspaceFolder, 0); IRasterWorkspaceEx workspaceEx = (IRasterWorkspaceEx)(mdWorkspace); IMosaicDataset mosaicDataset = (IMosaicDataset)workspaceEx.OpenRasterDataset(MDName); // Set Mosaic Dataset item information. SetMosaicDatasetItemInformation(mosaicDataset); // Set Key Property 'DataType' on the Mosaic Dataset to value 'Processed' // The change will be reflected on the 'General' page of the mosaic dataset // properties under the 'Source Type' property. SetKeyProperty((IDataset)mosaicDataset, "DataType", "Processed"); // Set the Product Definition on the Mosaic Dataset to 'NATURAL_COLOR_RGB' // First set the 'BandDefinitionKeyword' key property to natural color RGB. SetKeyProperty((IDataset)mosaicDataset, "BandDefinitionKeyword", "NATURAL_COLOR_RGB"); // Then set band names and wavelengths on the mosaic dataset. SetBandProperties((IDataset)mosaicDataset); // Last and most important, refresh the mosaic dataset so the changes are saved. ((IRasterDataset3)mosaicDataset).Refresh(); #region Shutdown Console.WriteLine("Success."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } catch (Exception exc) { #region Shutdown Console.WriteLine("Exception Caught while creating Function Raster Dataset. " + exc.Message); Console.WriteLine("Failed."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } }
public ITable GetMosicTable(IMosaicDataset pMosaic) { ITable pTable = pMosaic.Catalog as ITable; return(pTable); }
public void addRastersToMosaicDataset(IMosaicDataset mosaicDataSet, IRaster[] rasters) { IMosaicDatasetOperation mOp = (IMosaicDatasetOperation)mosaicDataSet; foreach(IRaster rs in rasters) { IAddRastersParameters addRs = new AddRastersParametersClass(); IRasterDatasetCrawler rsDsetCrawl = new RasterDatasetCrawlerClass(); rsDsetCrawl.RasterDataset = ((IRaster2)rs).RasterDataset; IRasterTypeFactory rsFact = new RasterTypeFactoryClass(); IRasterType rsType = rsFact.CreateRasterType("Raster dataset"); rsType.FullName = rsDsetCrawl.DatasetName; addRs.Crawler = (IDataSourceCrawler)rsDsetCrawl; addRs.RasterType = rsType; mOp.AddRasters(addRs, null); } return; }
/// <summary> /// Create a Mosaic Dataset in the geodatabase provided using the parameters defined by MDParamaters. /// </summary> /// <param name="gdbWorkspace">Geodatabase to create the Mosaic dataser in.</param> public void CreateMosaicDataset(IWorkspace gdbWorkspace) { try { #region Global Declarations IMosaicDataset theMosaicDataset = null; IMosaicDatasetOperation theMosaicDatasetOperation = null; IMosaicWorkspaceExtensionHelper mosaicExtHelper = null; IMosaicWorkspaceExtension mosaicExt = null; #endregion #region CreateMosaicDataset try { Console.WriteLine("Create Mosaic Dataset: " + MDParameters.mosaicDatasetName + ".amd"); /// Setup workspaces. /// Create Srs ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass(); // Create the mosaic dataset creation parameters object. ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass(); // Set the number of bands for the mosaic dataset. // If defined as zero leave defaults if (MDParameters.mosaicDatasetBands != 0) { creationPars.BandCount = MDParameters.mosaicDatasetBands; } // Set the pixel type of the mosaic dataset. // If defined as unknown leave defaults if (MDParameters.mosaicDatasetBits != rstPixelType.PT_UNKNOWN) { creationPars.PixelType = MDParameters.mosaicDatasetBits; } // Create the mosaic workspace extension helper class. mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); // Find the right extension from the workspace. mosaicExt = mosaicExtHelper.FindExtension(gdbWorkspace); // Default is none. if (MDParameters.productDefinitionKey.ToLower() != "none") { // Set the product definition keyword and properties. // (The property is called band definition keyword and band properties in the object). ((ICreateMosaicDatasetParameters2)creationPars).BandDefinitionKeyword = MDParameters.productDefinitionKey; MDParameters.productDefinitionProps = SetBandProperties(MDParameters.productDefinitionKey); if (MDParameters.productDefinitionProps.Count == 0) { Console.WriteLine("Setting production definition properties failed."); return; } ((ICreateMosaicDatasetParameters2)creationPars).BandProperties = MDParameters.productDefinitionProps; } // Use the extension to create a new mosaic dataset, supplying the // spatial reference and the creation parameters object created above. theMosaicDataset = mosaicExt.CreateMosaicDataset(MDParameters.mosaicDatasetName, MDParameters.mosaicDatasetSrs, creationPars, MDParameters.configKeyword); } catch (Exception exc) { Console.WriteLine("Exception Caught while creating Mosaic Dataset: " + exc.Message); return; } #endregion #region OpenMosaicDataset Console.WriteLine("Opening Mosaic Dataset"); theMosaicDataset = null; // Use the extension to open the mosaic dataset. theMosaicDataset = mosaicExt.OpenMosaicDataset(MDParameters.mosaicDatasetName); // The mosaic dataset operation interface is used to perform operations on // a mosaic dataset. theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); #endregion #region Preparing Raster Type Console.WriteLine("Preparing Raster Type"); // Create a Raster Type Name object. IRasterTypeName theRasterTypeName = new RasterTypeNameClass(); // Assign the name of the Raster Type to the name object. // The Name field accepts a path to an .art file as well // the name for a built in Raster Type. theRasterTypeName.Name = MDParameters.rasterTypeName; // Use the Open function from the IName interface to get the Raster Type object. IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open()); if (theRasterType == null) { Console.WriteLine("Raster Type not found " + MDParameters.rasterTypeName); } // Set the URI Filter on the loaded raster type. if (MDParameters.rasterTypeProductFilter != "") { // Get the supported URI filters from the raster type object using the // raster type properties interface. IArray mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters; IItemURIFilter productFilter = null; for (int i = 0; i < mySuppFilters.Count; ++i) { // Set the desired filter from the supported filters. productFilter = (IItemURIFilter)mySuppFilters.get_Element(i); if (productFilter.Name == MDParameters.rasterTypeProductFilter) { theRasterType.URIFilter = productFilter; } } } // Enable the correct templates in the raster type. string[] rasterProductNames = MDParameters.rasterTypeProductName.Split(';'); bool enableTemplate = false; if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != "")) { // Get the supported item templates from the raster type. IItemTemplateArray templateArray = theRasterType.ItemTemplates; for (int i = 0; i < templateArray.Count; ++i) { // Go through the supported item templates and enable the ones needed. IItemTemplate template = templateArray.get_Element(i); enableTemplate = false; for (int j = 0; j < rasterProductNames.Length; ++j) { if (template.Name == rasterProductNames[j]) { enableTemplate = true; } } if (enableTemplate) { template.Enabled = true; } else { template.Enabled = false; } } } if (MDParameters.dataSourceSrs != null) { ((IRasterTypeProperties)theRasterType).SynchronizeParameters.DefaultSpatialReference = MDParameters.dataSourceSrs; } #endregion #region Add DEM To Raster Type if (MDParameters.rasterTypeAddDEM && ((IRasterTypeProperties)theRasterType).SupportsOrthorectification) { // Open the Raster Dataset Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile( System.IO.Path.GetDirectoryName(MDParameters.rasterTypeDemPath), 0);; IRasterDataset myRasterDataset = rasterWorkspace.OpenRasterDataset( System.IO.Path.GetFileName(MDParameters.rasterTypeDemPath)); IGeometricFunctionArguments geometricFunctionArguments = new GeometricFunctionArgumentsClass(); geometricFunctionArguments.DEM = myRasterDataset; ((IRasterTypeProperties)theRasterType).OrthorectificationParameters = geometricFunctionArguments; } #endregion #region Preparing Data Source Crawler Console.WriteLine("Preparing Data Source Crawler"); // Create a new property set to specify crawler properties. IPropertySet crawlerProps = new PropertySetClass(); // Specify a file filter crawlerProps.SetProperty("Filter", MDParameters.dataSourceFilter); // Specify whether to search subdirectories. crawlerProps.SetProperty("Recurse", true); // Specify the source path. crawlerProps.SetProperty("Source", MDParameters.dataSource); // Get the recommended crawler from the raster type based on the specified // properties using the IRasterBuilder interface. IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps); #endregion #region Add Rasters Console.WriteLine("Adding Rasters"); // Create a AddRaster parameters object. IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); // Specify the data crawler to be used to crawl the data. AddRastersArgs.Crawler = theCrawler; // Specify the raster type to be used to add the data. AddRastersArgs.RasterType = theRasterType; // Use the mosaic dataset operation interface to add // rasters to the mosaic dataset. theMosaicDatasetOperation.AddRasters(AddRastersArgs, null); #endregion #region Compute Pixel Size Ranges Console.WriteLine("Computing Pixel Size Ranges"); // Create a calculate cellsize ranges parameters object. ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass(); // Use the mosaic dataset operation interface to calculate cellsize ranges. theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); #endregion #region Building Boundary Console.WriteLine("Building Boundary"); // Create a build boundary parameters object. IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass(); // Set flags that control boundary generation. boundaryArgs.AppendToExistingBoundary = true; // Use the mosaic dataset operation interface to build boundary. theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null); #endregion if (MDParameters.buildOverviews) { #region Defining Overviews Console.WriteLine("Defining Overviews"); // Create a define overview parameters object. IDefineOverviewsParameters defineOvArgs = new DefineOverviewsParametersClass(); // Use the overview tile parameters interface to specify the overview factor // used to generate overviews. ((IOverviewTileParameters)defineOvArgs).OverviewFactor = 3; // Use the mosaic dataset operation interface to define overviews. theMosaicDatasetOperation.DefineOverviews(defineOvArgs, null); #endregion #region Compute Pixel Size Ranges Console.WriteLine("Computing Pixel Size Ranges"); // Calculate cell size ranges to update the Min/Max pixel sizes. theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); #endregion #region Generating Overviews Console.WriteLine("Generating Overviews"); // Create a generate overviews parameters object. IGenerateOverviewsParameters genPars = new GenerateOverviewsParametersClass(); // Set properties to control overview generation. IQueryFilter genQuery = new QueryFilterClass(); ((ISelectionParameters)genPars).QueryFilter = genQuery; genPars.GenerateMissingImages = true; genPars.GenerateStaleImages = true; // Use the mosaic dataset operation interface to generate overviews. theMosaicDatasetOperation.GenerateOverviews(genPars, null); #endregion } #region Report Console.WriteLine("Success."); #endregion } catch (Exception exc) { #region Report Console.WriteLine("Exception Caught in CreateMD: " + exc.Message); Console.WriteLine("Shutting down."); #endregion } }
public static void TestThumbnailBuilder(string rasterTypeName, string rasterTypeProductFilter, string rasterTypeProductName, string dataSource, string dataSourceFilter, string fgdbParentFolder, bool saveToArt, string customTypeFilePath, bool clearGdbDirectory) { try { string[] rasterProductNames = rasterTypeProductName.Split(';'); string nameString = rasterTypeName.Replace(" ", "") + rasterTypeProductFilter.Replace(" ", "") + rasterProductNames[0].Replace(" ", ""); #region Directory Declarations string fgdbName = nameString + ".gdb"; string fgdbDir = fgdbParentFolder + "\\" + fgdbName; string MosaicDatasetName = nameString + "MD"; #endregion #region Global Declarations IMosaicDataset theMosaicDataset = null; IMosaicDatasetOperation theMosaicDatasetOperation = null; IMosaicWorkspaceExtensionHelper mosaicExtHelper = null; IMosaicWorkspaceExtension mosaicExt = null; #endregion #region Create File GDB Console.WriteLine("Creating File GDB: " + fgdbName); if (clearGdbDirectory) { try { Console.WriteLine("Emptying Gdb folder."); System.IO.Directory.Delete(fgdbParentFolder, true); System.IO.Directory.CreateDirectory(fgdbParentFolder); } catch (System.IO.IOException EX) { Console.WriteLine(EX.Message); return; } } // Create a File Gdb Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory FgdbFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); FgdbFactory.Create(fgdbParentFolder, fgdbName, null, 0); #endregion #region Create Mosaic Dataset try { Console.WriteLine("Create Mosaic Dataset: " + MosaicDatasetName); // Setup workspaces. IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(fgdbDir, 0); // Create Srs ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference mosaicSrs = spatialrefFactory.CreateProjectedCoordinateSystem( (int)(esriSRProjCSType.esriSRProjCS_World_Mercator)); // Create the mosaic dataset creation parameters object. ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass(); // Create the mosaic workspace extension helper class. mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); // Find the right extension from the workspace. mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace); // Use the extension to create a new mosaic dataset, supplying the // spatial reference and the creation parameters object created above. theMosaicDataset = mosaicExt.CreateMosaicDataset(MosaicDatasetName, mosaicSrs, creationPars, ""); theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset); } catch (Exception exc) { Console.WriteLine("Error: Failed to create Mosaic Dataset : {0}.", MosaicDatasetName + " " + exc.Message); return; } #endregion #region Create Custom Raster Type Console.WriteLine("Preparing Raster Type"); // Create a Raster Type Name object. IRasterTypeName theRasterTypeName = new RasterTypeNameClass(); // Assign the name of the Raster Type to the name object. // The Name field accepts a path to an .art file as well // the name for a built in Raster Type. theRasterTypeName.Name = rasterTypeName; // Use the Open function from the IName interface to get the Raster Type object. IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open()); if (theRasterType == null) { Console.WriteLine("Error:Raster Type not found " + rasterTypeName); return; } #endregion #region Prepare Raster Type // Set the URI Filter on the loaded raster type. if (rasterTypeProductFilter != "") { // Get the supported URI filters from the raster type object using the // raster type properties interface. IArray mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters; IItemURIFilter productFilter = null; for (int i = 0; i < mySuppFilters.Count; ++i) { // Set the desired filter from the supported filters. productFilter = (IItemURIFilter)mySuppFilters.get_Element(i); if (productFilter.Name == rasterTypeProductFilter) { theRasterType.URIFilter = productFilter; } } } // Enable the correct templates in the raster type. bool enableTemplate = false; if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != "")) { // Get the supported item templates from the raster type. IItemTemplateArray templateArray = theRasterType.ItemTemplates; for (int i = 0; i < templateArray.Count; ++i) { // Go through the supported item templates and enable the ones needed. IItemTemplate template = templateArray.get_Element(i); enableTemplate = false; for (int j = 0; j < rasterProductNames.Length; ++j) { if (template.Name == rasterProductNames[j]) { enableTemplate = true; } } if (enableTemplate) { template.Enabled = true; } else { template.Enabled = false; } } } ((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter; #endregion #region Save Custom Raster Type if (saveToArt) { IRasterTypeProperties rasterTypeProperties = (IRasterTypeProperties)theRasterType; IRasterTypeEnvironment rasterTypeHelper = new RasterTypeEnvironmentClass(); rasterTypeProperties.Name = customTypeFilePath; IMemoryBlobStream ipBlob = rasterTypeHelper.SaveRasterType(theRasterType); ipBlob.SaveToFile(customTypeFilePath); } #endregion #region Preparing Data Source Crawler Console.WriteLine("Preparing Data Source Crawler"); // Create a new property set to specify crawler properties. IPropertySet crawlerProps = new PropertySetClass(); // Specify a file filter crawlerProps.SetProperty("Filter", dataSourceFilter); // Specify whether to search subdirectories. crawlerProps.SetProperty("Recurse", true); // Specify the source path. crawlerProps.SetProperty("Source", dataSource); // Get the recommended crawler from the raster type based on the specified // properties using the IRasterBuilder interface. // Pass on the Thumbnailtype to the crawler... IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps); #endregion #region Add Rasters try { Console.WriteLine("Adding Rasters"); // Create a AddRaster parameters object. IAddRastersParameters AddRastersArgs = new AddRastersParametersClass(); // Specify the data crawler to be used to crawl the data. AddRastersArgs.Crawler = theCrawler; // Specify the Thumbnail raster type to be used to add the data. AddRastersArgs.RasterType = theRasterType; // Use the mosaic dataset operation interface to add // rasters to the mosaic dataset. theMosaicDatasetOperation.AddRasters(AddRastersArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Add raster Failed." + ex.Message); return; } #endregion #region Compute Pixel Size Ranges Console.WriteLine("Computing Pixel Size Ranges."); try { // Create a calculate cellsize ranges parameters object. ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass(); // Use the mosaic dataset operation interface to calculate cellsize ranges. theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Compute Pixel Size Failed." + ex.Message); return; } #endregion #region Building Boundary Console.WriteLine("Building Boundary"); try { // Create a build boundary parameters object. IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass(); // Set flags that control boundary generation. boundaryArgs.AppendToExistingBoundary = true; // Use the mosaic dataset operation interface to build boundary. theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null); } catch (Exception ex) { Console.WriteLine("Error: Build Boundary Failed." + ex.Message); return; } #endregion #region Report Console.WriteLine("Successfully created MD: " + MosaicDatasetName + ". "); #endregion } catch (Exception exc) { #region Report Console.WriteLine("Exception Caught in TestThumbnailBuilder: " + exc.Message); Console.WriteLine("Failed."); Console.WriteLine("Shutting down."); #endregion } }
public ITable GetMosicTable(IMosaicDataset pMosaic) { ITable pTable = pMosaic.Catalog as ITable; return pTable; }
public ITable GetMosaicDatasetTable(IMosaicDataset pMosaicDataset) { ITable pTable = null; IEnumName pEnumName = pMosaicDataset.Children; pEnumName.Reset(); ESRI.ArcGIS.esriSystem.IName pName; while ((pName = pEnumName.Next()) != null) { pTable = pName.Open() as ITable; int i = pTable.Fields.FieldCount; if (i >= 21) break; }//镶嵌数据集属性表默认23个字段 } return pTable; }
public bool ExistRow(IMosaicDataset pMosaic,string pValue) { ITable pTable= GetMosicTable(pMosaic); IQueryFilter pQueryFileter = new QueryFilterClass();//sevp_aoc_rdcp_sldas_ebref_achn_l88_pi_201212050010 pQueryFileter.SubFields = "Name"; pQueryFileter.WhereClause = "Name =" + pValue; if (pTable.RowCount(pQueryFileter) > 0) return true; return false; }
/// <summary> /// Sets band information on items in a mosaic dataset /// </summary> /// <param name="md">The mosaic dataset with the items</param> private static void SetMosaicDatasetItemInformation(IMosaicDataset md) { // Get the Attribute table from the Mosaic Dataset. IFeatureClass featureClass = md.Catalog; ISchemaLock schemaLock = (ISchemaLock)featureClass; IRasterDataset3 rasDs = null; try { // A try block is necessary, as an exclusive lock might not be available. schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); // Get an update cursor going through all the rows in the Moasic Dataset. IFeatureCursor fcCursor = featureClass.Update(null, false); // Alternatively, a read cursor can be used if the item does not need to be changed. // featureClass.Search(null, false); // For each row, IRasterCatalogItem rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature(); while (rasCatItem != null) { // get the functionrasterdataset from the Raster field. IFunctionRasterDataset funcDs = (IFunctionRasterDataset)rasCatItem.RasterDataset; if (funcDs != null) { // Check if the 'BandName' property exists in the dataset. bool propertyExists = false; for (int bandID = 0; bandID < funcDs.RasterInfo.BandCount; ++bandID) { object bandNameProperty = null; bandNameProperty = GetBandProperty((IDataset)funcDs, "BandName", bandID); if (bandNameProperty != null) propertyExists = true; } if (propertyExists == false && funcDs.RasterInfo.BandCount > 2) { // If the property does not exist and the dataset has atleast 3 bands, // set Band Definition Properties for first 3 bands of the dataset. SetBandProperties((IDataset)funcDs); funcDs.AlterDefinition(); rasDs = (IRasterDataset3)funcDs; // Refresh the dataset. rasDs.Refresh(); } } fcCursor.UpdateFeature((IFeature)rasCatItem); rasDs = null; rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature(); } rasCatItem = null; fcCursor = null; featureClass = null; } catch (Exception exc) { Console.WriteLine("Exception Caught in SetMosaicDatasetItemInformation: " + exc.Message); } finally { // Set the lock to shared, whether or not an error occurred. schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
/// <summary> /// Sets band information on items in a mosaic dataset /// </summary> /// <param name="md">The mosaic dataset with the items</param> private static void SetMosaicDatasetItemInformation(IMosaicDataset md) { // Get the Attribute table from the Mosaic Dataset. IFeatureClass featureClass = md.Catalog; ISchemaLock schemaLock = (ISchemaLock)featureClass; IRasterDataset3 rasDs = null; try { // A try block is necessary, as an exclusive lock might not be available. schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); // Get an update cursor going through all the rows in the Moasic Dataset. IFeatureCursor fcCursor = featureClass.Update(null, false); // Alternatively, a read cursor can be used if the item does not need to be changed. // featureClass.Search(null, false); // For each row, IRasterCatalogItem rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature(); while (rasCatItem != null) { // get the functionrasterdataset from the Raster field. IFunctionRasterDataset funcDs = (IFunctionRasterDataset)rasCatItem.RasterDataset; if (funcDs != null) { // Check if the 'BandName' property exists in the dataset. bool propertyExists = false; for (int bandID = 0; bandID < funcDs.RasterInfo.BandCount; ++bandID) { object bandNameProperty = null; bandNameProperty = GetBandProperty((IDataset)funcDs, "BandName", bandID); if (bandNameProperty != null) { propertyExists = true; } } if (propertyExists == false && funcDs.RasterInfo.BandCount > 2) { // If the property does not exist and the dataset has atleast 3 bands, // set Band Definition Properties for first 3 bands of the dataset. SetBandProperties((IDataset)funcDs); funcDs.AlterDefinition(); rasDs = (IRasterDataset3)funcDs; // Refresh the dataset. rasDs.Refresh(); } } fcCursor.UpdateFeature((IFeature)rasCatItem); rasDs = null; rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature(); } rasCatItem = null; fcCursor = null; featureClass = null; } catch (Exception exc) { Console.WriteLine("Exception Caught in SetMosaicDatasetItemInformation: " + exc.Message); } finally { // Set the lock to shared, whether or not an error occurred. schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
public void CanOpenRasterFileFromMosaicDatasetUsingSpatialQueryGdal_Learning() { // TODO: Corrext GDAL native reference. Work-around: copy the x64 directory to the output dir IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle(); IMosaicDataset mosaicDataset = DatasetUtils.OpenMosaicDataset(workspace, "TOPGIS_TLM.TLM_DTM_MOSAIC"); IFeatureClass rasterCatalog = mosaicDataset.Catalog; IPoint winterthurLL = GeometryFactory.CreatePoint( 2690021, 1254011, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)); IQueryFilter spatialFilter = GdbQueryUtils.CreateSpatialFilter(rasterCatalog, winterthurLL); Gdal.AllRegister(); IStringArray stringArray; Stopwatch watch = Stopwatch.StartNew(); List <IFeature> features = GdbQueryUtils.GetFeatures( rasterCatalog, spatialFilter, false).ToList(); Assert.True(features.Count > 0); var itemPathsQuery = (IItemPathsQuery)mosaicDataset; itemPathsQuery.QueryPathsParameters = new QueryPathsParametersClass(); stringArray = itemPathsQuery.GetItemPaths(features[0]); string rasterPath = stringArray.Element[0]; Dataset ds = Gdal.Open(rasterPath, Access.GA_ReadOnly); if (ds == null) { Console.WriteLine("Can't open " + rasterPath); return; } Console.WriteLine("Raster dataset parameters:"); Console.WriteLine(" Projection: " + ds.GetProjectionRef()); Console.WriteLine(" RasterCount: " + ds.RasterCount); Console.WriteLine(" RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")"); double[] adfGeoTransform = new double[6]; ds.GetGeoTransform(adfGeoTransform); double originX = adfGeoTransform[0]; double originY = adfGeoTransform[3]; Console.WriteLine($"Origin: {originX} | {originY}"); double pixelSizeX = adfGeoTransform[1]; double pixelSizeY = adfGeoTransform[5]; Console.WriteLine($"Pixel Size: {pixelSizeX} | {pixelSizeY}"); /* -------------------------------------------------------------------- */ /* Get driver */ /* -------------------------------------------------------------------- */ Driver drv = ds.GetDriver(); if (drv == null) { Console.WriteLine("Can't get driver."); Environment.Exit(-1); } Console.WriteLine("Using driver " + drv.LongName); /* -------------------------------------------------------------------- */ /* Get raster band */ /* -------------------------------------------------------------------- */ for (int iBand = 1; iBand <= ds.RasterCount; iBand++) { Band band = ds.GetRasterBand(iBand); Console.WriteLine("Band " + iBand + " :"); Console.WriteLine(" DataType: " + band.DataType); Console.WriteLine(" Size (" + band.XSize + "," + band.YSize + ")"); Console.WriteLine(" PaletteInterp: " + band.GetRasterColorInterpretation().ToString()); band.GetBlockSize(out int blockSizeX, out int blockSizeY); Console.WriteLine(" Block Size (" + blockSizeX + "," + blockSizeY + ")"); for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++) { Band over = band.GetOverview(iOver); Console.WriteLine(" OverView " + iOver + " :"); Console.WriteLine(" DataType: " + over.DataType); Console.WriteLine(" Size (" + over.XSize + "," + over.YSize + ")"); Console.WriteLine(" PaletteInterp: " + over.GetRasterColorInterpretation()); } // Get the value at winterthurLL: int pxlOffsetX = (int)Math.Floor((winterthurLL.X - originX) / pixelSizeX); int pxlOffsetY = (int)Math.Floor((winterthurLL.Y - originY) / pixelSizeY); double[] buffer = new double[1]; band.ReadRaster(pxlOffsetX, pxlOffsetY, 1, 1, buffer, 1, 1, 0, 0); double z = buffer[0]; // TODO: Theoretically there is an underlying block cache which would make subsequent // reads in a similar area very fast (TEST!) - probably the same as IRaster behaviour. // TODO: Bilinear interpolation if it's not the middle of a pixel! Console.WriteLine("Z value at {0}, {1}: {2}", winterthurLL.X, winterthurLL.Y, z); } }
public DMCIIRasterBuilder() { myMosaicDataset = null; myDefaultSpatialReference = null; myRasterTypeOperation = null; myRasterTypeProperties = null; myTrackCancel = null; myURIArray = null; myGeoTransformationHelper = null; myCanMergeItems = false; myMergeItems = false; myAuxiliaryFieldAlias = null; myAuxiliaryFields = null; myUID = new UIDClass(); myUID.Value = "{316725CB-35F2-4159-BEBB-A1445ECE9CF1}"; }