Exemplo n.º 1
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Uitvoeren.
        //

        ///<summary>Creates a table with some default fields.</summary>
        ///
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///
        ///<returns>An ITable interface or Nothing</returns>
        ///
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null)
            {
                return(null);                                                                                                  // valid feature workspace not passed in as an argument to the method
            }
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            ESRI.ArcGIS.Geodatabase.ITable            table;

            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
            {
                // table with that name already exists return that table
                table = featureWorkspace.OpenTable(tableName);
                return(table);
            }

            uid.Value = "esriGeoDatabase.Object";

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                fieldsEdit.AddField(this.CreateFieldInt("ID"));
                fieldsEdit.AddField(this.CreateFieldInt("index"));
                fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2));


                // add field to field collection
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.


            // create and return the table
            table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");

            return(table);
        }
        private IEnumLayer GetLayers()
        {
            //now get the map document to parse out the feature classes
            GxDialog      pGxDialog = new GxDialogClass();
            IEnumGxObject pEnumGxObject;
            bool          pResult;

            pGxDialog.ObjectFilter = new GxFilterMapsClass();
            pGxDialog.Title        = "Select a map document";
            try
            {
                pResult = pGxDialog.DoModalOpen(0, out pEnumGxObject);
                //check to see if the user canceled the dialog
                if (pResult == false)
                {
                    return(null);
                }
                IGxObject  pGxObject  = pEnumGxObject.Next();
                IMapReader pMapReader = new MapReaderClass();
                pMapReader.Open(pGxObject.FullName.ToString());
                IMap pMap = pMapReader.get_Map(0);
                ESRI.ArcGIS.esriSystem.UID pUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                pUID.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";                  //feature layer

                IEnumLayer pLayers = pMap.get_Layers(pUID, true);
                return(pLayers);
            }
            catch
            {
                //error getting layers
                return(null);
            }
        }
Exemplo n.º 3
0
        public void AddMapLegend(IPageLayout pageLayout, IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }
                IGraphicsContainer          graphicsContainer = pageLayout as IGraphicsContainer;              // Dynamic Cast
                IMapFrame                   mapFrame          = graphicsContainer.FindFrame(map) as IMapFrame; // Dynamic Cast
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Legend";
                IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

                //Get aspect ratio
                IQuerySize    querySize = mapSurroundFrame.MapSurround as IQuerySize; // Dynamic Cast
                System.Double w         = 0;
                System.Double h         = 0;
                querySize.QuerySize(ref w, ref h);
                System.Double aspectRatio = w / h;

                IEnvelope envelope = new EnvelopeClass();

                envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
                IElement element = mapSurroundFrame as IElement; // Dynamic Cast
                element.Geometry = envelope;
                graphicsContainer.AddElement(element, 0);
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 图形比例尺
        /// </summary>
        /// <returns></returns>
        public bool AddImgScaleBar()
        {
            IStyleSelector pStyleSelector = new ScaleBarSelectorClass();
            bool m_bOK = pStyleSelector.DoModal(0);
            if (m_bOK == true)
            {
                IScaleBar pScaleBar = pStyleSelector.GetStyle(0) as IScaleBar;

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(0.2, 0.2, 5, 1);
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Scalebar";
                IMap pMap = mainPage.ActiveView.FocusMap;
                IGraphicsContainer graphicsContainer = mainPage.ActiveView as IGraphicsContainer;
                IActiveView activeView = mainPage.ActiveView as IActiveView;
                IFrameElement frameElement = graphicsContainer.FindFrame(pMap);
                IMapFrame mapFrame = frameElement as IMapFrame;
                IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null);
                IMapSurround mapsurround = pScaleBar as IMapSurround;
                mapSurroundFrame.MapSurround = mapsurround;
                IElement element = mapSurroundFrame as IElement;
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;
            }
            return true;
        }
        ///<summary>Add a North Arrow to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///
        ///<remarks></remarks>
        public void AddNorthArrow(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(1, 24, 5, 24); //  Specify the location and size of the north arrow

            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.MarkerNorthArrow";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;                    // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView        activeView        = pageLayout as ESRI.ArcGIS.Carto.IActiveView;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = frameElement as ESRI.ArcGIS.Carto.IMapFrame;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement           element           = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement;                        // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            ESRI.ArcGIS.Carto.IMarkerNorthArrow        markerNorthArrow      = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow;         // Dynamic Cast
            ESRI.ArcGIS.Display.IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
            ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
            characterMarkerSymbol.CharacterIndex = 200;                                                                                    // change the symbol for the North Arrow
            markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
        }
Exemplo n.º 6
0
        // ArcGIS Snippet Title:
        // Add Legend
        //
        // Long Description:
        // Add a Legend to the Page Layout from the Map.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        ///
        ///<remarks></remarks>
        public void AddLegend(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;              // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IUID          uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 文字比例尺
        /// </summary>
        /// <returns></returns>
        public bool AddTxtSacleBar()
        {
            IStyleSelector pStyleSelector = new ScaleTextSelectorClass();
            bool           m_bOK          = pStyleSelector.DoModal(0);

            if (m_bOK == true)
            {
                IScaleText pScaleText = pStyleSelector.GetStyle(0) as IScaleText;

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(0.2, 0.2, 5, 1);
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Scaletext";
                IMap pMap = mainPage.ActiveView.FocusMap;
                IGraphicsContainer graphicsContainer = mainPage.ActiveView as IGraphicsContainer;
                IActiveView        activeView        = mainPage.ActiveView as IActiveView;
                IFrameElement      frameElement      = graphicsContainer.FindFrame(pMap);
                IMapFrame          mapFrame          = frameElement as IMapFrame;
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null);
                IMapSurround       mapsurround       = pScaleText as IMapSurround;
                mapSurroundFrame.MapSurround = mapsurround;
                IElement element = mapSurroundFrame as IElement;
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;
            }
            return(true);
        }
Exemplo n.º 8
0
 internal static GoogleMapsEngineToolsExtensionForArcGIS GetExtension()
 {
     // Extension loads just in time, call FindExtension to load it.
     if (s_extension == null)
     {
         ESRI.ArcGIS.esriSystem.UID extID = new ESRI.ArcGIS.esriSystem.UIDClass();
         extID.Value = ThisAddIn.IDs.GoogleMapsEngineToolsExtensionForArcGIS;
         ArcMap.Application.FindExtensionByCLSID(extID);
     }
     return(s_extension);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Finds the first layer on the focus map whose source feature class
        /// has the given name AND where the workspace matches that of the
        /// currently selected telecom workspace.
        /// </summary>
        /// <param name="ftClassName">Name to look for</param>
        /// <returns>IFeatureLayer</returns>
        public ESRI.ArcGIS.Carto.IFeatureLayer FindFeatureLayer(string ftClassName)
        {
            ESRI.ArcGIS.Carto.IFeatureLayer result = null;

            if (1 > ftClassName.Length)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "FindFeatureLayer: ", "ftClassName not specified");
                throw new ArgumentException("ftClassName not specified");
            }

            // Check the cache first for the layer
            if (_featureLayerCache.ContainsKey(ftClassName))
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Found Feature Layer in cache", ftClassName);
                return(_featureLayerCache[ftClassName]);
            }

            ESRI.ArcGIS.esriSystem.UID geoFeatureLayerID = new ESRI.ArcGIS.esriSystem.UIDClass();
            geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";

            ESRI.ArcGIS.Carto.IEnumLayer enumLayer = this.FocusMap.get_Layers(geoFeatureLayerID, true);

            // Step through each geofeature layer in the map
            enumLayer.Reset();
            ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;

            string testName        = ftClassName.ToLower(); // No reason to do this every time in the loop
            int    testDotPosition = testName.LastIndexOf('.');

            testName = testName.Substring(testDotPosition + 1);

            while (ftLayer != null)
            {
                if (ftLayer.Valid)
                {
                    ESRI.ArcGIS.Geodatabase.IDataset dataset = ftLayer.FeatureClass as ESRI.ArcGIS.Geodatabase.IDataset;
                    if (null != dataset && dataset.Workspace == _wkspHelper.CurrentWorkspace)
                    {
                        string tableName = GdbUtils.ParseTableName(dataset);
                        if (tableName.ToLower() == testName)
                        {
                            result = ftLayer;
                            _featureLayerCache.Add(ftClassName, result);
                            break;
                        }
                    }
                }

                ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;
            }

            return(result);
        }
Exemplo n.º 10
0
        public void SetToolActiveInToolBar(ESRI.ArcGIS.Framework.IApplication application, System.String toolName)
        {
            ESRI.ArcGIS.Framework.ICommandBars commandBars = application.Document.CommandBars;
            ESRI.ArcGIS.esriSystem.UID         commandID   = new ESRI.ArcGIS.esriSystem.UIDClass();
            commandID.Value = toolName; // example: "esriArcMapUI.ZoomInTool";
            ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(commandID, false, false);

            if (commandItem != null)
            {
                application.CurrentTool = commandItem;
            }
        }
Exemplo n.º 11
0
 ///<summary>Obtain a toolbar by specifying it's name.</summary>
 ///  
 ///<param name="application">An IApplication interface.</param>
 ///<param name="toolbarName">A System.String that is the name of the toolbar to return. Example: "esriArcMapUI.StandardToolBar"</param>
 ///   
 ///<returns>An ICommandBar interface.</returns>
 ///  
 ///<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ArcMapIds.htm for a listing of available CLSID's and ProgID's that can be used as the toolbarName parameter.</remarks>
 public static ICommandBar GetToolbarByName(IApplication application, System.String toolbarName)
 {
     ICommandBars commandBars = application.Document.CommandBars;
     ESRI.ArcGIS.esriSystem.UID barID = new ESRI.ArcGIS.esriSystem.UIDClass();
     barID.Value = toolbarName; // Example: "esriArcMapUI.StandardToolBar"
     ICommandItem commandItem = commandBars.Find(barID, false, false);
     if (commandItem != null && commandItem.Type == esriCommandTypes.esriCmdTypeToolbar)
     {
         return (ICommandBar)commandItem;
     }
     else
         return null;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Returns the editor
        /// </summary>
        /// <param name="mxApplication"></param>
        /// <returns>the editor</returns>
        public IEditor3 GetEditorFromArcMap(IMxApplication mxApplication)
        {
            if (mxApplication == null)
            {
                return(null);
            }
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}";
            ESRI.ArcGIS.Framework.IApplication application = mxApplication as ESRI.ArcGIS.Framework.IApplication; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IExtension  extension   = application.FindExtensionByCLSID(uid);
            ESRI.ArcGIS.Editor.IEditor3        editor3     = extension as ESRI.ArcGIS.Editor.IEditor3;            // Dynamic Cast

            return(editor3);
        }
Exemplo n.º 13
0
 public IDockableWindow GetDockableWindow(System.String windowName)
 {
     try
     {
         IDockableWindowManager dockWindowManager = ArcCatalog.Application as IDockableWindowManager;
         UID windowID = new ESRI.ArcGIS.esriSystem.UIDClass();
         windowID.Value = windowName; // example: "esriGeoprocessingUI.GPCommandWindow"
         return dockWindowManager.GetDockableWindow(windowID);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to load dockable window: " + windowName + Environment.NewLine + ex.Message);
         return null;
     }
 }
Exemplo n.º 14
0
        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        ///
        ///<remarks></remarks>
        public void AddLegend(IPageLayout pageLayout, IMap map, Double posX, Double posY, Double legW)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;              // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast


            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            //
            ILegend pLegend = mapSurroundFrame.MapSurround as ILegend;

            pLegend.Title = "图例";
            pLegend.Format.TitlePosition = esriRectanglePosition.esriLeftSide | esriRectanglePosition.esriTopSide;
            pLegend.Format.TitleSymbol   = new TextSymbolClass()
            {
                Font = GetFontDisp(24)
            };
            pLegend.get_Item(0).ShowLayerName   = true;
            pLegend.get_Item(0).LayerNameSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(22)
            };
            pLegend.get_Item(0).LegendClassFormat.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast

            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
Exemplo n.º 15
0
        ///<summary>Find a command item particularly on a toolbar.</summary>
        ///  
        ///<param name="application">An IApplication interface.</param>
        ///<param name="toolbarName">A System.String that is the name of the toolbar to return. Example: "esriArcMapUI.StandardToolBar"</param>
        ///<param name="commandName">A System.String that is the name of the command to return. Example: "esriFramework.HelpContentsCommand"</param>
        ///   
        ///<returns>An ICommandItem interface.</returns>
        ///  
        ///<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ArcMapIds.htm for a listing of available CLSID's and ProgID's that can be used as the toolbarName and commandName parameters.</remarks>
        public static ICommandItem GetCommandOnToolbar(IApplication application, System.String toolbarName, System.String commandName)
        {
            ICommandBars commandBars = application.Document.CommandBars;
            ESRI.ArcGIS.esriSystem.UID barID = new ESRI.ArcGIS.esriSystem.UIDClass();
            barID.Value = toolbarName; // Example: "esriArcMapUI.StandardToolBar"
            ICommandItem barItem = commandBars.Find(barID, false, false);

            if (barItem != null && barItem.Type == esriCommandTypes.esriCmdTypeToolbar)
            {
                ICommandBar commandBar = (ICommandBar)barItem;
                ESRI.ArcGIS.esriSystem.UID commandID = new ESRI.ArcGIS.esriSystem.UIDClass();
                commandID.Value = commandName; // Example: "esriArcMapUI.AddDataCommand"
                return commandBar.Find(commandID, false);
            }
            else
                return null;
        }
        public void IClassSchemaEdit_Example(IObjectClass objectClass)
        {
            //This function shows how you can use the IClassSchemaEdit
            //interface to alter the COM class extension for an object class.
            //cast for the IClassSchemaEdit
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
            //set and exclusive lock on the class
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
            ESRI.ArcGIS.esriSystem.UID classUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            //GUID for the C# project.
            classUID.Value = "{65a43962-8cc0-49c0-bfa3-015d0ff8350e}";
            classSchemaEdit.AlterClassExtensionCLSID(classUID, null);
            //release the exclusive lock
            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
        }
        ///<summary>Find a command and click it programmatically.</summary>
        ///
        ///<param name="application">An IApplication interface.</param>
        ///<param name="commandName">A System.String that is the name of the command to return. Example: "esriFramework.HelpContentsCommand" or "{D74B2F25-AC90-11D2-87F8-0000F8751720}"</param>
        ///
        ///<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ArcMapIds.htm for a listing of available CLSID's and ProgID's that can be used as the commandName parameter.</remarks>
        public void FindCommandAndExecute(ESRI.ArcGIS.Framework.IApplication application, System.String commandName)
        {
            try
            {
                ESRI.ArcGIS.Framework.ICommandBars commandBars = application.Document.CommandBars;
                ESRI.ArcGIS.esriSystem.UID         uid         = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = commandName;
                ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(uid, false, false);

                if (commandItem != null)
                {
                    commandItem.Execute();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Extensions manager could not be opened: {0}", ex.Message));
            }
        }
Exemplo n.º 18
0
        public void AddNorthArrow(IPageLayout pageLayout, IMap map, double posX, double posY, double division)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(posX - division, posY - division, posX, posY); //  Specify the location and size of the north arrow

                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.MarkerNorthArrow";

                // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
                // Activate it and add it to the PageLayout's graphics container
                IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;                                      // Dynamic Cast
                IActiveView        activeView        = pageLayout as IActiveView;                                             // Dynamic Cast
                IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
                IMapFrame          mapFrame          = frameElement as IMapFrame;                                             // Dynamic Cast
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
                IElement           element           = mapSurroundFrame as IElement;                                          // Dynamic Cast
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;

                // Change out the default north arrow
                IMarkerNorthArrow      markerNorthArrow      = mapSurround as IMarkerNorthArrow;       // Dynamic Cast
                IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
                ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast
                characterMarkerSymbol.CharacterIndex = 174;                                            // change the symbol for the North Arrow
                markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 19
0
        ///<summary>Add a Scale Bar to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///
        ///<remarks></remarks>
        public void AddScalebar(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(7, 1, 25, 1.5); // Specify the location and size of the scalebar
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.AlternatingScaleBar";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;                    // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView        activeView        = pageLayout as ESRI.ArcGIS.Carto.IActiveView;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = frameElement as ESRI.ArcGIS.Carto.IMapFrame;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement           element           = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement;                        // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;


            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));

            markerScaleBar.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };
            markerScaleBar.UnitLabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
        }
 private ESRI.ArcGIS.esriSystem.UID getUID(string uid)
 {
     ESRI.ArcGIS.esriSystem.IUID vl = new ESRI.ArcGIS.esriSystem.UIDClass();
     vl.Value = uid;
     return (ESRI.ArcGIS.esriSystem.UID)(vl);
 }
Exemplo n.º 21
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //
        ///<summary>Creates a table with some default fields.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///  
        ///<returns>An ITable interface or Nothing</returns>
        ///  
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        internal ESRI.ArcGIS.Geodatabase.ITable CreateRelationTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword, string metadataAbstract, string metadataPurpose)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.ITable table = null;

            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

                if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
                {
                    // if a table with the same name already exists delete it....
                    table = featureWorkspace.OpenTable(tableName);

                    if (!DeleteDataset((IDataset)table))
                    {
                        return table;
                    }
                }

                uid.Value = "esriGeoDatabase.Object";

                ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

                // if a fields collection is not passed in then supply our own
                if (fields == null)
                {
                    // create the fields using the required fields method
                    fields = objectClassDescription.RequiredFields;
                    ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                    // create OSM base fields the osm administrative fields
                    // add the OSM ID field
                    IFieldEdit osmIDField = new FieldClass() as IFieldEdit;
                    osmIDField.Name_2 = "OSMID";
                    osmIDField.Required_2 = true;
                    osmIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmIDField);

                    // user, uid, visible, version, changeset, timestamp
                    IFieldEdit osmuserField = new FieldClass() as IFieldEdit;
                    osmuserField.Name_2 = "osmuser";
                    osmuserField.Required_2 = true;
                    osmuserField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmuserField.Length_2 = 100;
                    fieldsEdit.AddField((IField)osmuserField);

                    IFieldEdit osmuidField = new FieldClass() as IFieldEdit;
                    osmuidField.Name_2 = "osmuid";
                    osmuidField.Required_2 = true;
                    osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmuidField);

                    IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit;
                    osmvisibleField.Name_2 = "osmvisible";
                    osmvisibleField.Required_2 = true;
                    osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmvisibleField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmvisibleField);

                    IFieldEdit osmversionField = new FieldClass() as IFieldEdit;
                    osmversionField.Name_2 = "osmversion";
                    osmversionField.Required_2 = true;
                    osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    fieldsEdit.AddField((IField)osmversionField);

                    IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit;
                    osmchangesetField.Name_2 = "osmchangeset";
                    osmchangesetField.Required_2 = true;
                    osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmchangesetField);

                    IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit;
                    osmtimestampField.Name_2 = "osmtimestamp";
                    osmtimestampField.Required_2 = true;
                    osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate;
                    fieldsEdit.AddField((IField)osmtimestampField);

                    IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit;
                    osmrelationIDField.Name_2 = "osmMemberOf";
                    osmrelationIDField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmrelationIDField);

                    IFieldEdit osmMembersField = new FieldClass() as IFieldEdit;
                    osmMembersField.Name_2 = "osmMembers";
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmMembersField.Required_2 = true;
                    osmMembersField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmMembersField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmMembersField);

                    // add the field for the tag cloud for all other tag/value pairs
                    IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit;
                    osmXmlTagsField.Name_2 = "osmTags";
                    osmXmlTagsField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmXmlTagsField);

                    //IFieldEdit osmTrackChangesField = new FieldClass() as IFieldEdit;
                    //osmTrackChangesField.Name_2 = "osmTrackChanges";
                    //osmTrackChangesField.Required_2 = true;
                    //osmTrackChangesField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    //osmTrackChangesField.DefaultValue_2 = 0;
                    //fieldsEdit.AddField((IField)osmTrackChangesField);

                    fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
                }

                // Use IFieldChecker to create a validated fields collection.
                ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
                ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.

                // create and return the table
                table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword);

                // create the openstreetmap spcific metadata
                _osmUtility.CreateOSMMetadata((IDataset)table, metadataAbstract, metadataPurpose);
            }
            catch
            {
                throw;
            }

            return table;
        }
		private IEnumLayer GetLayers()
		{
			//now get the map document to parse out the feature classes
			GxDialog pGxDialog = new GxDialogClass();
			IEnumGxObject pEnumGxObject;
			bool pResult;

			pGxDialog.ObjectFilter = new GxFilterMapsClass();
			pGxDialog.Title = "Select a map document";
			try
			{
				pResult = pGxDialog.DoModalOpen(0, out pEnumGxObject);
				//check to see if the user canceled the dialog
				if (pResult == false) return null;
				IGxObject pGxObject = pEnumGxObject.Next();
				IMapReader pMapReader = new MapReaderClass();
				pMapReader.Open(pGxObject.FullName.ToString());
				IMap pMap = pMapReader.get_Map(0);
				ESRI.ArcGIS.esriSystem.UID pUID = new ESRI.ArcGIS.esriSystem.UIDClass();
				pUID.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";  //feature layer

				IEnumLayer pLayers = pMap.get_Layers(pUID, true);
                return pLayers;
			}
			catch
			{
				//error getting layers
				return null;
			}

		}
Exemplo n.º 23
0
        internal ESRI.ArcGIS.Geodatabase.ITable CreateRevisionTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.ITable table = null;

            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

                if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
                {
                    // if a table with the same name already exists delete it....if that is not possible return the current instance
                    table = featureWorkspace.OpenTable(tableName);

                    if (!DeleteDataset((IDataset)table))
                    {
                        return table;
                    }
                }

                uid.Value = "esriGeoDatabase.Object";

                ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

                // if a fields collection is not passed in then supply our own
                if (fields == null)
                {
                    // create the fields using the required fields method
                    fields = objectClassDescription.RequiredFields;
                    ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                    //
                    IFieldEdit osmChangesetField = new FieldClass() as IFieldEdit;
                    osmChangesetField.Name_2 = "osmchangeset";
                    osmChangesetField.Required_2 = true;
                    osmChangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmChangesetField);

                    IFieldEdit osmActionField = new FieldClass() as IFieldEdit;
                    osmActionField.Name_2 = "osmaction";
                    osmActionField.Required_2 = true;
                    osmActionField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmActionField.Length_2 = 10;
                    fieldsEdit.AddField((IField)osmActionField);

                    IFieldEdit osmElementTypeField = new FieldClass() as IFieldEdit;
                    osmElementTypeField.Name_2 = "osmelementtype";
                    osmElementTypeField.Required_2 = true;
                    osmElementTypeField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmElementTypeField.Length_2 = 10;
                    fieldsEdit.AddField((IField)osmElementTypeField);

                    IFieldEdit osmVersionField = new FieldClass() as IFieldEdit;
                    osmVersionField.Name_2 = "osmversion";
                    osmVersionField.Required_2 = true;
                    osmVersionField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmVersionField);

                    IFieldEdit fcNameField = new FieldClass() as IFieldEdit;
                    fcNameField.Name_2 = "sourcefcname";
                    fcNameField.Required_2 = true;
                    fcNameField.Type_2 = esriFieldType.esriFieldTypeString;
                    fcNameField.Length_2 = 50;
                    fieldsEdit.AddField((IField)fcNameField);

                    IFieldEdit osmOldIDField = new FieldClass() as IFieldEdit;
                    osmOldIDField.Name_2 = "osmoldid";
                    osmOldIDField.Required_2 = true;
                    osmOldIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmOldIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmOldIDField);

                    IFieldEdit osmNewIDField = new FieldClass() as IFieldEdit;
                    osmNewIDField.Name_2 = "osmnewid";
                    osmNewIDField.Required_2 = true;
                    osmNewIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmNewIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmNewIDField);

                    IFieldEdit latField = new FieldClass() as IFieldEdit;
                    latField.Name_2 = "osmlat";
                    latField.Required_2 = true;
                    latField.Type_2 = esriFieldType.esriFieldTypeDouble;
                    latField.Scale_2 = 10;
                    fieldsEdit.AddField((IField)latField);

                    IFieldEdit lonField = new FieldClass() as IFieldEdit;
                    lonField.Name_2 = "osmlon";
                    lonField.Required_2 = true;
                    lonField.Type_2 = esriFieldType.esriFieldTypeDouble;
                    lonField.Scale_2 = 10;
                    fieldsEdit.AddField((IField)lonField);

                    IFieldEdit statusField = new FieldClass() as IFieldEdit;
                    statusField.Name_2 = "osmstatus";
                    statusField.Required_2 = true;
                    statusField.Type_2 = esriFieldType.esriFieldTypeString;
                    statusField.Length_2 = 40;
                    fieldsEdit.AddField((IField)statusField);

                    IFieldEdit statusCodeField = new FieldClass() as IFieldEdit;
                    statusCodeField.Name_2 = "osmstatuscode";
                    statusCodeField.Required_2 = true;
                    statusCodeField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)statusCodeField);

                    IFieldEdit errorMessageField = new FieldClass() as IFieldEdit;
                    errorMessageField.Name_2 = "osmerrormessage";
                    errorMessageField.Required_2 = true;
                    errorMessageField.Type_2 = esriFieldType.esriFieldTypeString;
                    errorMessageField.Length_2 = 255;
                    fieldsEdit.AddField((IField)errorMessageField);

                    fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
                }

                // Use IFieldChecker to create a validated fields collection.
                ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
                ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.

                // create and return the table
                table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword);
            }
            catch
            {
                throw;
            }

            return table;
        }
 public void IClassSchemaEdit_Example(IObjectClass objectClass) 
 {        
   //This function shows how you can use the IClassSchemaEdit   
   //interface to alter the COM class extension for an object class.    
   //cast for the IClassSchemaEdit      
   IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
     //set and exclusive lock on the class     
   ISchemaLock schemaLock = (ISchemaLock)objectClass;  
   schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
     ESRI.ArcGIS.esriSystem.UID classUID = new ESRI.ArcGIS.esriSystem.UIDClass();
   //GUID for the C# project.
     classUID.Value = "{65a43962-8cc0-49c0-bfa3-015d0ff8350e}";
     classSchemaEdit.AlterClassExtensionCLSID(classUID, null);    
   //release the exclusive lock     
   schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);  
 }
Exemplo n.º 25
0
        ///<summary>Simple helper to create a featureclass in a geodatabase.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="featureDataset">An IFeatureDataset interface or Nothing</param>
        ///<param name="featureClassName">A System.String that contains the name of the feature class to open or create. Example: "states"</param>
        ///<param name="fields">An IFields interface</param>
        ///<param name="CLSID">A UID value or Nothing. Example "esriGeoDatabase.Feature" or Nothing</param>
        ///<param name="CLSEXT">A UID value or Nothing (this is the class extension if you want to reference a class extension when creating the feature class).</param>
        ///<param name="strConfigKeyword">An empty System.String or RDBMS table string for ArcSDE. Example: "myTable" or ""</param>
        ///  
        ///<returns>An IFeatureClass interface or a Nothing</returns>
        ///  
        ///<remarks>
        ///  (1) If a 'featureClassName' already exists in the workspace a reference to that feature class 
        ///      object will be returned.
        ///  (2) If an IFeatureDataset is passed in for the 'featureDataset' argument the feature class
        ///      will be created in the dataset. If a Nothing is passed in for the 'featureDataset'
        ///      argument the feature class will be created in the workspace.
        ///  (3) When creating a feature class in a dataset the spatial reference is inherited 
        ///      from the dataset object.
        ///  (4) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///      table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///      default values in the method.
        ///  (5) The 'strConfigurationKeyword' parameter allows the application to control the physical layout 
        ///      for this table in the underlying RDBMS—for example, in the case of an Oracle database, the 
        ///      configuration keyword controls the tablespace in which the table is created, the initial and 
        ///     next extents, and other properties. The 'strConfigurationKeywords' for an ArcSDE instance are 
        ///      set up by the ArcSDE data administrator, the list of available keywords supported by a workspace 
        ///      may be obtained using the IWorkspaceConfiguration interface. For more information on configuration 
        ///      keywords, refer to the ArcSDE documentation. When not using an ArcSDE table use an empty 
        ///      string (ex: "").
        ///</remarks>
        internal ESRI.ArcGIS.Geodatabase.IFeatureClass CreatePolygonFeatureClass(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset, System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, System.String strConfigKeyword, OSMDomains osmDomains, string metadataAbstract, string metadataPurpose)
        {
            if (featureClassName == "") return null; // name was not passed in

            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null;

            try
            {

                ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

                if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists
                {
                    // if a feature class with the same name already exists delete it....
                    featureClass = featureWorkspace.OpenFeatureClass(featureClassName);

                    if (!DeleteDataset((IDataset)featureClass))
                    {
                        return featureClass;
                    }
                }

                // assign the class id value if not assigned
                if (CLSID == null)
                {
                    CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                    CLSID.Value = "esriGeoDatabase.Feature";
                }

                ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

                // if a fields collection is not passed in then supply our own
                if (fields == null)
                {
                    // create the fields using the required fields method
                    fields = objectClassDescription.RequiredFields;
                    ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                    // add the domain driven string field for the OSM features
                    foreach (var domainAttribute in osmDomains.domain)
                    {
                        IFieldEdit domainField = new FieldClass() as IFieldEdit;
                        domainField.Name_2 = domainAttribute.name;
                        domainField.Type_2 = esriFieldType.esriFieldTypeString;
                        domainField.Required_2 = true;
                        domainField.Length_2 = 30;
                        try
                        {
                            domainField.Domain_2 = ((IWorkspaceDomains)workspace).get_DomainByName(domainAttribute.name + "_ply");
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                            System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                        }

                        fieldsEdit.AddField((IField)domainField);
                    }

                    // add the OSM ID field
                    IFieldEdit osmIDField = new FieldClass() as IFieldEdit;
                    osmIDField.Name_2 = "OSMID";
                    osmIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmIDField.Length_2 = 20;
                    osmIDField.Required_2 = true;
                    fieldsEdit.AddField((IField)osmIDField);

                    // add the field for the tag cloud for all other tag/value pairs
                    IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit;
                    osmXmlTagsField.Name_2 = "osmTags";
                    osmXmlTagsField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmXmlTagsField);

                    // user, uid, visible, version, changeset, timestamp
                    IFieldEdit osmuserField = new FieldClass() as IFieldEdit;
                    osmuserField.Name_2 = "osmuser";
                    osmuserField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmuserField.Required_2 = true;
                    osmuserField.Length_2 = 100;
                    fieldsEdit.AddField((IField)osmuserField);

                    IFieldEdit osmuidField = new FieldClass() as IFieldEdit;
                    osmuidField.Name_2 = "osmuid";
                    osmuidField.Required_2 = true;
                    osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmuidField);

                    IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit;
                    osmvisibleField.Name_2 = "osmvisible";
                    osmvisibleField.Required_2 = true;
                    osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmvisibleField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmvisibleField);

                    IFieldEdit osmversionField = new FieldClass() as IFieldEdit;
                    osmversionField.Name_2 = "osmversion";
                    osmversionField.Required_2 = true;
                    osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    fieldsEdit.AddField((IField)osmversionField);

                    IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit;
                    osmchangesetField.Name_2 = "osmchangeset";
                    osmchangesetField.Required_2 = true;
                    osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmchangesetField);

                    IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit;
                    osmtimestampField.Name_2 = "osmtimestamp";
                    osmtimestampField.Required_2 = true;
                    osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate;
                    fieldsEdit.AddField((IField)osmtimestampField);

                    IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit;
                    osmrelationIDField.Name_2 = "osmMemberOf";
                    osmrelationIDField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmrelationIDField);

                    //IFieldEdit osmrelationsField = new FieldClass() as IFieldEdit;
                    //osmrelationsField.Name_2 = "osmMembers";
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    //    osmrelationsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmrelationsField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    //fieldsEdit.AddField((IField)osmrelationsField);
                    IFieldEdit osmSupportingElementField = new FieldClass() as IFieldEdit;
                    osmSupportingElementField.Name_2 = "osmSupportingElement";
                    osmSupportingElementField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmSupportingElementField.Length_2 = 5;
                    osmSupportingElementField.DefaultValue_2 = "no";
                    osmSupportingElementField.Required_2 = true;
                    fieldsEdit.AddField((IField)osmSupportingElementField);

                    IFieldEdit osmMembersField = new FieldClass() as IFieldEdit;
                    osmMembersField.Name_2 = "osmMembers";
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmMembersField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    osmMembersField.Required_2 = true;
                    //}
                    //else
                    //{
                    //    osmMembersField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmMembersField);

                    //IFieldEdit osmTrackChangesField = new FieldClass() as IFieldEdit;
                    //osmTrackChangesField.Name_2 = "osmTrackChanges";
                    //osmTrackChangesField.Required_2 = true;
                    //osmTrackChangesField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    //osmTrackChangesField.DefaultValue_2 = 0;
                    //fieldsEdit.AddField((IField)osmTrackChangesField);

                    fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
                }

                System.String strShapeField = "";

                // locate the shape field
                for (int j = 0; j < fields.FieldCount; j++)
                {
                    if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry)
                    {
                        strShapeField = fields.get_Field(j).Name;

                        // redefine geometry type

                        IFieldEdit shapeField = fields.get_Field(j) as IFieldEdit;
                        IGeometryDefEdit geometryDef = new GeometryDefClass() as IGeometryDefEdit;
                        geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                        geometryDef.HasZ_2 = false;
                        geometryDef.HasM_2 = false;
                        geometryDef.GridCount_2 = 1;
                        geometryDef.set_GridSize(0, 0);

                        geometryDef.SpatialReference_2 = ((IGeoDataset)featureDataset).SpatialReference;

                        shapeField.GeometryDef_2 = (IGeometryDef)geometryDef;

                        break;
                    }
                }

                // Use IFieldChecker to create a validated fields collection.
                ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
                ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.

                // finally create and return the feature class
                if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
                {
                    featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
                    IPropertySet extensionPropertySet = new PropertySetClass();
                    extensionPropertySet.SetProperty("VERSION", OSMClassExtensionManager.Version);
                    ((IClassSchemaEdit2)featureClass).AlterClassExtensionProperties(extensionPropertySet);

                }
                else
                {
                    featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
                    IPropertySet extensionPropertySet = new PropertySetClass();
                    extensionPropertySet.SetProperty("VERSION", OSMClassExtensionManager.Version);
                    ((IClassSchemaEdit2)featureClass).AlterClassExtensionProperties(extensionPropertySet);
                }

                // create the openstreetmap spcific metadata
                _osmUtility.CreateOSMMetadata((IDataset)featureClass, metadataAbstract, metadataPurpose);

                // the change at release 2.1 requires a new model name
                IModelInfo fcModelInfo = featureClass as IModelInfo;
                if (fcModelInfo != null)
                {
                    fcModelInfo.ModelName = OSMClassExtensionManager.OSMModelName;
                }

            }
            catch
            {
                throw;
            }

            return featureClass;
        }
Exemplo n.º 26
0
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            _message = message;

            IFeatureClass osmPointFeatureClass = null;
            IFeatureClass osmLineFeatureClass = null;
            IFeatureClass osmPolygonFeatureClass = null;

            try
            {
                DateTime syncTime = DateTime.Now;

                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPParameter baseURLParameter = paramvalues.get_Element(in_downloadURLNumber) as IGPParameter;
                IGPString baseURLString = gpUtilities3.UnpackGPValue(baseURLParameter) as IGPString;

                if (baseURLString == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), baseURLParameter.Name));
                }

                IGPParameter downloadExtentParameter = paramvalues.get_Element(in_downloadExtentNumber) as IGPParameter;
                IGPValue downloadExtentGPValue = gpUtilities3.UnpackGPValue(downloadExtentParameter);

                esriGPExtentEnum gpExtent;
                IEnvelope downloadEnvelope = gpUtilities3.GetExtent(downloadExtentGPValue, out gpExtent);

                IGPParameter includeAllReferences = paramvalues.get_Element(in_includeReferencesNumber) as IGPParameter;
                IGPBoolean includeAllReferencesGPValue = gpUtilities3.UnpackGPValue(includeAllReferences) as IGPBoolean;

                if (includeAllReferencesGPValue == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), includeAllReferences.Name));
                }

                IEnvelope newExtent = null;

                ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass() as ISpatialReferenceFactory;
                ISpatialReference wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984) as ISpatialReference;

                // this determines the spatial reference as defined from the gp environment settings and the initial wgs84 SR
                ISpatialReference downloadSpatialReference = gpUtilities3.GetGPSpRefEnv(envMgr, wgs84, newExtent, 0, 0, 0, 0, null);

                downloadEnvelope.Project(wgs84);

                Marshal.ReleaseComObject(wgs84);
                Marshal.ReleaseComObject(spatialReferenceFactory);

                HttpWebRequest httpClient;
                System.Xml.Serialization.XmlSerializer serializer = null;
                serializer = new XmlSerializer(typeof(osm));

                // get the capabilities from the server
                HttpWebResponse httpResponse = null;

                api apiCapabilities = null;
                CultureInfo enUSCultureInfo = new CultureInfo("en-US");

#if DEBUG
                Console.WriteLine("Debbuging");
                message.AddMessage("Debugging...");
#endif

                message.AddMessage(resourceManager.GetString("GPTools_OSMGPDownload_startingDownloadRequest"));

                try
                {
                    httpClient = HttpWebRequest.Create(baseURLString.Value + "/api/capabilities") as HttpWebRequest;
                    httpClient = AssignProxyandCredentials(httpClient);

                    httpResponse = httpClient.GetResponse() as HttpWebResponse;

                    osm osmCapabilities = null;

                    Stream stream = httpResponse.GetResponseStream();

                    XmlTextReader xmlReader = new XmlTextReader(stream);
                    osmCapabilities = serializer.Deserialize(xmlReader) as osm;
                    xmlReader.Close();

                    apiCapabilities = osmCapabilities.Items[0] as api;

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    message.AddError(120009, ex.Message);

                    if (ex is WebException)
                    {
                        WebException webException = ex as WebException;
                        string serverErrorMessage = webException.Response.Headers["Error"];
                        if (!String.IsNullOrEmpty(serverErrorMessage))
                        {
                            message.AddError(120009, serverErrorMessage);
                        }
                    }

                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Close();
                    }
                    httpClient = null;
                }

                if (apiCapabilities != null)
                {
                    // check for the extent
                    double roiArea = ((IArea)downloadEnvelope).Area;
                    double capabilitiyArea = Convert.ToDouble(apiCapabilities.area.maximum, new CultureInfo("en-US"));

                    if (roiArea > capabilitiyArea)
                    {
                        message.AddAbort(resourceManager.GetString("GPTools_OSMGPDownload_exceedDownloadROI"));
                        return;
                    }
                }

                // check for user interruption
                if (TrackCancel.Continue() == false)
                {
                    return;
                }

                // list containing either only one document for a single bbox request or multiple if relation references need to be resolved
                List<string> downloadedOSMDocuments = new List<string>();

                string requestURL = baseURLString.Value + "/api/0.6/map?bbox=" + downloadEnvelope.XMin.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.YMin.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.XMax.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.YMax.ToString("f5", enUSCultureInfo);
                string osmMasterDocument = downloadOSMDocument(ref message, requestURL, apiCapabilities);

                // check if the initial request was successfull
                // it might have failed at this point because too many nodes were requested or because of something else
                if (String.IsNullOrEmpty(osmMasterDocument))
                {
                    message.AddAbort(resourceManager.GetString("GPTools_OSMGPDownload_noValidOSMResponse"));
                    return;
                }

                // add the "master document" ) original bbox request to the list
                downloadedOSMDocuments.Add(osmMasterDocument);

                if (includeAllReferencesGPValue.Value)
                {
                    List<string> nodeList = new List<string>();
                    List<string> wayList = new List<string>();
                    List<string> relationList = new List<string>();
                    // check for user interruption
                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    parseOSMDocument(osmMasterDocument, ref message, ref nodeList, ref wayList, ref relationList, ref downloadedOSMDocuments, baseURLString.Value, apiCapabilities);
                }

                string metadataAbstract = resourceManager.GetString("GPTools_OSMGPDownload_metadata_abstract");
                string metadataPurpose = resourceManager.GetString("GPTools_OSMGPDownload_metadata_purpose");

                IGPParameter targetDatasetParameter = paramvalues.get_Element(out_targetDatasetNumber) as IGPParameter;
                IDEDataset2 targetDEDataset2 = gpUtilities3.UnpackGPValue(targetDatasetParameter) as IDEDataset2;
                IGPValue targetDatasetGPValue = gpUtilities3.UnpackGPValue(targetDatasetParameter);
                string targetDatasetName = ((IGPValue)targetDEDataset2).GetAsText();

                IDataElement targetDataElement = targetDEDataset2 as IDataElement;
                IDataset targetDataset = gpUtilities3.OpenDatasetFromLocation(targetDataElement.CatalogPath);

                IName parentName = null;

                try
                {
                    parentName = gpUtilities3.CreateParentFromCatalogPath(targetDataElement.CatalogPath);
                }
                catch
                {
                    message.AddError(120033, resourceManager.GetString("GPTools_OSMGPFileReader_unable_to_create_fd"));
                    return;
                }

                // test if the feature classes already exists, 
                // if they do and the environments settings are such that an overwrite is not allowed we need to abort at this point
                IGeoProcessorSettings gpSettings = (IGeoProcessorSettings)envMgr;
                if (gpSettings.OverwriteOutput == true)
                {
                }

                else
                {
                    if (gpUtilities3.Exists((IGPValue)targetDEDataset2) == true)
                    {
                        message.AddError(120010, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_basenamealreadyexists"), targetDataElement.Name));
                        return;
                    }
                }

                string Container = "";
                IDEUtilities deUtilities = new DEUtilitiesClass();
                deUtilities.ParseContainer(targetDataElement.CatalogPath, ref Container);

                IFeatureWorkspace featureWorkspace = gpUtilities3.OpenFromString(Container) as IFeatureWorkspace;

                if (featureWorkspace == null)
                {
                    message.AddError(120011, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nofeatureworkspace"), Container));
                    return;
                }

                // load the descriptions from which to derive the domain values
                OSMDomains availableDomains = null;

                System.Xml.XmlTextReader reader = null;
                try
                {
                    if (File.Exists(m_editorConfigurationSettings["osmdomainsfilepath"]))
                    {
                        reader = new System.Xml.XmlTextReader(m_editorConfigurationSettings["osmdomainsfilepath"]);
                    }
                }
                // If is in the server and hasn't been install all the configuration files
                catch
                {
                    if (File.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(OSMGPDownload)).Location), "osm_domains.xml")))
                    {
                        reader = new System.Xml.XmlTextReader(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(OSMGPDownload)).Location), "osm_domains.xml"));
                    }
                }

                if (reader == null)
                {
                    message.AddError(120012, resourceManager.GetString("GPTools_OSMGPDownload_NoDomainConfigFile"));
                    return;
                }

                try
                {
                    serializer = new XmlSerializer(typeof(OSMDomains));
                    availableDomains = serializer.Deserialize(reader) as OSMDomains;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    message.AddError(120013, ex.Message);
                    return;
                }

                #region define and add domains to the workspace
                // we are using domains to guide the edit templates in the editor for ArcGIS desktop
                Dictionary<string, IDomain> codedValueDomains = new Dictionary<string, IDomain>();

                foreach (var domain in availableDomains.domain)
                {
                    ICodedValueDomain pointCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)pointCodedValueDomain).Name = domain.name + "_pt";
                    ((IDomain)pointCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    ICodedValueDomain lineCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)lineCodedValueDomain).Name = domain.name + "_ln";
                    ((IDomain)lineCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    ICodedValueDomain polygonCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)polygonCodedValueDomain).Name = domain.name + "_ply";
                    ((IDomain)polygonCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    for (int i = 0; i < domain.domainvalue.Length; i++)
                    {
                        for (int domainGeometryIndex = 0; domainGeometryIndex < domain.domainvalue[i].geometrytype.Length; domainGeometryIndex++)
                        {
                            switch (domain.domainvalue[i].geometrytype[domainGeometryIndex])
                            {
                                case geometrytype.point:
                                    pointCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                case geometrytype.line:
                                    lineCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                case geometrytype.polygon:
                                    polygonCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }

                    // add the domain tables to the domains collection
                    codedValueDomains.Add(((IDomain)pointCodedValueDomain).Name, (IDomain)pointCodedValueDomain);
                    codedValueDomains.Add(((IDomain)lineCodedValueDomain).Name, (IDomain)lineCodedValueDomain);
                    codedValueDomains.Add(((IDomain)polygonCodedValueDomain).Name, (IDomain)polygonCodedValueDomain);
                }

                IWorkspaceDomains workspaceDomain = featureWorkspace as IWorkspaceDomains;
                foreach (var domain in codedValueDomains.Values)
                {
                    IDomain testDomain = null;
                    try
                    {
                        testDomain = workspaceDomain.get_DomainByName(domain.Name);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    }

                    if (testDomain == null)
                    {
                        workspaceDomain.AddDomain(domain);
                    }
                }
                #endregion

                IGPEnvironment configKeyword = getEnvironment(envMgr, "configKeyword");
                IGPString gpString = null;
                if (configKeyword != null)
                    gpString = configKeyword.Value as IGPString;

                string storageKeyword = String.Empty;

                if (gpString != null)
                {
                    storageKeyword = gpString.Value;
                }

                IFeatureDataset targetFeatureDataset = null;
                if (gpUtilities3.Exists((IGPValue)targetDEDataset2))
                {
                    targetFeatureDataset = gpUtilities3.OpenDataset((IGPValue)targetDEDataset2) as IFeatureDataset;
                }
                else
                {
                    targetFeatureDataset = featureWorkspace.CreateFeatureDataset(targetDataElement.Name, downloadSpatialReference);
                }


                ESRI.ArcGIS.esriSystem.UID osmClassExtensionUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                //GUID for the OSM feature class extension
                osmClassExtensionUID.Value = "{65CA4847-8661-45eb-8E1E-B2985CA17C78}";


                downloadSpatialReference = ((IGeoDataset)targetFeatureDataset).SpatialReference;
                OSMToolHelper osmToolHelper = new OSMToolHelper();

                #region create point/line/polygon feature classes and tables
                // points
                try
                {
                    osmPointFeatureClass = osmToolHelper.CreatePointFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_pt", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120014, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullpointfeatureclass"), ex.Message));
                    return;
                }

                if (osmPointFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmPointFeatureClass.RemoveOSMClassExtension();

                // lines
                try
                {
                    osmLineFeatureClass = osmToolHelper.CreateLineFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_ln", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120015, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nulllinefeatureclass"), ex.Message));
                    return;
                }

                if (osmLineFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmLineFeatureClass.RemoveOSMClassExtension();

                // polygons
                try
                {
                    osmPolygonFeatureClass = osmToolHelper.CreatePolygonFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_ply", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120016, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullpolygonfeatureclass"), ex.Message));
                    return;
                }

                if (osmPolygonFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmPolygonFeatureClass.RemoveOSMClassExtension();

                // relation table
                ITable relationTable = null;

                try
                {
                    relationTable = osmToolHelper.CreateRelationTable((IWorkspace2)featureWorkspace, targetDataElement.Name + "_osm_relation", null, storageKeyword, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120017, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullrelationtable"), ex.Message));
                    return;
                }

                if (relationTable == null)
                {
                    return;
                }

                // revision table 
                ITable revisionTable = null;

                try
                {
                    revisionTable = osmToolHelper.CreateRevisionTable((IWorkspace2)featureWorkspace, targetDataElement.Name + "_osm_revision", null, storageKeyword);
                }
                catch (Exception ex)
                {
                    message.AddError(120018, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullrelationtable"), ex.Message));
                    return;
                }

                if (revisionTable == null)
                {
                    return;
                }

                // check for user interruption
                if (TrackCancel.Continue() == false)
                {
                    return;
                }
                #endregion

                #region clean any existing data from loading targets
                ESRI.ArcGIS.Geoprocessing.IGeoProcessor2 gp = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
                IGeoProcessorResult gpResult = new GeoProcessorResultClass();

                try
                {
                    IVariantArray truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_pt");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ln");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ply");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "_osm_relation");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "_osm_revision");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);
                }
                catch (Exception ex)
                {
                    message.AddWarning(ex.Message);
                }
                #endregion

                Dictionary<string, OSMToolHelper.simplePointRef> osmNodeDictionary = null;

                foreach (string osmDownloadDocument in downloadedOSMDocuments.Reverse<string>())
                {
                    long nodeCapacity = 0;
                    long wayCapacity = 0;
                    long relationCapacity = 0;

                    message.AddMessage(resourceManager.GetString("GPTools_OSMGPFileReader_countingNodes"));

                    osmToolHelper.countOSMStuff(osmDownloadDocument, ref nodeCapacity, ref wayCapacity, ref relationCapacity, ref TrackCancel);
                    message.AddMessage(String.Format(resourceManager.GetString("GPTools_OSMGPFileReader_countedElements"), nodeCapacity, wayCapacity, relationCapacity));

                    if (osmNodeDictionary == null)
                        osmNodeDictionary = new Dictionary<string, OSMToolHelper.simplePointRef>(Convert.ToInt32(nodeCapacity));

                    #region load points
                    osmToolHelper.loadOSMNodes(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, false, false, Convert.ToInt32(nodeCapacity), ref osmNodeDictionary, featureWorkspace, downloadSpatialReference, availableDomains, false);
                    #endregion

                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    #region load ways
                    if (wayCapacity > 0)
                    {
                        List<string> missingWays = null;
                        missingWays = osmToolHelper.loadOSMWays(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, osmLineFeatureClass, osmPolygonFeatureClass, false, false, Convert.ToInt32(wayCapacity), ref osmNodeDictionary, featureWorkspace, downloadSpatialReference, availableDomains, false);
                    }
                    #endregion

                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    # region for conserve memory condition, update refcount
                    int refCounterFieldIndex = osmPointFeatureClass.Fields.FindField("wayRefCount");
                    if (refCounterFieldIndex > -1)
                    {
                        foreach (var refNode in osmNodeDictionary)
                        {
                            try
                            {
                                IFeature updateFeature = osmPointFeatureClass.GetFeature(refNode.Value.pointObjectID);

                                int refCount = refNode.Value.RefCounter;
                                if (refCount == 0)
                                {
                                    refCount = 1;
                                }

                                updateFeature.set_Value(refCounterFieldIndex, refCount);
                                updateFeature.Store();
                            }
                            catch { }
                        }
                    }

                    #endregion

                    // check for user interruption
                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }
                    ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                    #region for local geodatabases enforce spatial integrity
                    bool storedOriginal = geoProcessor.AddOutputsToMap;
                    geoProcessor.AddOutputsToMap = false;

                    try
                    {
                        if (osmLineFeatureClass != null)
                        {
                            if (((IDataset)osmLineFeatureClass).Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                            {
                                IVariantArray lineRepairParameters = new VarArrayClass();
                                lineRepairParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ln");
                                lineRepairParameters.Add("DELETE_NULL");

                                IGeoProcessorResult2 gpResults = gp.Execute("RepairGeometry_management", lineRepairParameters, TrackCancel) as IGeoProcessorResult2;
                                message.AddMessages(gpResults.GetResultMessages());
                            }
                        }

                        if (osmPolygonFeatureClass != null)
                        {
                            if (((IDataset)osmPolygonFeatureClass).Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                            {
                                IVariantArray polygonRepairParameters = new VarArrayClass();
                                polygonRepairParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ply");
                                polygonRepairParameters.Add("DELETE_NULL");

                                IGeoProcessorResult2 gpResults = gp.Execute("RepairGeometry_management", polygonRepairParameters, TrackCancel) as IGeoProcessorResult2;
                                message.AddMessages(gpResults.GetResultMessages());
                            }
                        }
                    }
                    catch
                    {
                        message.AddWarning(resourceManager.GetString("GPTools_OSMGPDownload_repairgeometryfailure"));
                    }
                    geoProcessor.AddOutputsToMap = storedOriginal;
                    #endregion



                    #region load relations
                    if (relationCapacity > 0)
                    {
                        List<string> missingRelations = null;
                        missingRelations = osmToolHelper.loadOSMRelations(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, osmLineFeatureClass, osmPolygonFeatureClass, Convert.ToInt32(relationCapacity), relationTable, availableDomains, false, false);
                    }
                    #endregion
                }

                #region update the references counts and member lists for nodes
                message.AddMessage(resourceManager.GetString("GPTools_OSMGPFileReader_updatereferences"));
                IFeatureCursor pointUpdateCursor = null;

                using (SchemaLockManager ptLockManager = new SchemaLockManager(osmPointFeatureClass as ITable))
                {
                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        int updateCount = 0;
                        pointUpdateCursor = osmPointFeatureClass.Update(null, false);
                        updateCount = ((ITable)osmPointFeatureClass).RowCount(null);

                        IStepProgressor stepProgressor = TrackCancel as IStepProgressor;

                        if (stepProgressor != null)
                        {
                            stepProgressor.MinRange = 0;
                            stepProgressor.MaxRange = updateCount;
                            stepProgressor.Position = 0;
                            stepProgressor.Message = resourceManager.GetString("GPTools_OSMGPFileReader_updatepointrefcount");
                            stepProgressor.StepValue = 1;
                            stepProgressor.Show();
                        }

                        comReleaser.ManageLifetime(pointUpdateCursor);

                        IFeature pointFeature = pointUpdateCursor.NextFeature();

                        int osmPointIDFieldIndex = osmPointFeatureClass.FindField("OSMID");
                        int osmWayRefCountFieldIndex = osmPointFeatureClass.FindField("wayRefCount");
                        int positionCounter = 0;
                        while (pointFeature != null)
                        {
                            positionCounter++;
                            string nodeID = Convert.ToString(pointFeature.get_Value(osmPointIDFieldIndex));

                            // let get the reference counter from the internal node dictionary
                            if (osmNodeDictionary[nodeID].RefCounter == 0)
                            {
                                pointFeature.set_Value(osmWayRefCountFieldIndex, 1);
                            }
                            else
                            {
                                pointFeature.set_Value(osmWayRefCountFieldIndex, osmNodeDictionary[nodeID].RefCounter);
                            }

                            pointUpdateCursor.UpdateFeature(pointFeature);

                            if (pointFeature != null)
                                Marshal.ReleaseComObject(pointFeature);

                            pointFeature = pointUpdateCursor.NextFeature();

                            if (stepProgressor != null)
                            {
                                stepProgressor.Position = positionCounter;
                            }
                        }

                        if (stepProgressor != null)
                        {
                            stepProgressor.Hide();
                        }
                    }
                }
                #endregion

                // clean all the downloaded OSM files
                foreach (string osmFile in downloadedOSMDocuments)
                {
                    if (File.Exists(osmFile))
                    {
                        try
                        {
                            File.Delete(osmFile);
                        }
                        catch { }
                    }
                }

                SyncState.StoreLastSyncTime(targetDatasetName, syncTime);

                gpUtilities3 = new GPUtilitiesClass() as IGPUtilities3;

                // repackage the feature class into their respective gp values
                IGPParameter pointFeatureClassParameter = paramvalues.get_Element(out_osmPointsNumber) as IGPParameter;
                IGPValue pointFeatureClassPackGPValue = gpUtilities3.UnpackGPValue(pointFeatureClassParameter);
                gpUtilities3.PackGPValue(pointFeatureClassPackGPValue, pointFeatureClassParameter);

                IGPParameter lineFeatureClassParameter = paramvalues.get_Element(out_osmLinesNumber) as IGPParameter;
                IGPValue lineFeatureClassPackGPValue = gpUtilities3.UnpackGPValue(lineFeatureClassParameter);
                gpUtilities3.PackGPValue(lineFeatureClassPackGPValue, lineFeatureClassParameter);

                IGPParameter polygonFeatureClassParameter = paramvalues.get_Element(out_osmPolygonsNumber) as IGPParameter;
                IGPValue polygon1FeatureClassPackGPValue = gpUtilities3.UnpackGPValue(polygonFeatureClassParameter);
                gpUtilities3.PackGPValue(polygon1FeatureClassPackGPValue, polygonFeatureClassParameter);

                gpUtilities3.ReleaseInternals();
                Marshal.ReleaseComObject(gpUtilities3);

                Marshal.ReleaseComObject(baseURLString);
                Marshal.ReleaseComObject(downloadExtentGPValue);
                Marshal.ReleaseComObject(downloadEnvelope);
                Marshal.ReleaseComObject(includeAllReferences);
                Marshal.ReleaseComObject(downloadSpatialReference);

                if (osmToolHelper != null)
                    osmToolHelper = null;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                message.AddError(120019, ex.Message);
            }
            finally
            {
                try
                {
                    if (osmPointFeatureClass != null)
                    {
                        osmPointFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmPointFeatureClass);
                    }

                    if (osmLineFeatureClass != null)
                    {
                        osmLineFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmLineFeatureClass);
                    }

                    if (osmPolygonFeatureClass != null)
                    {
                        osmPolygonFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmPolygonFeatureClass);
                    }
                }
                catch (Exception ex)
                {
                    message.AddError(120020, ex.ToString());
                }
            }
        }
 internal static GoogleMapsEngineToolsExtensionForArcGIS GetExtension()
 {
     // Extension loads just in time, call FindExtension to load it.
     if (s_extension == null)
     {
         ESRI.ArcGIS.esriSystem.UID extID = new ESRI.ArcGIS.esriSystem.UIDClass();
         extID.Value = ThisAddIn.IDs.GoogleMapsEngineToolsExtensionForArcGIS;
         ArcMap.Application.FindExtensionByCLSID(extID);
     }
     return s_extension;
 }
Exemplo n.º 28
0
 private ESRI.ArcGIS.esriSystem.UID getUID(string uid)
 {
     ESRI.ArcGIS.esriSystem.IUID vl = new ESRI.ArcGIS.esriSystem.UIDClass();
     vl.Value = uid;
     return((ESRI.ArcGIS.esriSystem.UID)(vl));
 }
Exemplo n.º 29
0
        private bool StartEditor(IWorkspace pWKS )
        {
            IApplication pApp;
            UID eUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            IVersion pVer;

            try
            {
                SW1.Reset();
                SW1.Start();

                Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
                System.Object obj = Activator.CreateInstance(t);
                pApp = obj as IApplication;

                eUID.Value = "esriEditor.Editor";
                pEditor = pApp.FindExtensionByCLSID(eUID) as IEditor;

                pVer = (IVersion)Workspace;

                if (pVer == null)
                {
                    if (pWKS != null)
                    {
                        pVer = (IVersion)pWKS;
                        Workspace = pWKS;
                    }
                    else
                    {
                        Logger.WriteLine("No Valid workspace found");
                        return false;
                    }
                }
                this.Logger.WriteLine("Workspace Name:" + pVer.VersionName);
                if (pEditor != null)
                {
                    if (pEditor.EditState != esriEditState.esriStateEditing)
                    {

                        pEditor.StartEditing(Workspace);
                        SW1.Stop();
                        RecordActionTime("StartEditing: " , SW1.ElapsedMilliseconds);
                    }
                    else
                    {
                        this.Logger.WriteLine("Already Editing");
                    }
                }
                else
                {
                    this.Logger.WriteLine("No Editor");
                }
                return true;
            }
            catch (System.Runtime.InteropServices.COMException ComEX)
            {
                Logger.WriteLine("Error in StartEditor: " + ComEX.Message + " " + ComEX.StackTrace);
                return false;
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in StartEditor: " + EX.Message + " " + EX.StackTrace);
                return false;
            }
        }
Exemplo n.º 30
0
        void landPriceTool_Changed(object sender, EventArgs e)
        {
            //_mathua4LandPrice = _landPriceTool.GetMaThua();
            //MessageBox.Show(string.Format("so luong select:{0}",m_mapControl.Map.SelectionCount));
            //ISelection l = m_mapControl.Map.;
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            IEnumLayer layers = ((IMapControl3)_map.GetHook()).Map.get_Layers(null, false);
            ILayer layer = null;
            IFeatureLayer ftl = new FeatureLayerClass();
            ISelectionSet sls = null;
            IFeatureSelection fts = null;
            int c = 0;
            if (layers.Next() == null)
            {
                MessageBox.Show(string.Format("ko co layer: {0}", ((IMapControl3)_map.GetHook()).Map.LayerCount));
            }

            //while ((layer = layers.Next()) != null)
            //{
            //    ftl=(IFeatureLayer)layer;
            //    fts=(IFeatureSelection)ftl;
            //    c=fts.SelectionSet.Count;
            //    if (c != 0)
            //    {
            //        MessageBox.Show(string.Format("layer:{0}, selected:{1}", ftl.FeatureClass.AliasName, c));
            //    }
            //}
            //xemGiaDatView.MaThua = _mathua4LandPrice;
            //xemGiaDatView.Show();
            //xemGiaDatView.Query();
        }
        private ESRI.ArcGIS.Geodatabase.IFeatureClass CreatePointFeatureClass(System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID)
        {
            if (featureClassName == "") return null; // name was not passed in

            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
            // Create a new in-memory workspace. This returns a name object.
            IWorkspaceName workspaceName = workspaceFactory.Create(null, "OSMPointsWorkspace", null, 0);
            IName name = (IName)workspaceName;

            // Open the workspace through the name object.
            IWorkspace workspace = (IWorkspace)name.Open();

            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

            // assign the class id value if not assigned
            if (CLSID == null)
            {
                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                // add the OSM ID field
                IFieldEdit osmIDField = new FieldClass() as IFieldEdit;
                osmIDField.Name_2 = "OSMID";
                osmIDField.Type_2 = esriFieldType.esriFieldTypeString;
                osmIDField.Length_2 = 20;
                fieldsEdit.AddField((IField)osmIDField);

                // add the field for the tag cloud for all other tag/value pairs
                IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit;
                osmXmlTagsField.Name_2 = "osmTags";
                    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                fieldsEdit.AddField((IField)osmXmlTagsField);

                // user, uid, visible, version, changeset, timestamp
                IFieldEdit osmuserField = new FieldClass() as IFieldEdit;
                osmuserField.Name_2 = "osmuser";
                osmuserField.Type_2 = esriFieldType.esriFieldTypeString;
                osmuserField.Length_2 = 100;
                fieldsEdit.AddField((IField) osmuserField);

                IFieldEdit osmuidField = new FieldClass() as IFieldEdit;
                osmuidField.Name_2 = "osmuid";
                osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField((IField)osmuidField);

                IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit;
                osmvisibleField.Name_2 = "osmvisible";
                osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString;
                osmvisibleField.Length_2 = 20;
                fieldsEdit.AddField((IField)osmvisibleField);

                IFieldEdit osmversionField = new FieldClass() as IFieldEdit;
                osmversionField.Name_2 = "osmversion";
                osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                fieldsEdit.AddField((IField)osmversionField);

                IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit;
                osmchangesetField.Name_2 = "osmchangeset";
                osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField((IField)osmchangesetField);

                IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit;
                osmtimestampField.Name_2 = "osmtimestamp";
                osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate;
                fieldsEdit.AddField((IField)osmtimestampField);

                IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit;
                osmrelationIDField.Name_2 = "osmMemberOf";
                    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob;
                fieldsEdit.AddField((IField)osmrelationIDField);

                IFieldEdit hasOSMTagsField = new FieldClass() as IFieldEdit;
                hasOSMTagsField.Name_2 = "hasOSMTags";

                IFieldEdit osmSupportingElementField = new FieldClass() as IFieldEdit;
                osmSupportingElementField.Name_2 = "osmSupportingElement";
                osmSupportingElementField.Type_2 = esriFieldType.esriFieldTypeString;
                osmSupportingElementField.Length_2 = 5;
                fieldsEdit.AddField((IField) osmSupportingElementField);

                IFieldEdit wayRefCountField = new FieldClass() as IFieldEdit;
                wayRefCountField.Name_2 = "wayRefCount";
                wayRefCountField.Type_2 = esriFieldType.esriFieldTypeInteger;
                wayRefCountField.DefaultValue_2 = 0;
                fieldsEdit.AddField((IField)wayRefCountField);

                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;

                    // redefine geometry type

                    IFieldEdit shapeField = fields.get_Field(j) as IFieldEdit;
                    IGeometryDefEdit geometryDef = new GeometryDefClass() as IGeometryDefEdit;
                    geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                    geometryDef.HasZ_2 = false;
                    geometryDef.HasM_2 = false;
                    geometryDef.GridCount_2 = 1;
                    geometryDef.set_GridSize(0, 1);

                    ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();
                    ISpatialReference wgs84 = spatialRefFactory.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984) as ISpatialReference;
                    geometryDef.SpatialReference_2 = wgs84;

                    shapeField.GeometryDef_2 = (IGeometryDef)geometryDef;

                    break;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class
                try
                {
                    featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, null, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, "");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

            return featureClass;
        }
        private bool SetupFeaturePropertySheet(ILayer layer)
        {
            if (layer == null)
            {
                return(false);
            }
            try
            {
                ESRI.ArcGIS.Framework.IComPropertySheet pComPropSheet;
                pComPropSheet       = new ESRI.ArcGIS.Framework.ComPropertySheetClass();
                pComPropSheet.Title = layer.Name + "- Properties";

                ESRI.ArcGIS.esriSystem.UID pPPUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                pComPropSheet.AddCategoryID(pPPUID);

                // General....
                ESRI.ArcGIS.Framework.IPropertyPage pGenPage = new ESRI.ArcGIS.CartoUI.GeneralLayerPropPageClass();
                pComPropSheet.AddPage(pGenPage);

                // Source
                ESRI.ArcGIS.Framework.IPropertyPage pSrcPage = new ESRI.ArcGIS.CartoUI.FeatureLayerSourcePropertyPageClass();
                pComPropSheet.AddPage(pSrcPage);

                // Selection...
                ESRI.ArcGIS.Framework.IPropertyPage pSelectPage = new ESRI.ArcGIS.CartoUI.FeatureLayerSelectionPropertyPageClass();
                pComPropSheet.AddPage(pSelectPage);

                // Display....
                ESRI.ArcGIS.Framework.IPropertyPage pDispPage = new ESRI.ArcGIS.CartoUI.FeatureLayerDisplayPropertyPageClass();
                pComPropSheet.AddPage(pDispPage);

                // Symbology....
                ESRI.ArcGIS.Framework.IComPropertyPage pDrawPage = new ESRI.ArcGIS.CartoUI.LayerDrawingPropertyPageClass();
                pComPropSheet.AddPage(pDrawPage);

                // Fields...
                ESRI.ArcGIS.Framework.IPropertyPage pFieldsPage = new ESRI.ArcGIS.CartoUI.LayerFieldsPropertyPageClass();
                pComPropSheet.AddPage(pFieldsPage);

                // Definition Query...
                ESRI.ArcGIS.Framework.IPropertyPage pQueryPage = new ESRI.ArcGIS.CartoUI.LayerDefinitionQueryPropertyPageClass();
                pComPropSheet.AddPage(pQueryPage);

                // Labels....
                ESRI.ArcGIS.Framework.IPropertyPage pSelPage = new ESRI.ArcGIS.CartoUI.LayerLabelsPropertyPageClass();
                pComPropSheet.AddPage(pSelPage);

                // Joins & Relates....
                ESRI.ArcGIS.Framework.IPropertyPage pJoinPage = new ESRI.ArcGIS.ArcMapUI.JoinRelatePageClass();
                pComPropSheet.AddPage(pJoinPage);

                // Setup layer link
                ESRI.ArcGIS.esriSystem.ISet pMySet = new ESRI.ArcGIS.esriSystem.SetClass();
                pMySet.Add(layer);
                pMySet.Reset();

                // make the symbology tab active
                pComPropSheet.ActivePage = 4;

                // show the property sheet
                bool bOK = pComPropSheet.EditProperties(pMySet, this.Handle.ToInt32());

                m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
                m_TOCControl.Update();
                return(bOK);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Exemplo n.º 33
0
        public IFeatureClass createFeatureClassInMemory(string strName, IFields FeatureFields, IWorkspace pWS, esriFeatureType featType)
        {
            ESRI.ArcGIS.esriSystem.UID CLSID = null;
            //ESRI.ArcGIS.esriSystem.UID CLSEXT = null;
            IFeatureWorkspace pFWS = null;

            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = null;
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            try
            {
                //CLSEXT = null;

                pFWS = (IFeatureWorkspace)pWS;


                if (CLSID == null)
                {
                    CLSID       = new ESRI.ArcGIS.esriSystem.UIDClass();
                    CLSID.Value = "esriGeoDatabase.Feature";
                }


                fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                enumFieldError  = null;
                validatedFields = null;
                fieldChecker.ValidateWorkspace = pWS;
                fieldChecker.Validate(FeatureFields, out enumFieldError, out validatedFields);
                bool          FCCreated = false;
                IFeatureClass newFeat   = null;
                int           loopCnt   = 0;
                while (FCCreated == false)
                {
                    try
                    {
                        if (loopCnt == 0)
                        {
                            loopCnt = loopCnt + 1;
                            newFeat = pFWS.CreateFeatureClass(strName, validatedFields, null, null, featType, "SHAPE", "");
                        }
                        else
                        {
                            loopCnt = loopCnt + 1;
                            newFeat = pFWS.CreateFeatureClass(strName + (loopCnt - 1).ToString(), validatedFields, null, null, featType, "SHAPE", "");
                        }
                        FCCreated = true;
                    }
                    catch
                    {
                        FCCreated = false;
                    }
                    if (loopCnt == 100)
                    {
                        FCCreated = true;
                    }
                }
                return(newFeat);
            }
            catch
            {
                return(null);
            }
            finally
            {
                CLSID = null;

                pFWS = null;

                fieldChecker    = null;
                enumFieldError  = null;
                validatedFields = null;
            }
        }
    //the guid of the layer
    public override void GetClassID(out Guid pClassID)
    {
      ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
      uid.Value = "RSSWeatherLayer3D.RSSWeatherLayer3DClass";

      pClassID = new Guid(Convert.ToString(uid.Value));
    }
        private bool SetupFeaturePropertySheet(ILayer layer)
        {
            if (layer == null) return false;
            try
            {
                ESRI.ArcGIS.Framework.IComPropertySheet pComPropSheet;
                pComPropSheet = new ESRI.ArcGIS.Framework.ComPropertySheetClass();
                pComPropSheet.Title = layer.Name + "- Properties";

                ESRI.ArcGIS.esriSystem.UID pPPUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                pComPropSheet.AddCategoryID(pPPUID);

                // General....
                ESRI.ArcGIS.Framework.IPropertyPage pGenPage = new ESRI.ArcGIS.CartoUI.GeneralLayerPropPageClass();
                pComPropSheet.AddPage(pGenPage);

                // Source
                ESRI.ArcGIS.Framework.IPropertyPage pSrcPage = new ESRI.ArcGIS.CartoUI.FeatureLayerSourcePropertyPageClass();
                pComPropSheet.AddPage(pSrcPage);

                // Selection...
                ESRI.ArcGIS.Framework.IPropertyPage pSelectPage = new ESRI.ArcGIS.CartoUI.FeatureLayerSelectionPropertyPageClass();
                pComPropSheet.AddPage(pSelectPage);

                // Display....
                ESRI.ArcGIS.Framework.IPropertyPage pDispPage = new ESRI.ArcGIS.CartoUI.FeatureLayerDisplayPropertyPageClass();
                pComPropSheet.AddPage(pDispPage);

                // Symbology....
                ESRI.ArcGIS.Framework.IComPropertyPage pDrawPage = new ESRI.ArcGIS.CartoUI.LayerDrawingPropertyPageClass();
                pComPropSheet.AddPage(pDrawPage);

                // Fields...
                ESRI.ArcGIS.Framework.IPropertyPage pFieldsPage = new ESRI.ArcGIS.CartoUI.LayerFieldsPropertyPageClass();
                pComPropSheet.AddPage(pFieldsPage);

                // Definition Query...
                ESRI.ArcGIS.Framework.IPropertyPage pQueryPage = new ESRI.ArcGIS.CartoUI.LayerDefinitionQueryPropertyPageClass();
                pComPropSheet.AddPage(pQueryPage);

                // Labels....
                ESRI.ArcGIS.Framework.IPropertyPage pSelPage = new ESRI.ArcGIS.CartoUI.LayerLabelsPropertyPageClass();
                pComPropSheet.AddPage(pSelPage);

                // Joins & Relates....
                ESRI.ArcGIS.Framework.IPropertyPage pJoinPage = new ESRI.ArcGIS.ArcMapUI.JoinRelatePageClass();
                pComPropSheet.AddPage(pJoinPage);

                // Setup layer link
                ESRI.ArcGIS.esriSystem.ISet pMySet = new ESRI.ArcGIS.esriSystem.SetClass();
                pMySet.Add(layer);
                pMySet.Reset();

                // make the symbology tab active
                pComPropSheet.ActivePage = 4;

                // show the property sheet
                bool bOK = pComPropSheet.EditProperties(pMySet, this.Handle.ToInt32());

                m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
                m_TOCControl.Update();
                return (bOK);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Exemplo n.º 36
0
        public void LoadAnalysisObjectsByField(ESRI.ArcGIS.Geodatabase.ITable inputClass,
                                               string naClassName, ESRI.ArcGIS.NetworkAnalyst.INAContext naContext)
        {
            // Both Initialize and Load take a cursor from the input class
            ESRI.ArcGIS.Geodatabase.ICursor cursor = inputClass.Search(null, false) as
                                                     ESRI.ArcGIS.Geodatabase.ICursor;
            ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2 naClassLoader = new
                                                                       ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass();
            naClassLoader.Initialize(naContext, naClassName, cursor);

            // Store the current set of locator agents, so they can be added back later
            int agentCount   = naContext.Locator.LocatorAgentCount;
            var listOfAgents = new System.Collections.Generic.List <
                ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent>();

            for (int locIndex = 0; locIndex < agentCount; locIndex++)
            {
                listOfAgents.Add(naContext.Locator.get_LocatorAgent(locIndex));
            }

            // Remove the existing locator agents from the locator
            // This for loop is done in reverse order, because agents are being removed as the loop executes
            for (int locIndex = agentCount - 1; locIndex >= 0; locIndex--)
            {
                naContext.Locator.RemoveLocatorAgent(locIndex);
            }

            // Create and add a fields agent
            var fieldsAgent = new
                              ESRI.ArcGIS.NetworkAnalyst.NALocatorLocationFieldsAgentClass() as
                              ESRI.ArcGIS.NetworkAnalyst.INALocatorLocationFieldsAgent2;

            // Set the field names appropriately based on input data and NAClass
            var naClass = naContext.NAClasses.get_ItemByName(naClassName) as
                          ESRI.ArcGIS.NetworkAnalyst.INAClass;
            var naFeatureClass = naClass as ESRI.ArcGIS.Geodatabase.IFeatureClass;

            // Check to see if the NAClass is of type NALocation or NALocationRanges
            ESRI.ArcGIS.esriSystem.UID naLocationFeatureUID = new
                                                              ESRI.ArcGIS.esriSystem.UIDClass();
            naLocationFeatureUID.Value = "esriNetworkAnalyst.NALocationFeature";
            ESRI.ArcGIS.esriSystem.UID naLocationFeatureRangesUID = new
                                                                    ESRI.ArcGIS.esriSystem.UIDClass();
            naLocationFeatureRangesUID.Value = "esriNetworkAnalyst.NALocationRangesFeature";
            if (naFeatureClass.CLSID.Compare(naLocationFeatureUID))
            {
                // The field names listed below are the names used in ArcGIS Network Analyst extension classes to represent NALocations.
                //  These are also the names of fields added by the CalculateLocations geoprocessing tool
                fieldsAgent.OIDFieldName      = "SourceOID";
                fieldsAgent.SourceIDFieldName = "SourceID";
                fieldsAgent.PositionFieldName = "PosAlong";
                fieldsAgent.SideFieldName     = "SideOfEdge";
            }
            else if (naFeatureClass.CLSID.Compare(naLocationFeatureRangesUID))
            {
                // The location ranges input field must be of type BLOB
                fieldsAgent.LocationRangesFieldName = "Locations";
                var blobField = inputClass.Fields.get_Field(inputClass.FindField
                                                                (fieldsAgent.LocationRangesFieldName));
                if (blobField.Type !=
                    ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob)
                {
                    System.Windows.Forms.MessageBox.Show(
                        "Loading location ranges by field requires a blob field");
                    return;
                }
            }
            naContext.Locator.AddLocatorAgent(fieldsAgent as
                                              ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent);

            // After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
            //  that every row from the input feature class has been loaded into the network analysis class
            int rowsIn      = 0;
            int rowsLocated = 0;

            naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

            // Now remove the custom fields agent and add back the stored agents
            naContext.Locator.RemoveLocatorAgent(0);
            foreach (var agent in listOfAgents)
            {
                naContext.Locator.AddLocatorAgent(agent);
            }
        }
        protected void SelectArrowToolOnToolbar()
        {
            ESRI.ArcGIS.Framework.ICommandBars commandBars = ArcMap.Application.Document.CommandBars;
            ESRI.ArcGIS.esriSystem.UID commandID = new ESRI.ArcGIS.esriSystem.UIDClass();
            commandID.Value = "esriArcMapUI.SelectTool"; // example: "esriArcMapUI.ZoomInTool";
            ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(commandID, false, false);

            if (commandItem != null)
                ArcMap.Application.CurrentTool = commandItem;
        }
Exemplo n.º 38
0
        public static void AddScalebar(AxPageLayoutControl axpagelayoutcontrol, ESRI.ArcGIS.Carto.IMap map)
        {
            IPageLayout pageLayout;
            pageLayout = axpagelayoutcontrol.PageLayout;

            if (pageLayout == null || map == null)
            {
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(8, 3, 15, 3.8); // Specify the location and size of the scalebar
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.AlternatingScaleBar";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));
            ITextSymbol scalbarsm = markerScaleBar.LabelSymbol;
            markerScaleBar.Units = esriUnits.esriKilometers;
            markerScaleBar.Name = "比例尺";
            markerScaleBar.Map = axpagelayoutcontrol.ActiveView.FocusMap;

            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriTop;
            //markerScaleBar.UseMapSettings();
        }
        /// <summary>
        /// Method to set the map tool as the active tool for the map
        /// </summary>
        /// <param name="application"></param>
        /// <param name="toolName"></param>
        public void SetToolActiveInToolBar(ESRI.ArcGIS.Framework.IApplication application, System.String toolName)
        {
            ESRI.ArcGIS.Framework.ICommandBars commandBars = application.Document.CommandBars;
            ESRI.ArcGIS.esriSystem.UID commandID = new ESRI.ArcGIS.esriSystem.UIDClass();
            commandID.Value = toolName;
            ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(commandID, false, false);

            if (commandItem != null)
                application.CurrentTool = commandItem;
        }
Exemplo n.º 40
0
        public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType)
        {
            if (featureClassName == "") return null; // name was not passed in
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists
            {

                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return featureClass;
            }

            // assign the class id value if not assigned

            if (CLSID == null)
            {
                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

            // if a fields collection is not passed in then supply our own

            if (fields == null)
            {

                // create the fields using the required fields method

                fields = objectClassDescription.RequiredFields;

                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
                ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();

                // create a user defined text field
                ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast

                // setup field properties
                fieldEdit.Name_2 = "SampleField";
                fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2 = true;
                fieldEdit.AliasName_2 = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                fieldEdit.Editable_2 = true;
                fieldEdit.Length_2 = 100;

                // add field to field collection
                fieldsEdit.AddField(field);
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                    ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class

            if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            return featureClass;
        }
Exemplo n.º 41
0
        private IGxDocumentationView setActiveView_GxDocumentationView()
        {
            try
            {
                IGxApplication gxApp = ArcCatalog.Application as IGxApplication;
                IGxCatalog gxCat = gxApp.Catalog;
                IGxViewContainer pGxViewContainer = (IGxViewContainer)ArcCatalog.ThisApplication;
                UID windowID = new ESRI.ArcGIS.esriSystem.UIDClass();
                windowID.Value = "esriCatalogUI.GxDocumentationView";

                IGxView docView = pGxViewContainer.FindView(windowID);
                if (docView.Applies(gxApp.SelectedObject)) gxApp.ViewClassID = windowID;
                UID tbID = docView.DefaultToolbarCLSID;
                if (tbID != null) showCommandBar(tbID);
                return (IGxDocumentationView)docView;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to set active view as metadata" + Environment.NewLine + ex.Message);
                return null;
            }
        }
Exemplo n.º 42
0
        public bool UpdateStringAttribute(string sClassName,string sWhere, string sUpdates)
        {
            IApplication pApp;

            IObjectClass pOC;
            ITable pTable;
            IRow pRow;
            ICursor pCursor;
            IFeatureWorkspace pFWKS;
            IQueryFilter pQF;
            UID eUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            IWorkspaceEdit pWKSEdit;
            string[] sUpdateArray;
            bool bAborted;
            try
            {
                sUpdateArray = GetParameters(sUpdates);
                if (sUpdateArray.Count() % 1 != 0)
                {
                }
                else
                {
                    try
                    {
                        Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
                        System.Object obj = Activator.CreateInstance(t);
                        pApp = obj as IApplication;

                        SW1.Reset();
                        SW1.Start();
                        pFWKS = (IFeatureWorkspace)Workspace;
                        pWKSEdit = (IWorkspaceEdit)Workspace;
                        pOC = (IObjectClass)pFWKS.OpenTable(sClassName);
                        try
                        {
                            pQF = new QueryFilter();
                            pQF.WhereClause = sWhere;
                            pTable = (ITable)pOC;
                            try
                            {
                                pCursor = pTable.Search(pQF, false);
                                Logger.WriteLine("Got Cursor");
                                pRow = pCursor.NextRow();
                                Logger.WriteLine("Got Row");
                                //pWKSEdit.StartEditOperation();
                                bAborted = false;
                                pEditor.StartOperation();
                                Logger.WriteLine("Started Editor");
                                int iPos;
                                while (pRow != null)
                                {
                                    iPos = 0;
                                    for (int i = 0; i < ((sUpdateArray.Count()+1)/2); i++)
                                    {
                                        int iFld = pRow.Fields.FindField(sUpdateArray[iPos]);
                                        if (iFld > 0)
                                        {
                                            Logger.WriteLine("Field:" + iFld);
                                            try
                                            {
                                                pRow.set_Value(iFld, sUpdateArray[iPos + 1]);
                                            }
                                            catch (Exception EX2)
                                            {
                                                Logger.WriteLine("Error in Update Attribute:" + EX2.Message);
                                                bAborted = true;
                                            }
                                        }
                                        else
                                        {
                                            Logger.WriteLine("Field not found:" + sUpdateArray[i]);
                                        }
                                        iPos = iPos + 2;
                                    }
                                    if (!bAborted)
                                    {
                                        pRow.Store();
                                    }
                                    pRow = pCursor.NextRow();
                                }
                                //pWKSEdit.StopEditOperation();
                                pEditor.StopOperation("Update Attribute");
                                SW1.Stop();
                                RecordActionTime("UPDATE_ATTRIBUTE", SW1.ElapsedMilliseconds);
                                return true;
                            }
                            catch (Exception EX)
                            {
                                this.Logger.WriteLine("UpdateStringAttribute error:" + EX.Message + " " + EX.StackTrace);
                                return false;
                            }
                        }
                        catch (Exception EX)
                        {
                            this.Logger.WriteLine("UpdateStringAttribute error:" + EX.Message + " " + EX.StackTrace);
                            return false;
                        }
                    }
                    catch (Exception EX)
                    {
                        this.Logger.WriteLine("UpdateStringAttribute error:" + EX.Message + " " + EX.StackTrace);
                        return false;
                    }
                }
                return true;
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("UpdateStringAttribute error:" + EX.Message + " " + EX.StackTrace);
                return false;
            }
        }
Exemplo n.º 43
0
        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        /// 
        ///<remarks></remarks>
        public static void Addlegend(AxPageLayoutControl axpageLayoutControl, ESRI.ArcGIS.Carto.IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            IPageLayout pageLayout;
            pageLayout = axpageLayoutControl.PageLayout;
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
Exemplo n.º 44
0
        public IFeatureClass createFeatureClassInMemory(string strName, IFields FeatureFields, IWorkspace pWS, esriFeatureType featType)
        {
            ESRI.ArcGIS.esriSystem.UID CLSID = null;
              //ESRI.ArcGIS.esriSystem.UID CLSEXT = null;
              IFeatureWorkspace pFWS = null;

              ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = null;
              ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
              ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
              try
              {
            //CLSEXT = null;

            pFWS = (IFeatureWorkspace)pWS;

            if (CLSID == null)
            {
              CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
              CLSID.Value = "esriGeoDatabase.Feature";
            }

            fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            enumFieldError = null;
            validatedFields = null;
            fieldChecker.ValidateWorkspace = pWS;
            fieldChecker.Validate(FeatureFields, out enumFieldError, out validatedFields);
            bool FCCreated = false;
            IFeatureClass newFeat = null;
            int loopCnt = 0;
            while (FCCreated == false)
            {
              try
              {
            if (loopCnt == 0)
            {
              loopCnt = loopCnt + 1;
              newFeat = pFWS.CreateFeatureClass(strName, validatedFields, null, null, featType, "SHAPE", "");
            }
            else
            {
              loopCnt = loopCnt + 1;
              newFeat = pFWS.CreateFeatureClass(strName + (loopCnt - 1).ToString(), validatedFields, null, null, featType, "SHAPE", "");
            }
            FCCreated = true;
              }
              catch
              {
            FCCreated = false;
              }
              if (loopCnt == 100)
            FCCreated = true;

            }
            return newFeat;

              }
              catch
              {
            return null;

              }
              finally
              {
            CLSID = null;

            pFWS = null;

            fieldChecker = null;
            enumFieldError = null;
            validatedFields = null;
              }
        }
        /// <summary>
        /// Finds the first layer on the focus map whose source feature class 
        /// has the given name AND where the workspace matches that of the 
        /// currently selected telecom workspace.
        /// </summary>
        /// <param name="ftClassName">Name to look for</param>
        /// <returns>IFeatureLayer</returns>
        public ESRI.ArcGIS.Carto.IFeatureLayer FindFeatureLayer(string ftClassName)
        {
            ESRI.ArcGIS.Carto.IFeatureLayer result = null;

            if (1 > ftClassName.Length)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "FindFeatureLayer: ", "ftClassName not specified");
                throw new ArgumentException("ftClassName not specified");
            }

            // Check the cache first for the layer
            if (_featureLayerCache.ContainsKey(ftClassName))
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Found Feature Layer in cache", ftClassName);
                return _featureLayerCache[ftClassName];
            }

            ESRI.ArcGIS.esriSystem.UID geoFeatureLayerID = new ESRI.ArcGIS.esriSystem.UIDClass();
            geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";

            ESRI.ArcGIS.Carto.IEnumLayer enumLayer = this.FocusMap.get_Layers(geoFeatureLayerID, true);

            // Step through each geofeature layer in the map
            enumLayer.Reset();
            ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;

            string testName = ftClassName.ToLower(); // No reason to do this every time in the loop
            int testDotPosition = testName.LastIndexOf('.');
            testName = testName.Substring(testDotPosition + 1);

            while (ftLayer != null)
            {
                if (ftLayer.Valid)
                {
                    ESRI.ArcGIS.Geodatabase.IDataset dataset = ftLayer.FeatureClass as ESRI.ArcGIS.Geodatabase.IDataset;
                    if (null != dataset && dataset.Workspace == _wkspHelper.CurrentWorkspace)
                    {
                        string tableName = GdbUtils.ParseTableName(dataset);
                        if (tableName.ToLower() == testName)
                        {
                            result = ftLayer;
                            _featureLayerCache.Add(ftClassName, result);
                            break;
                        }
                    }
                }

                ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;
            }

            return result;
        }
Exemplo n.º 46
0
        public static void AddNorthArrow(AxPageLayoutControl axpagelayoutcontrol, ESRI.ArcGIS.Carto.IMap map)
        {
            IPageLayout pageLayout;
               pageLayout = axpagelayoutcontrol.PageLayout;

            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(16, 24, 21, 29); //  Specify the location and size of the north arrow

            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.MarkerNorthArrow";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            ESRI.ArcGIS.Carto.IMarkerNorthArrow markerNorthArrow = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow; // Dynamic Cast
            ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;
            ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
            characterMarkerSymbol.CharacterIndex = 202; // change the symbol for the North Arrow
            markerNorthArrow.MarkerSymbol = characterMarkerSymbol;
        }
Exemplo n.º 47
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Uitvoeren.
        //
        ///<summary>Creates a table with some default fields.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///  
        ///<returns>An ITable interface or Nothing</returns>
        ///  
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            ESRI.ArcGIS.Geodatabase.ITable table;

            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
            {
                // table with that name already exists return that table
                table = featureWorkspace.OpenTable(tableName);
                return table;
            }

            uid.Value = "esriGeoDatabase.Object";

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                fieldsEdit.AddField(this.CreateFieldInt("ID"));
                fieldsEdit.AddField(this.CreateFieldInt("index"));
                fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2));

                // add field to field collection
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // create and return the table
            table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");

            return table;
        }
Exemplo n.º 48
0
        public void insert(Transaction current, SEE see, ISpatialReference utmSR)
        {
            // Create table on datastore PGDB first?
            current.TxId = see.RestID;
            IPolygon sourcePolygon = see.Shape;
            //sourcePolygon.Project(utmSR);

            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
            fieldsEdit.FieldCount_2 = 3;
            //Create the Object ID field.
            IField fieldUserDefined = new Field();
            IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2 = "OBJECTID";
            fieldEdit.AliasName_2 = "OBJECT ID";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, fieldUserDefined);
            // Create the Shape field.
            fieldUserDefined = new Field();
            fieldEdit = (IFieldEdit)fieldUserDefined;
            // Set up the geometry definition for the Shape field.
            IGeometryDef geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
            // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size
            // will be based on the initial loading or inserting of features.
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;
            //Assign the spatial reference that was passed in, possibly from
            //IGeodatabase.SpatialReference for the containing feature dataset.
            if (see.Shape.SpatialReference != null)
            {
                geometryDefEdit.SpatialReference_2 = see.Shape.SpatialReference;
            }
            //if (utmSR == null)
            //{
            //    ISpatialReferenceFactory2 sre = (ISpatialReferenceFactory2)new SpatialReferenceEnvironment();
            //    utmSR = sre.CreateSpatialReference((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_10N);
            //}

            //geometryDefEdit.SpatialReference_2 = utmSR;// see.Shape.SpatialReference;
            // Set standard field properties.
            fieldEdit.Name_2 = "SHAPE";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Required_2 = true;
            fieldsEdit.set_Field(1, fieldUserDefined);
            // Create a field of type double to hold some information for the features.
            fieldUserDefined = new Field();
            fieldEdit = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2 = "SPATIAL_EDIT_EXTENT_SP_ID";
            fieldEdit.AliasName_2 = "SPATIAL_EDIT_EXTENT_SP_ID";
            fieldEdit.Editable_2 = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Length_2 = 125;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(2, fieldUserDefined);
            // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
            ESRI.ArcGIS.esriSystem.UID CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            IFeatureClass fc = osdb.CreateFeatureClass(OSDB_SEE_NAME, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");

            //IGeoDatasetSchemaEdit fd_ed = (IGeoDatasetSchemaEdit)fc;
            //ISpatialReference oldSR = ((IGeoDataset)fc).SpatialReference;
            //if (fd_ed.CanAlterSpatialReference && !oldSR.Equals(utmSR))
            //{
            //    // does not reproject the data
            //    // doees alter all child feature classes
            //    fd_ed.AlterSpatialReference(utmSR);
            //}

            IWorkspaceEdit wse = (IWorkspaceEdit)osdb;
            wse.StartEditing(false);
            wse.StartEditOperation();

            try
            {
                fc = osdb.OpenFeatureClass(OSDB_SEE_NAME);
            }
            catch(Exception e)
            {
                MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }

            IFeatureCursor fcrs = null;

            try
            {
                fcrs = fc.Insert(false);
                IFeatureBuffer buffer = fc.CreateFeatureBuffer();

                buffer.set_Value(fcrs.FindField(SEE_ID_COL), RestTransactionManager.Instance.NewTransactionSeeID);
                //buffer.set_Value(fcrs.FindField(OSDB_NAME_COL),current.OperationalDatasetName);

                //string t = current.Description;
                //if (t != null && t.Length > EDIT_INTENT_COL_LNG)
                //{
                //    t = t.Substring(0, EDIT_INTENT_COL_LNG);
                //}
                //buffer.set_Value(fcrs.FindField(EDIT_INTENT_COL), t);

                //buffer.set_Value(fcrs.FindField(OPEN_DATE_COL),current.CreationDate);
                //t = current.PGDB.FullName;
                //buffer.set_Value(fcrs.FindField(PGDB_PATH_COL), t);

                IPolygon p = sourcePolygon;
                if(p!=null)
                {
                    //p.Project(utmSR);
                    p.Project(((IGeoDataset)fc).SpatialReference);
                }
                buffer.Shape = p;

                fcrs.InsertFeature(buffer);

                fcrs.Flush();

                // Explicitly release the cursor.
                Marshal.ReleaseComObject(fcrs);

                // Stop editing.
                wse.StopEditOperation();
                wse.StopEditing(true);
            }
            catch(Exception e)
            {
                // Failed while writing the SEE area poygon to the PGDB?
                // We should carry on with the transaction, but the SEE area will be lost

                MessageBox.Show("Error occured storing SEE geometry. " + e.Message);
            }
            finally
            {
                if(fcrs != null)
                {
                    Utils.Release(fcrs);
                }
            }
        }
Exemplo n.º 49
0
 internal static ESRI.ArcGIS.esriSystem.UID ToUID(this System.String id)
 {
     ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
     uid.Value = id;
     return(uid);
 }
Exemplo n.º 50
0
        public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType)
        {
            if (featureClassName == "")
            {
                return(null);                        // name was not passed in
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass     featureClass;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName))        //feature class with that name already exists
            {
                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return(featureClass);
            }


            // assign the class id value if not assigned

            if (CLSID == null)
            {
                CLSID       = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();


            // if a fields collection is not passed in then supply our own

            if (fields == null)
            {
                // create the fields using the required fields method

                fields = objectClassDescription.RequiredFields;

                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
                ESRI.ArcGIS.Geodatabase.IField      field      = new ESRI.ArcGIS.Geodatabase.FieldClass();

                // create a user defined text field
                ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast

                // setup field properties
                fieldEdit.Name_2         = "SampleField";
                fieldEdit.Type_2         = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2   = true;
                fieldEdit.AliasName_2    = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                fieldEdit.Editable_2     = true;
                fieldEdit.Length_2       = 100;

                // add field to field collection
                fieldsEdit.AddField(field);
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                    ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class

            if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            return(featureClass);
        }