Beispiel #1
0
        private void RepairWithLayerFile(int mapIndex, IDataLayer2 dataLayer, string newLayerFile, bool keepBrokenLayer, AlertForm alert)
        {
            // Add Layer File to ActiveView Snippet: (http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000050000000)
            IGxLayer gxLayer = new GxLayer();
            IGxFile  gxFile  = (IGxFile)gxLayer;

            gxFile.Path = newLayerFile;
            if (gxLayer.Layer != null)
            {
                // AddLayer will add the new layer at the most appropriate point in the TOC.
                //   This is much easier and potentially less confusing than adding at the old data location.
                ArcMap.Document.Maps.Item[mapIndex].AddLayer(gxLayer.Layer);
                if (!keepBrokenLayer)
                {
                    ArcMap.Document.Maps.Item[mapIndex].DeleteLayer((ILayer)dataLayer);
                }
            }
            else
            {
                // Notify the user that the LayerFile could not be opened (missing, corrupt, ...)
                alert.Text        = @"Error";
                alert.msgBox.Text = $"The layer file '{newLayerFile}' could not be opened.";
                alert.ShowDialog(new WindowWrapper(new IntPtr(ArcMap.Application.hWnd)));
            }
        }
Beispiel #2
0
        public bool CanDisplayObject(IGxObject @object)
        {
            bool canDisplay = false;

            if (@object == null)
            {
                return(canDisplay);
            }

            IGxFile gxFile = @object as IGxFile;

            if (gxFile != null)
            {
                if (gxFile.Path.EndsWith(".xml"))
                {
                    canDisplay = true;
                }
            }

            IGxFolder gxFolder = @object as IGxFolder;

            if (gxFolder != null)
            {
                canDisplay = true;
            }

            return(canDisplay);
        }
Beispiel #3
0
        private void btnFeatureDomains_Click(object sender, EventArgs e)
        {
            try
            {
                bool isDomain = false;

                if (sender.Equals(btnFeatureDomains))
                {
                    isDomain = true;
                }

                IGxDialog xmlFileSelectDialog = new GxDialogClass();
                xmlFileSelectDialog.AllowMultiSelect = false;
                if (isDomain)
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_domain");
                }
                else
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_feature");
                }
                xmlFileSelectDialog.RememberLocation = true;
                xmlFileSelectDialog.ButtonCaption    = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_buttoncaption");

                xmlFileSelectDialog.ObjectFilter = new GxFilterXmlFiles();

                IEnumGxObject selectedConfigurationFile = null;

                if (xmlFileSelectDialog.DoModalOpen(m_editor.Parent.hWnd, out selectedConfigurationFile))
                {
                    if (selectedConfigurationFile == null)
                    {
                        return;
                    }

                    selectedConfigurationFile.Reset();

                    IGxFile xmlFile = selectedConfigurationFile.Next() as IGxFile;

                    if (xmlFile == null)
                    {
                        return;
                    }

                    if (isDomain)
                    {
                        txtOSMDomainFileLocation.Text = xmlFile.Path;
                    }
                    else
                    {
                        txtOSMFeaturePropertiesFileLocation.Text = xmlFile.Path;
                    }

                    SetPageDirty(true);
                }
            }
            catch
            {
            }
        }
Beispiel #4
0
        private static void ApplySymbology(ILayer layer, FileInfo symbology)
        {
            if (symbology == null || !symbology.Exists)
            {
                return;
            }

            IGxLayer pGXLayer = new GxLayer();
            IGxFile  pGXFile  = (IGxFile)pGXLayer;

            pGXFile.Path = symbology.FullName;


            if (layer is IRasterLayer)
            {
                if (pGXLayer.Layer is IRasterLayer)
                {
                    IRasterLayer prlayer = (IRasterLayer)pGXLayer.Layer;
                    ((IRasterLayer)layer).Renderer = prlayer.Renderer;
                }
                else
                {
                    throw new Exception(string.Format("Cannot apply symbology file to raster layer {0}. file: {1}", layer.Name, symbology.FullName));
                }
            }
            else if (layer is IGeoFeatureLayer)
            {
                if (pGXLayer.Layer is IGeoFeatureLayer)
                {
                    IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pGXLayer.Layer;
                    ((IGeoFeatureLayer)layer).Renderer = pGFLayer.Renderer;

                    // Copy labels
                    if (pGFLayer.DisplayAnnotation)
                    {
                        try
                        {
                            ((IGeoFeatureLayer)layer).DisplayAnnotation    = true;
                            ((IGeoFeatureLayer)layer).AnnotationProperties = pGFLayer.AnnotationProperties;
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.Print(ex.Message);
                            System.Diagnostics.Debug.Assert(false, "Error applying labels from layer file.");
                        }
                    }

                    // Make sure the correct layer properties dialog appears
                    IRendererPropertyPage pRendererPropPage = GetVectorPropertyPage(pGFLayer.Renderer);
                    if (pRendererPropPage != null)
                    {
                        ((IGeoFeatureLayer)layer).RendererPropertyPageClassID = pRendererPropPage.ClassID;
                    }
                }
            }
        }
Beispiel #5
0
        private static void ApplySymbology(ILayer layer, FileInfo symbology)
        {
            if (symbology == null || !symbology.Exists)
            {
                return;
            }

            IGxLayer pGXLayer = new GxLayer();
            IGxFile  pGXFile  = (IGxFile)pGXLayer;

            pGXFile.Path = symbology.FullName;


            if (layer is IRasterLayer)
            {
                if (pGXLayer.Layer is IRasterLayer)
                {
                    IRasterLayer prlayer = (IRasterLayer)pGXLayer.Layer;
                    ((IRasterLayer)layer).Renderer = prlayer.Renderer;
                }
                else
                {
                    throw new Exception(string.Format("Cannot apply symbology file to raster layer {0}. file: {1}", layer.Name, symbology.FullName));
                }
            }
            else if (layer is IGeoFeatureLayer)
            {
                if (pGXLayer.Layer is IGeoFeatureLayer)
                {
                    IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pGXLayer.Layer;
                    ((IGeoFeatureLayer)layer).Renderer = pGFLayer.Renderer;

                    IRendererPropertyPage pRendererPropPage = GetVectorPropertyPage(pGFLayer.Renderer);
                    if (pRendererPropPage != null)
                    {
                        ((IGeoFeatureLayer)layer).RendererPropertyPageClassID = pRendererPropPage.ClassID;
                    }
                }
            }
        }
Beispiel #6
0
        public bool CanChooseObject(IGxObject @object, ref esriDoubleClickResult result)
        {
            bool canChoose = false;

            if (@object == null)
            {
                return(canChoose);
            }

            IGxFile gxFile = @object as IGxFile;

            if (gxFile == null)
            {
                return(false);
            }

            if (gxFile.Path.EndsWith(".xml"))
            {
                canChoose = true;
            }

            return(canChoose);
        }
        private void AddQALayerToActiveView(IMap map, IFeatureClass SourceLineFeatureClass, IFeatureClass SourcePolygonFeatureClass,
                                            string layerPathFile, double metersPerUnit, bool bIsBefore1022, bool bFabricIsInGCS)
        {
            if (map == null || layerPathFile == null || !layerPathFile.EndsWith(".lyr"))
            {
                return;
            }

            // Create a new GxLayer
            IGxLayer gxLayer = new GxLayerClass();
            IGxFile  gxFile  = (IGxFile)gxLayer;

            // Set the path for where the layerfile is located on disk
            gxFile.Path = layerPathFile;

            // Test if we have a valid layer and add it to the map
            if (!(gxLayer.Layer == null))
            {
                if (!(gxLayer.Layer is ICompositeLayer))
                {
                    return;
                }
                ICompositeLayer pCompLyr = (ICompositeLayer)gxLayer.Layer;
                for (int i = 0; i < pCompLyr.Count; i++)
                {
                    ILayer pLyr = pCompLyr.get_Layer(i);
                    //
                    if (pLyr is IFeatureLayer)
                    {
                        IFeatureLayer pFlyr = (IFeatureLayer)pLyr;
                        //now update the definition query
                        IFeatureLayerDefinition pFeatLyrDef = (IFeatureLayerDefinition)pFlyr;
                        string sLyrName = pFlyr.Name;
                        bool   bExc     = false;
                        if (sLyrName.Contains("Minus"))
                        {
                            pFlyr.FeatureClass = SourceLineFeatureClass;
                            bExc = false;

                            //ILayerFields pLayerFields = pFlyr as ILayerFields;
                            //First turn off all layers
                            //for (int kk = 0; kk < pLayerFields.FieldCount; kk++)
                            //{
                            //  IFieldInfo pFieldInfo = pLayerFields.get_FieldInfo(kk);
                            //  pFieldInfo.Visible = false;
                            //}

                            SetLabelExpressionOnFeatureLayer(pFlyr, out bExc);
                            if (bExc || bFabricIsInGCS)
                            {
                                int jj = pFlyr.FeatureClass.FindField("ComputedMinusObserved");
                                if (jj > -1)
                                {
                                    string sVal     = (0.1 / metersPerUnit).ToString("0.00");
                                    string sCminusO = pFlyr.FeatureClass.Fields.get_Field(jj).Name;
                                    pFeatLyrDef.DefinitionExpression = sCminusO + " > " + sVal + " AND " + sCminusO + " < " + sVal;

                                    //IFieldInfo pFieldInfo = pLayerFields.get_Field(jj) as IFieldInfo;
                                    //pFieldInfo.Visible = true;
                                }
                                continue;
                            }
                            string s      = pFeatLyrDef.DefinitionExpression;
                            int    iField = SourceLineFeatureClass.FindField("ArcLength");
                            if (iField > -1)
                            {
                                //IFieldInfo pFieldInfo = pLayerFields.get_Field(iField) as IFieldInfo;
                                //pFieldInfo.Visible = true;

                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"ArcLength\"", s2);
                                pFeatLyrDef.DefinitionExpression = s.Replace("ArcLength", s2);
                            }

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourceLineFeatureClass.FindField("Distance");
                            if (iField > -1)
                            {
                                //IFieldInfo pFieldInfo = pLayerFields.get_Field(iField) as IFieldInfo;
                                //pFieldInfo.Visible = true;

                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"Distance\"", s2);
                                pFeatLyrDef.DefinitionExpression = s.Replace("Distance", s2);
                            }

                            s = pFeatLyrDef.DefinitionExpression;
                            pFeatLyrDef.DefinitionExpression = s.Replace("Shape_Length", SourceLineFeatureClass.LengthField.Name);
                        }
                        else if (sLyrName.Contains("Parcel"))
                        { //In 10.1 start editing crashes if the definition query in these layers that use POWER function is present.
                          //Can test if the release is 10.1 and knock out the def query, or else exclude the layers.

                            string s      = pFeatLyrDef.DefinitionExpression;
                            int    iField = SourcePolygonFeatureClass.FindField("MiscloseDistance");
                            string s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"MiscloseDistance\"", s2);
                            pFeatLyrDef.DefinitionExpression = s.Replace("MiscloseDistance", s2);

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorE");
                            s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorE\"", s2);
                            pFeatLyrDef.DefinitionExpression = s.Replace("ShapeStdErrorE", s2);

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorN");
                            s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorN\"", s2);
                            pFeatLyrDef.DefinitionExpression = s.Replace("ShapeStdErrorN", s2);

                            pFlyr.FeatureClass = SourcePolygonFeatureClass;
                            SetLabelExpressionOnFeatureLayer(pFlyr, out bExc);

                            if (s.ToLower().Contains("power") && bIsBefore1022)
                            {//remove the def query CR278039
                                pFeatLyrDef.DefinitionExpression = "";
                                continue;
                            }
                        }
                    }
                }
                gxLayer.Layer.Name = "QA Symbology";

                IMxDocument         pMXDoc    = ArcMap.Document;
                IOperationStack     pOpSt     = pMXDoc.OperationStack;
                IAddLayersOperation pAddLyrOp = new AddLayersOperationClass();
                pAddLyrOp.SetDestinationInfo(0, map, null);
                pAddLyrOp.Name = "Add Fabric QA Layer";
                pAddLyrOp.AddLayer(gxLayer.Layer);
                IOperation pOp = (IOperation)pAddLyrOp;
                pOpSt.Do(pOp);
            }
        }
Beispiel #8
0
        private void AddQALayerToActiveView(IMap map, IFeatureClass SourceLineFeatureClass, IFeatureClass SourcePolygonFeatureClass,
                                            string layerPathFile, double metersPerUnit, bool bIsBefore1022, bool bFabricIsInGCS)
        {
            if (map == null || layerPathFile == null || !layerPathFile.EndsWith(".lyr"))
            {
                return;
            }

            IWorkspace pWS         = SourceLineFeatureClass.FeatureDataset.Workspace;
            bool       bIsPostGres = false;

            if (pWS.Type != esriWorkspaceType.esriLocalDatabaseWorkspace)
            {
                IDatabaseConnectionInfo2 connectionInfo2 = (IDatabaseConnectionInfo2)(pWS);
                bIsPostGres = (connectionInfo2.ConnectionDBMS == esriConnectionDBMS.esriDBMS_PostgreSQL);
            }

            // Create a new GxLayer
            IGxLayer gxLayer = new GxLayerClass();
            IGxFile  gxFile  = (IGxFile)gxLayer;

            // Set the path for where the layerfile is located on disk
            gxFile.Path = layerPathFile;

            // Test if we have a valid layer and add it to the map
            if (!(gxLayer.Layer == null))
            {
                if (!(gxLayer.Layer is ICompositeLayer))
                {
                    return;
                }
                ICompositeLayer pCompLyr = (ICompositeLayer)gxLayer.Layer;
                for (int i = 0; i < pCompLyr.Count; i++)
                {
                    ILayer pLyr = pCompLyr.get_Layer(i);
                    //
                    if (pLyr is IFeatureLayer)
                    {
                        IFeatureLayer pFlyr = (IFeatureLayer)pLyr;
                        //now update the definition query
                        IFeatureLayerDefinition pFeatLyrDef = (IFeatureLayerDefinition)pFlyr;
                        string sLyrName = pFlyr.Name;
                        bool   bExc     = false;
                        if (sLyrName.Contains("Minus"))
                        {
                            pFlyr.FeatureClass = SourceLineFeatureClass;
                            bExc = false;

                            SetLabelExpressionOnFeatureLayer(pFlyr, out bExc);
                            if (bExc || bFabricIsInGCS)
                            {
                                int jj = pFlyr.FeatureClass.FindField("ComputedMinusObserved");
                                if (jj > -1)
                                {
                                    string sVal     = (0.1 / metersPerUnit).ToString("0.00");
                                    string sCminusO = pFlyr.FeatureClass.Fields.get_Field(jj).Name;
                                    pFeatLyrDef.DefinitionExpression = "(" + sCminusO + " > " + sVal + " OR " + sCminusO + " < -" + sVal + ") AND (" + sCminusO + " IS NOT NULL)";

                                    if (bIsPostGres)
                                    {
                                        pFeatLyrDef.DefinitionExpression = "(((st_length(shape) - distance) > " + sVal +
                                                                           " OR (st_length(shape) - distance) < -" + sVal + " OR (distance - st_length(shape)) > " + sVal +
                                                                           " OR  (distance - st_length(shape)) < -" + sVal +
                                                                           ") AND (radius IS NULL AND (densifytype IS NULL OR densifytype <> 3))  AND category <> 4) OR ( ( ((st_length(shape) - arclength) > " + sVal +
                                                                           " OR (st_length(shape) - arclength) < -" + sVal + ")    OR (arclength - st_length(shape)) > " + sVal +
                                                                           " OR  (arclength - st_length(shape)) < -" + sVal + ") AND ( NOT arclength IS NULL ) )"; //this is query for ST_Geometry as well as PG_Geometry
                                    }
                                }
                                continue;
                            }

                            string s      = pFeatLyrDef.DefinitionExpression;
                            int    iField = SourceLineFeatureClass.FindField("ArcLength");
                            if (iField > -1)
                            {
                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"ArcLength\"", s2);
                                pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ArcLength", s2);
                            }

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourceLineFeatureClass.FindField("Category");
                            if (iField > -1)
                            {
                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"Category\"", s2);
                                pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Category", s2);
                            }

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourceLineFeatureClass.FindField("Radius");
                            if (iField > -1)
                            {
                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"Radius\"", s2);
                                pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Radius", s2);
                            }

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourceLineFeatureClass.FindField("Distance");
                            if (iField > -1)
                            {
                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"Distance\"", s2);
                                pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Distance", s2);
                            }

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourceLineFeatureClass.FindField("DensifyType");
                            if (iField > -1)
                            {
                                string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name;
                                pFeatLyrDef.DefinitionExpression = s.Replace("\"DensifyType\"", s2);
                                pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("DensifyType", s2);
                            }


                            s = pFeatLyrDef.DefinitionExpression;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"Shape_Length\"", SourceLineFeatureClass.LengthField.Name);
                            pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Shape_Length", SourceLineFeatureClass.LengthField.Name);
                        }
                        else if (sLyrName.Contains("Parcel"))
                        { //In 10.1 start editing crashes if the definition query in these layers that use POWER function is present.
                          //Can test if the release is 10.1 and knock out the def query, or else exclude the layers.

                            string s      = pFeatLyrDef.DefinitionExpression;
                            int    iField = SourcePolygonFeatureClass.FindField("MiscloseDistance");
                            string s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"MiscloseDistance\"", s2);
                            pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("MiscloseDistance", s2);

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorE");
                            s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorE\"", s2);
                            pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ShapeStdErrorE", s2);

                            s      = pFeatLyrDef.DefinitionExpression;
                            iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorN");
                            s2     = SourcePolygonFeatureClass.Fields.get_Field(iField).Name;
                            pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorN\"", s2);
                            pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ShapeStdErrorN", s2);

                            pFlyr.FeatureClass = SourcePolygonFeatureClass;
                            SetLabelExpressionOnFeatureLayer(pFlyr, out bExc);

                            if (s.ToLower().Contains("power") && bIsBefore1022)
                            {//remove the def query CR278039
                                pFeatLyrDef.DefinitionExpression = "";
                                continue;
                            }
                        }
                    }
                }
                gxLayer.Layer.Name = "QA Symbology";

                IMxDocument         pMXDoc    = ArcMap.Document;
                IOperationStack     pOpSt     = pMXDoc.OperationStack;
                IAddLayersOperation pAddLyrOp = new AddLayersOperationClass();
                pAddLyrOp.SetDestinationInfo(0, map, null);
                pAddLyrOp.Name = "Add Fabric QA Layer";
                pAddLyrOp.AddLayer(gxLayer.Layer);
                IOperation pOp = (IOperation)pAddLyrOp;
                pOpSt.Do(pOp);
            }
        }