Example #1
0
        static void Main()
        {
            if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.ArcReader))
            {
                if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop))
                {
                    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }

            LicenseInitializer aoLicenseInitializer = new LicenseInitializer();
            if (!aoLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeArcView, esriLicenseProductCode.esriLicenseProductCodeArcEditor, esriLicenseProductCode.esriLicenseProductCodeArcInfo },
            new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork }))
            {
                System.Windows.Forms.MessageBox.Show("This application could not initialize with the correct ArcGIS license and will shutdown. LicenseMessage: " + aoLicenseInitializer.LicenseMessage());
                aoLicenseInitializer.ShutdownApplication();
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            aoLicenseInitializer.ShutdownApplication();
        }
Example #2
0
 protected void ShutdownLicense()
 {
     if (_licenseInitializer != null)
     {
         _licenseInitializer.ShutdownApplication();
     }
 }
Example #3
0
        static void Main()
        {
            try
            {
                //Process process = Common.ProcessCheck.RuningInstance();
                //if (process != null)
                //{
                //    Common.ProcessCheck.HandleRunningInstance(process);
                //    //System.Threading.Thread.Sleep(1000);
                //    System.Environment.Exit(1);
                //}
                Application.SetCompatibleTextRenderingDefault(false);
                Application.EnableVisualStyles();

                bool licensed = m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                                             new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst });
                if (!licensed)
                {
                    MessageBox.Show(m_AOLicenseInitializer.LicenseMessage(), "初始化许可失败", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                frmLogin login = new frmLogin();
                if (DialogResult.OK == login.ShowDialog())
                {
                    Application.Run(new frmMain());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "启动失败!");
            }
            finally
            {
                m_AOLicenseInitializer.ShutdownApplication();
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
                                                         new esriLicenseExtensionCode[] { });


            if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine))
            {
                if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop))
                {
                    Console.WriteLine("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }

            m_AOLicenseInitializer.ShutdownApplication();


            //SqlServer m_SqlServer = new SqlServer();
            //m_SqlServer.mySqlOpenCon();
            //m_SqlServer.filepath= @"./testFD.txt";
            //m_SqlServer.readSqlData();
            //m_SqlServer.mySqlColseCon();

            Program p = new Program();

            p.LoadBigTxt("testFD.txt", 1);//大文件(文件位置,起始读取行数)
        }
Example #5
0
        static void Main()
        {
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
                                                         new esriLicenseExtensionCode[] { });


            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.LookAndFeel.UserLookAndFeel.Default.UseWindowsXPTheme = false;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.Style             = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName          = "Black";

            RibbonReportDesigner.SplashScreen.Splasher.Show(typeof(WHC.OrderWater.ServerSide.SplashScreen.frmSplash));

            MainForm mainForm = new MainForm();

            mainForm.CreateNewReport();
            Application.Run(mainForm);

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Example #6
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                         new esriLicenseExtensionCode[] { });
            //ESRI License Initializer generated code.


            //Get a path to the raster workspace and create a RasterWorkspace object
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            IRasterWorkspace2 rasterWorkspace  = (IRasterWorkspace2)workspaceFactory.OpenFromFile("\\\\Filepath\\ToRaster\\Folder", 0);
            IRasterDataset    rasterDataset    = rasterWorkspace.OpenRasterDataset("DEM_Resample.tif");

            //Create a raster layer to get the raster object from it
            IRasterLayer rasterLayer = new RasterLayer();

            rasterLayer.CreateFromDataset(rasterDataset);
            IRaster raster = rasterLayer.Raster;

            //Get the raster properties so we can modify them later and get details about them if we so choose.
            IRasterProps rasterProps = raster as IRasterProps;
            double       cellSize    = 60;

            //Declate a new spatial reference if you want to change the spatial reference used.
            ISpatialReferenceFactory srFactory   = new SpatialReferenceEnvironment();
            ISpatialReference2       srReference = srFactory.CreateProjectedCoordinateSystem(26917) as ISpatialReference2;

            //Create an IRasterGeometryProc object as this has the projectFast method we are looking for.
            IRasterGeometryProc rasterGeometryProc = new RasterGeometryProc();

            rasterGeometryProc.ProjectFast(rasterProps.SpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ((object)cellSize), raster);

            //Create a new rasterBandCollection to store the raster in and save it there.
            IRasterBandCollection rasterBandCollection = raster as IRasterBandCollection;
            String outName = "NewImage.tif";

            String outType = "TIFF";

            rasterBandCollection.SaveAs(outName, ((IWorkspace)rasterWorkspace), outType);

            Console.WriteLine("DONE");
            Console.ReadLine();
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Example #7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //licenseInitializer.InitializeApplication(
            //    new[] {
            //        esriLicenseProductCode.esriLicenseProductCodeAdvanced
            //    },
            //    new[] {
            //        esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork,
            //        esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst,
            //    });

            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
            Application.Run(new MainForm());
            //Application.Run(new OleDbQueryForm());
            //Application.Run(new ExportMapForm());
            //Application.Run(new PathFolderBrowserDialog(@""));
            licenseInitializer.ShutdownApplication();
        }
        private static void inicializaLicenca()
        {
            if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine))
            {
                if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop))
                {
                    Console.WriteLine("This application could not load the correct version of ArcGIS.");
                    return;
                }
            }

            LicenseInitializer aoLicenseInitializer = new LicenseInitializer();

            if (!aoLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeBasic, esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                            new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork }))
            {
                Console.WriteLine("This application could not initialize with the correct ArcGIS license and will shutdown. LicenseMessage: " + aoLicenseInitializer.LicenseMessage());
                aoLicenseInitializer.ShutdownApplication();
                return;
            }
        }
Example #9
0
        static void Main()
        {
            //cyf 20110612 modify:将许可授权文件由ArcEngine改为ArcINfo
            //ESRI License Initializer generated code.
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);



            IAoInitialize m_AoInitialize = new AoInitialize();

            m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);             //esriLicenseProductCodeArcInfo);//.esriLicenseProductCodeEngineGeoDB);
            m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB); //esriLicenseProductCodeArcInfo);//.esriLicenseProductCodeEngineGeoDB);
            //end
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

            //added by chulili 20110714检测有没有安装arcengine
            RegistryKey LocalMachineRegKey = Registry.LocalMachine;

            RegistryKey InstallDirRegKey = LocalMachineRegKey.OpenSubKey(@"SOFTWARE\ESRI\CoreRuntime");

            if (InstallDirRegKey == null)
            {
                InstallDirRegKey = LocalMachineRegKey.OpenSubKey(@"SOFTWARE\\ESRI\\Engine10.0\\CoreRuntime");
            }
            if (InstallDirRegKey == null)
            {
                InstallDirRegKey = LocalMachineRegKey.OpenSubKey(@"SOFTWARE\\ESRI\\Desktop10.0\\CoreRuntime");
            }

            if (InstallDirRegKey == null)
            {
                MessageBox.Show("没有安装ArcGIS Runtime或ArcGIS Desktop!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }

            //end add
            ///软件狗的检测
            //GeoOneKey key = new GeoOneKey();

            //if (key.addkey() != -1)
            //{
            bool b = GetProcessSysmain();

            if (b == true)
            {
                //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "该程序已启动!");
                MessageBox.Show("该程序已启动!请查看程序是否正在运行,或请在进程中关闭。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
            else
            {
                //deleted by chulili 20110531 删除psc的数据库连接窗体,仅适用南京的数据库连接窗体
                //**********************************************************************************************
                //guozhegng 2011-2-25 系统维护库的连接正确性判断以及库体结构完整性判断//
                //#region 系统维护库的连接正确性判断以及库体结构完整性判断
                //Exception ex = null;
                //clsAddAppDBConnection addAppDB = new clsAddAppDBConnection();
                //string sConnect = addAppDB.GetAppDBConInfo(out ex);
                //if (string.IsNullOrEmpty(sConnect))
                //{
                //    sConnect = addAppDB.SetAppDBConInfo(out ex);
                //}
                //if (!string.IsNullOrEmpty(sConnect))
                //{
                //    addAppDB.JudgeAppDbConfiguration(sConnect, out ex);
                //    if (ex != null)
                //    {
                //        //if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "系统维护库库体结构错误:" + ex.Message + ",\n是否重新配置系统维护库连接信息?"))
                //        if (MessageBox.Show("系统维护库库体结构错误:" + ex.Message + ",\n是否重新配置系统维护库连接信息?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //        {
                //            sConnect = addAppDB.SetAppDBConInfo(out ex);
                //        }
                //        else
                //        {
                //            Application.Exit();
                //            return;
                //        }

                //    }
                //}
                //else
                //{
                //    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取系统维护库连接信息失败");
                //    Application.Exit();
                //    return;
                //}
                //#endregion
                //end  deleted by chulili 20110531

                //登陆主窗体条件设置
                if (ModuleOperator.CheckLogin())
                {
                    ISelectionEnvironmentThreshold threshold = new SelectionEnvironmentClass();
                    threshold.WarningThreshold = 2000;
                    Application.Run(new frmMain());
                }
            }

            m_AoInitialize.Shutdown();
            m_AoInitialize = null;
            m_AOLicenseInitializer.ShutdownApplication();
            m_AOLicenseInitializer = null;
        }
Example #10
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },
                                                         new esriLicenseExtensionCode[] { });
            //ESRI License Initializer generated code.

            IWorkspaceFactory2 wsf2 = new SdeWorkspaceFactoryClass() as IWorkspaceFactory2;
            IWorkspace         ws   = wsf2.OpenFromFile(@"C:\Users\User123\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\ConnectionToSQLServer.sde", 0);

            IFeatureWorkspace fws = ws as IFeatureWorkspace;

            ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fws.OpenFeatureClass("DB_101.DBO.Points_Projected_UTMz11NCopy4_3");

            ITableWrite tw = fc as ITableWrite;

            int numRows = 300;

            Int32[] int32Array = new Int32[numRows];

            for (Int32 i = 0; i < numRows; i++)
            {
                int32Array[i] = i;
            }

            IGeoDatabaseBridge2 gdbBridge2 = new GeoDatabaseHelperClass();

            //IGeoDatabaseBridge2 fc_gdbBridge2 = fc as IGeoDatabaseBridge2;

            bool Recycling = false;

            IFeatureCursor featCursor = gdbBridge2.GetFeatures(fc, ref int32Array, Recycling);

            ISet setOfRows = new SetClass();

            IFeature feat;

            feat = featCursor.NextFeature();

            while (feat != null)
            {
                IObject obj = feat as IObject;
                setOfRows.Add(obj);
                feat = featCursor.NextFeature();
            }

            // TEST 1: ITableWrite.DeleteRows
            //-------------------------------

            DateTime dateTimeNow_Start = System.DateTime.Now;

            tw.DeleteRows(setOfRows);
            DateTime dateTimeNow_End = System.DateTime.Now;
            Double   timeDifference  = dateTimeNow_End.Subtract(dateTimeNow_Start).Milliseconds;

            System.Diagnostics.Debug.WriteLine("ITableWrite.DeleteRows(" + numRows + "rows): Processing time = " +
                                               timeDifference + " Milliseconds.");

            // TEST 2: ITableWrite.RemoveRows
            //-------------------------------

            //DateTime dateTimeNow_Start = System.DateTime.Now;
            //tw.RemoveRows(setOfRows);
            //DateTime dateTimeNow_End = System.DateTime.Now;
            //Double timeDifference = dateTimeNow_End.Subtract(dateTimeNow_Start).Milliseconds;
            //System.Diagnostics.Debug.WriteLine("ITableWrite.RemoveRows(" + numRows + "rows): Processing time = " +
            //                                                                timeDifference + " Milliseconds.");

            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Example #11
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                         new esriLicenseExtensionCode[] { });

            Dictionary <string, Vertex> nodeDict = new Dictionary <string, Vertex>();
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(@"C:\Users\hellocomrade\NHDPlusV21_GL_04.gdb", 0);
            IFeatureWorkspace iFtrWs           = workspace as IFeatureWorkspace;

            if (null != iFtrWs)
            {
                IFeatureClass fcLine  = iFtrWs.OpenFeatureClass("NHD_Flowline");
                IFeatureClass fcPoint = iFtrWs.OpenFeatureClass("Hydro_Net_Junctions");
                System.Diagnostics.Debug.Assert(null != fcLine && null != fcPoint);

                var fldLst = new List <string> {
                    "OBJECTID", "FlowDir", "FTYPE", "V0001E_MA", "V0001E_MM", "V0001E_01", "V0001E_02", "V0001E_03", "V0001E_04", "V0001E_05", "V0001E_06", "V0001E_07", "V0001E_08", "V0001E_09", "V0001E_10", "V0001E_11", "V0001E_12"
                };
                Dictionary <string, int> fldDict = new Dictionary <string, int>();
                fldLst.ForEach(fldName => fldDict.Add(fldName, fcLine.FindField(fldName)));

                int lineFtrId = -1;
                //Find field index for oid in Hydro_Net_Junctions feature class
                int    pntFtrIdIdx = fcPoint.FindField("OBJECTID");
                string pntFtrId    = null;

                /*
                 * It has been observed that the most time consuming part of this script is on spatial query.
                 * We could take the same approach we had on Arcpy through fcLine.Search() with a spatial filter.
                 * However, it will make us have the same granularity as using arcpy.
                 * Instead, we took a different route here by using IFeatureIndex and IIndexQuery2
                 */
                IGeoDataset       geoLineDS = (IGeoDataset)fcLine;
                ISpatialReference srLine    = geoLineDS.SpatialReference;
                IFeatureIndex     lineIdx   = new FeatureIndexClass();
                lineIdx.FeatureClass = fcLine;
                lineIdx.Index(null, geoLineDS.Extent);
                IIndexQuery2 queryLineByIdx = lineIdx as IIndexQuery2;

                IFeatureIndex pointIdx = new FeatureIndexClass();
                pointIdx.FeatureClass = fcPoint;
                pointIdx.Index(null, ((IGeoDataset)fcPoint).Extent);
                IIndexQuery2 queryPointByIdx = pointIdx as IIndexQuery2;

                //Get a cursor on Hydro_Net_Junctions as the iterator
                IFeatureCursor pntCur        = fcPoint.Search(null, false);
                IFeature       pnt           = pntCur.NextFeature();
                IFeature       line          = null;
                IFeature       otherPnt      = null;
                List <string>  requiredTypes = new List <string> {
                    "StreamRiver", "ArtificialPath"
                };

                /*
                 * ITopologicalOpeartor is good for two geometries comparing with each other. It doesn't fit
                 * very well for our situation, which check the geometric relationships between a geometry
                 * against a feature class that may have more than 100K geometries.
                 */
                //ITopologicalOperator optor = null;

                /*
                 * It's a shame that we have to reference to a Server API in order to calcuate Geodesic
                 * distances for a polyline with lon/lat as coordinates.
                 *
                 * We could do Haversine ourselves, but we have to believe ESRI could definitely does a
                 * better job there, well, hard to figure out how to get this simple task done in an intutive
                 * way though...
                 */
                IGeometryServer2 geoOperator = new GeometryServerClass();

                IPolyline             polyLine = null;
                List <DownstreamNode> dsLst    = null;
                int[]         lineIds          = null;
                int[]         pntIds           = null;
                object        idobjs;
                object        idobjs1;
                PolylineArray tmpArr   = null;
                IDoubleArray  lengths  = null;
                double        lineLen  = 0.0;
                double        v        = 0.0;
                ILinearUnit   unit     = new LinearUnitClass();
                var           range    = Enumerable.Range(3, 14);
                int           count    = 0;
                int           incoming = 0;
                while (null != pnt)
                {
                    //get ftr id of the current vertex
                    pntFtrId = pnt.get_Value(pntFtrIdIdx).ToString();
                    //optor = pnt.Shape as ITopologicalOperator;

                    /*
                     * This should return feature ids that interects with the given geometry in the feature
                     * class having the index built.
                     */
                    queryLineByIdx.IntersectedFeatures(pnt.Shape, out idobjs);
                    lineIds = idobjs as int[];
                    if (null != lineIds && lineIds.Length > 0)
                    {
                        foreach (int id in lineIds)
                        {
                            line      = fcLine.GetFeature(id);
                            lineFtrId = int.Parse(line.get_Value(fldDict["OBJECTID"]).ToString());
                            if ("1" == line.get_Value(fldDict["FlowDir"]).ToString() && true == requiredTypes.Contains(line.get_Value(fldDict["FTYPE"]).ToString()))
                            {
                                polyLine = line.Shape as IPolyline;
                                if (isSamePoint(polyLine.FromPoint, pnt.Shape as IPoint))
                                {
                                    queryPointByIdx.IntersectedFeatures(line.Shape, out idobjs1);
                                    pntIds = idobjs1 as int[];
                                    if (null != pntIds && 2 == pntIds.Length)
                                    {
                                        foreach (int pid in pntIds)
                                        {
                                            otherPnt = fcPoint.GetFeature(pid);
                                            if (false == isSamePoint(otherPnt.Shape as IPoint, pnt.Shape as IPoint))
                                            {
                                                tmpArr = new PolylineArrayClass();
                                                tmpArr.Add(polyLine);
                                                lengths = geoOperator.GetLengthsGeodesic(srLine, tmpArr as IPolylineArray, unit);
                                                if (0 == lengths.Count)
                                                {
                                                    continue;
                                                }
                                                lineLen = lengths.get_Element(0) * 3.28084;
                                                //var velos = from idx in range select double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                List <double> velos = new List <double>();
                                                foreach (int idx in range)
                                                {
                                                    v = double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                    velos.Add(v == 0 ? 0 : lineLen / v);
                                                }
                                                if (null == dsLst)
                                                {
                                                    dsLst = new List <DownstreamNode>();
                                                }
                                                dsLst.Add(new DownstreamNode(pid, id, velos));
                                            }
                                        }
                                    }
                                }
                                else // pnt at the end of the polyline
                                {
                                    ++incoming;
                                }
                            }
                        }
                    }
                    if (null != dsLst || incoming > 0)
                    {
                        nodeDict.Add(pntFtrId, new Vertex(int.Parse(pntFtrId), incoming, dsLst));
                    }
                    pnt = pntCur.NextFeature();
                    if (++count % 1000 == 0)
                    {
                        Console.WriteLine("Processing Count: " + count);
                    }
                    incoming = 0;
                    dsLst    = null;
                }//end of while(null != pnt)
                ReleaseCOMObj(pntCur);
            }
            ReleaseCOMObj(workspaceFactory);
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Example #12
0
 public void TearDown()
 {
     m_AOLicenseInitializer.ShutdownApplication();
 }
Example #13
0
        static void Main(string[] args)
        {
            if (2 != args.Length)
            {
                System.Console.WriteLine("We need that GLRD csv file in this demo, dude! Also, tell me the State Name as filter please!");
                return;
            }
            string gdb  = string.Format(GDB_Name, args[1]);
            var    prjs = ParseCSV(args[0], args[1]);

            if (prjs.Count > 0)
            {
                try
                {
                    //ESRI License Initializer generated code.
                    m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                                 new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork, esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst });
                    //print version info to console
                    var runtimes = RuntimeManager.InstalledRuntimes;
                    foreach (RuntimeInfo runtime in runtimes)
                    {
                        System.Console.WriteLine(runtime.Path);
                        System.Console.WriteLine(runtime.Version);
                        System.Console.WriteLine(runtime.Product.ToString());
                    }
                    // Instantiate a file geodatabase workspace factory and create a file geodatabase.
                    // The Create method returns a workspace name object.
                    // Ugly way to create object through reflection
                    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    if (false == System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(args[0])) + "\\" + gdb))
                    {
                        IWorkspaceName workspaceName = workspaceFactory.Create(System.IO.Path.GetDirectoryName(args[0]), gdb, null, 0);
                        //ugly way to release raw COM Object
                        ReleaseCOMObj(workspaceFactory);
                        // Cast the workspace name object to the IName interface and open the workspace.
                        IName             name      = (IName)workspaceName;
                        IWorkspace        workspace = (IWorkspace)name.Open();
                        IFeatureWorkspace ftrspace  = workspace as IFeatureWorkspace;
                        List <dynamic>    fldlst    = new List <dynamic>();
                        fldlst.Add(new { Name = "Title", Type = esriFieldType.esriFieldTypeString });
                        IFeatureClass ftrClass = CreateFeatureClass(FtrClass_Name, ftrspace, esriGeometryType.esriGeometryPoint, 4326, fldlst);
                        if (null != ftrClass)
                        {
                            IPoint pnt = null;
                            double x, y;
                            string title    = null;
                            int    idxTitle = ftrClass.Fields.FindField("Title");
                            //http://edndoc.esri.com/arcobjects/9.2/NET/e7b33417-0373-4f87-93db-074910907898.htm
                            // Create the feature buffer.
                            IFeatureBuffer ftrBuffer = ftrClass.CreateFeatureBuffer();
                            // Create insert feature cursor using buffering.
                            IFeatureCursor ftrCursor = ftrClass.Insert(true);
                            foreach (var prj in prjs)
                            {
                                x     = prj.X;
                                y     = prj.Y;
                                title = prj.Name;
                                pnt   = new PointClass();
                                pnt.PutCoords(x, y);
                                ftrBuffer.Shape = pnt;
                                ftrBuffer.set_Value(idxTitle, title);
                                ftrCursor.InsertFeature(ftrBuffer);
                            }
                            try
                            {
                                ftrCursor.Flush();
                                Console.WriteLine(string.Format("File GDB: {0} has been created!", gdb));
                            }
                            catch (System.Runtime.InteropServices.COMException)
                            {
                                throw;
                            }
                            finally
                            {
                                ReleaseCOMObj(ftrCursor);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Dude, the GDB has been created already! Remove {0} and try again please.", gdb));
                    }
                    //ESRI License Initializer generated code.
                    //Do not make any call to ArcObjects after ShutDownApplication()
                    m_AOLicenseInitializer.ShutdownApplication();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }