Ejemplo n.º 1
0
 static void Main()
 {
     ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
     ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
     ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngine);
     ao.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Form1());
 }
Ejemplo n.º 2
0
        static void Main()
        {
            // Bind this ArcObjects application to this machine's ArcGIS license
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
            // Fetch the License
            ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
            esriLicenseStatus status = ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeStandard);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Ejemplo n.º 3
0
    public static void InitializeArcObjects()
    {
        try
        {
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
            //采用代码初始化License

            /*            IAoInitialize m_AoInitialize = new AoInitializeClass();
             *          esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
             *          licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);*/
            ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
            ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeStandard);
        }
        catch (Exception)
        {
        }
    }
Ejemplo n.º 4
0
        static void Main()
        {
            if (!RuntimeManager.Bind(ProductCode.Desktop))
            {
                if (!RuntimeManager.Bind(ProductCode.Engine))
                {
                    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }

            ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
            ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeAdvanced);

            Enable3DAnalysis(); //avoid "The 3D Analyst extension has not been enabled"

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrmContinuousGeneralizer());
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Initialize the license
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                Console.WriteLine("Obtaining license");
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
                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


            //Coordinate system for raster column
            IGPCoordinateSystem rSR = new GPCoordinateSystemClass();
            rSR.SpatialReference = CreateSpatialReference((int)esriSRProjCSType.esriSRProjCS_World_Mercator);
            //Coordinate system for geometry column
            IGPSpatialReference gSR = new GPSpatialReferenceClass();
            gSR.SpatialReference = CreateSpatialReference((int)esriSRProjCSType.esriSRProjCS_World_Mercator);

            //Creates raster catalog
            CreateRasterCatalog_GP(rSR, gSR);

            //Loads rasters in the given directory to raster catalog
            LoadDirToRasterCatalog(outRC, rasterFolder);
            System.Console.WriteLine("Loading completed");

            System.Console.ReadLine();//waiting user to click a key to finish

            //Do not make any call to ArcObjects after license is shut down.
            aoInit.Shutdown();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
                Console.WriteLine("License Checkout successful.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
            }

            try
            {
                //Create temporary unmanaged raster catalog and load all rasters
                CreateUnmanagedRasterCatalog();

                //Open raster catalog
                IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)OpenRasterPGDBWorkspace(tempPGDBPath);
                IRasterCatalog     rasterCatalog     = rasterWorkspaceEx.OpenRasterCatalog(tempRasterCatalog);

                //Mosaic rasters in the raster catalog
                Mosaic(rasterCatalog);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            Console.Write("Please press any key to close the application.");
            Console.ReadKey();

            //Do not make any call to ArcObjects after ShutDown() call
            aoInit.Shutdown();
        }
        static void Main(string[] args)
        {
            //If creating a raster dataset in ArcSDE, it will need Standard or Advanced License
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
                Console.WriteLine("License Checkout successful.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
            }

            try
            {
                //Creates an empty raster dataset
                //Make sure parameters of the empty raster dataset match our data (number of bands, bit depth, etc.)
                CreateRasterDS();

                //Loads rasters in the input folder to the new raster dataset
                LoadDirToRasterDataset(FGDBPath + "\\" + dsName, rasterFolder);
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
            }

            Console.Write("Please press any key to close the application.");
            Console.ReadKey();

            //Do not make any call to ArcObjects after ShutDown()
            aoInit.Shutdown();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // Don't show the "program stopped working" popup if a file/path cannot be opened
            AppDomain.CurrentDomain.UnhandledException += (sender, eargs) =>
            {
                Console.Error.WriteLine("Unhandled exception: " + eargs.ExceptionObject);
                Environment.Exit(1);
            };

            // The user must specify the root path to be explored (i.e. a path containing File GeoDatabases (*.gdb)
            // as well as an output csv file
            if (args.Length != 3)
            {
                usageExit();
            }
            else
            {
                // Bind this ArcObjects application to this machine's ArcGIS license
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                // Fetch the License
                ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
                esriLicenseStatus status = ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeStandard);

                string option   = args[0];
                string rootPath = args[1]; // Target path is the first argument of the console application
                string outfile  = args[2]; // Output CSV file is the second argument
                outfile = toCSVPath(outfile);

                switch (option)
                {
                case "-p":     // Path to a File GeoDatabase
                    testFGDBPath(rootPath);
                    Console.WriteLine("Processing... please wait.");
                    printCSVHeader(outfile);
                    exploreFGDB(rootPath, outfile);
                    break;

                case "-P":     // Path to a File GeoDatabase
                    testFGDBPath(rootPath);
                    Console.WriteLine("Processing... please wait.");
                    printCSVHeader(outfile);
                    exploreFGDB(rootPath, outfile);
                    break;

                case "-r":     // Root directory that contains File GeoDatabases
                    exploreRootDirectory(rootPath, outfile);
                    break;

                case "-R":     // Root directory that contains File GeoDatabases
                    exploreRootDirectory(rootPath, outfile);
                    break;

                default:
                    usageExit();
                    break;
                }

                Console.WriteLine("Done Processing.");
                System.Environment.Exit(0);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            #region Initialize License
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                Console.WriteLine("Obtaining license");
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                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
            {
                #region Setup MD Parameters
                MDParameters.gdbParentFolder = @"e:\MD\CustomRasterType\DMCII";
                // Choose which type of gdb to create/open.
                // 0 - Create File Gdb
                // 1 - Create Personal Gdb
                // 2 - Open SDE
                int gdbOption = 0;
                // Provide the proper extension based on the gdb you want to create.
                // e.g. MDParameters.gdbName = "samplePGdb.mdb" to create a personal gdb.
                // To use an SDE, set SDE connection properties below.
                MDParameters.gdbName           = @"CustomTypeGdb.gdb";
                MDParameters.mosaicDatasetName = @"CustomTypeMD";

                // Specify the srs of the mosaic dataset
                ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();
                MDParameters.mosaicDatasetSrs = spatialrefFactory.CreateProjectedCoordinateSystem(
                    (int)(esriSRProjCSType.esriSRProjCS_World_Mercator));

                // 0 and PT_UNKNOWN for bits and bands = use defaults.
                MDParameters.mosaicDatasetBands = 0;
                MDParameters.mosaicDatasetBits  = rstPixelType.PT_UNKNOWN;
                MDParameters.configKeyword      = "";

                // Product Definition key choices:
                // None
                // NATURAL_COLOR_RGB
                // NATURAL_COLOR_RGBI
                // FALSE_COLOR_IRG
                // FORMOSAT-2_4BANDS
                // GEOEYE-1_4BANDS
                // IKONOS_4BANDS
                // KOMPSAT-2_4BANDS
                // LANDSAT_6BANDS
                // LANDSAT_MSS_4BANDS
                // QUICKBIRD_4BANDS
                // RAPIDEYE_5BANDS
                // SPOT-5_4BANDS
                // WORLDVIEW-2_8BANDS

                // Setting this property ensures any data added to the MD with its
                // metadata defined gets added with the correct band combination.
                MDParameters.productDefinitionKey = "FALSE_COLOR_IRG";

                MDParameters.rasterTypeName = "DMCIIRasterType";
                // The next two properties can be left blank for defaults
                // The product filter defines which specific product of the raster
                // type to add, e.g. To specfiy Quickbird Basic use value "Basic"
                MDParameters.rasterTypeProductFilter = "";
                // The product name specifies which template to use when adding data.
                // e.g. "Pansharpen and Multispectral" means both multispectral and
                // pansharpened rasters are added to the mosaic dataset.
                MDParameters.rasterTypeProductName = "Raw";

                // Data source from which to read the data.
                MDParameters.dataSource       = @"F:\Data\DMCii";
                MDParameters.dataSourceFilter = @"";
                // No need to set if data source has an srs or if you want to use the MD srs as data source srs.
                MDParameters.dataSourceSrs = null;

                MDParameters.buildOverviews = false;
                #endregion

                MDParameters.emptyGdbFolder        = false;
                MDParameters.createGdbParentFolder = false;
                #region Empty/Create Output Directory
                if (MDParameters.emptyGdbFolder)
                {
                    try
                    {
                        Console.WriteLine("Emptying Output Directory");
                        Directory.Delete(MDParameters.gdbParentFolder, true);
                        Directory.CreateDirectory(MDParameters.gdbParentFolder);
                    }
                    catch (Exception)
                    {
                    }
                }
                if (MDParameters.createGdbParentFolder && !System.IO.Directory.Exists(MDParameters.gdbParentFolder))
                {
                    Console.WriteLine("Creating Output Directory");
                    Directory.CreateDirectory(MDParameters.gdbParentFolder);
                }
                #endregion

                CreateMD createMD = new CreateMD();

                if (gdbOption == 0)
                {
                    #region Create MD in File GDB
                    Console.WriteLine("Creating File GDB: " + MDParameters.gdbName);
                    IWorkspace fgdbWorkspace = CreateFileGdbWorkspace(MDParameters.gdbParentFolder, MDParameters.gdbName);
                    createMD.CreateMosaicDataset(fgdbWorkspace);
                    #endregion
                }
                else if (gdbOption == 1)
                {
                    #region Create MD in Personal GDB
                    Console.WriteLine("Creating Personal GDB: " + MDParameters.gdbName);
                    IWorkspace pGdbWorkspace = CreateAccessWorkspace(MDParameters.gdbParentFolder, MDParameters.gdbName);
                    createMD.CreateMosaicDataset(pGdbWorkspace);
                    #endregion
                }
                else if (gdbOption == 2)
                {
                    #region Open SDE GDB
                    // Set SDE connection properties.
                    IPropertySet sdeProperties = new PropertySetClass();
                    sdeProperties.SetProperty("SERVER", "barbados");
                    sdeProperties.SetProperty("INSTANCE", "9411");
                    sdeProperties.SetProperty("VERSION", "sde.DEFAULT");
                    sdeProperties.SetProperty("USER", "gdb");
                    sdeProperties.SetProperty("PASSWORD", "gdb");
                    sdeProperties.SetProperty("DATABASE", "VTEST");
                    IWorkspace sdeWorkspace = CreateSdeWorkspace(sdeProperties);
                    if (sdeWorkspace == null)
                    {
                        Console.WriteLine("Could not open SDE workspace: ");
                        return;
                    }

                    #endregion

                    #region Create MD in SDE
                    MDParameters.mosaicDatasetName = @"sampleMD";
                    createMD.CreateMosaicDataset(sdeWorkspace);
                    #endregion
                }

                #region Shutdown
                Console.WriteLine("Press any key...");
                Console.ReadKey();
                // Shutdown License
                aoInit.Shutdown();
                #endregion
            }
            catch (Exception exc)
            {
                #region Report
                Console.WriteLine("Exception Caught in Main: " + exc.Message);
                Console.WriteLine("Shutting down.");
                #endregion

                #region Shutdown
                Console.WriteLine("Press any key...");
                Console.ReadKey();
                // Shutdown License
                aoInit.Shutdown();
                #endregion
            }
        }
        static void Main()
        {
            #region Initialize license
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
                Console.WriteLine("License Checkout successful.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
            }
            #endregion
            try
            {
                //Get the location for data installed with .net sdk
                string          versionInfo  = RuntimeManager.ActiveRuntime.Version;
                RegistryKey     regKey       = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcObjectsSDK" + versionInfo + @"\.NET");
                string          path         = System.Convert.ToString(regKey.GetValue("MainDir"));
                string          rasterFolder = System.IO.Path.Combine(path, @"Samples\ArcObjectsNET\CustomNodataFilter");
                IPixelOperation raster       = (IPixelOperation)OpenRasterDataset(rasterFolder, "testimage.tif");

                if (raster == null)
                {
                    Console.WriteLine("invalid raster");
                    return;
                }

                //create nodatafilter and set properties
                CustomNodataFilter.INodataFilter nFilter = new CustomNodataFilter.NodataFilter();

                //filter out all values between 0 and 50 as nodata
                nFilter.MinNodataValue = 0;
                nFilter.MaxNodataValue = 50;

                //apply the convolutionfilter to raster
                raster.PixelFilter = nFilter;

                //set nodata value using the minimum of the nodata range
                IRasterProps rasterProps = (IRasterProps)raster;
                rasterProps.NoDataValue = 0;

                //save the filtered raster to a new raster dataset in TEMP directory
                ISaveAs saveAs = (ISaveAs)raster;
                //IWorkspace workspace = OpenWorkspace(Environment.GetEnvironmentVariable("TEMP"));
                IWorkspace workspace = OpenWorkspace(rasterFolder);
                saveAs.SaveAs("nodata.tif", workspace, "TIFF");

                Console.WriteLine("Completed");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDown()
            aoInit.Shutdown();
        }
Ejemplo n.º 11
0
        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
            }
        }