Beispiel #1
0
        internal static ESRI.ArcGIS.Carto.ILayer getLayerByName(string name)
        {
            ESRI.ArcGIS.Carto.IMap     map = ArcMap.Document.FocusMap;
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";


            ESRI.ArcGIS.Carto.IEnumLayer enumLayer = map.get_Layers(null, true);
            ESRI.ArcGIS.Carto.ILayer     l         = enumLayer.Next();
            while (l != null)
            {
                if (l.Name.ToUpper() == name.ToUpper())
                {
                    break;
                }

                l = enumLayer.Next();
            }

            return(l);
        }
Beispiel #2
0
        internal void SetMap(string filePath)
        {
            // open the map document
            ESRI.ArcGIS.Carto.IMapDocument mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass();
            mapDocument.Open(filePath, null);
            // get first map (data frame)
            ESRI.ArcGIS.Carto.IMap map = mapDocument.get_Map(0);
            // track whether we need to save properties
            string[] tTmp = new string[m_ExtractionLayerProperties.Keys.Count];
            m_ExtractionLayerProperties.Keys.CopyTo(tTmp, 0);
            // we will remove items from this previously configured list and anything left we know is no longer in map, so remove
            // from saved properties
            List <string> tPreviouslyConfiguredLayers = tTmp.ToList <string>();

            // get raster layers
            ESRI.ArcGIS.esriSystem.UID rasterLayerId = new ESRI.ArcGIS.esriSystem.UIDClass();
            // GUID for a raster layer
            rasterLayerId.Value = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}";
            ESRI.ArcGIS.Carto.IEnumLayer rasterEnumLayer = map.get_Layers(rasterLayerId, true);

            int dirSelectedIndex = 0;
            int accSelectedIndex = 0;

            // set a default value of none
            // if either box is left at none then the SOE will know not to
            // expose the watershed operation
            ComboFlowDir.Items.Add("NONE");
            ComboFlowAcc.Items.Add("NONE");
            ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = null;
            while ((rasterLayer = rasterEnumLayer.Next() as ESRI.ArcGIS.Carto.IRasterLayer) !=
                   null)
            {
                ESRI.ArcGIS.DataSourcesRaster.IRasterProps tRasterProps =
                    rasterLayer.Raster as ESRI.ArcGIS.DataSourcesRaster.IRasterProps;
                ESRI.ArcGIS.Geodatabase.rstPixelType tPixelType = tRasterProps.PixelType;
                // flow dir can only be an integer raster of short or long types
                if (tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_UCHAR ||
                    tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_SHORT ||
                    tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_ULONG ||
                    tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_LONG)
                {
                    ComboFlowDir.Items.Add(rasterLayer.Name);
                    ComboFlowAcc.Items.Add(rasterLayer.Name);
                }
                // flow acc can theoretically be floating point as far as i can see
                // albeit it won't normally be
                else if (tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_FLOAT ||
                         tPixelType == ESRI.ArcGIS.Geodatabase.rstPixelType.PT_DOUBLE)
                {
                    ComboFlowAcc.Items.Add(rasterLayer.Name);
                }
                if (rasterLayer.Name == m_FlowAccLayerName)
                {
                    accSelectedIndex = ComboFlowAcc.Items.Count - 1;
                }
                else if (rasterLayer.Name == m_FlowDirLayerName)
                {
                    dirSelectedIndex = ComboFlowDir.Items.Count - 1;
                }
                string tRasterType = "ContinuousRaster";
                if (tRasterProps.IsInteger)
                {
                    tRasterType = "CategoricalRaster";
                }

                ExtractionLayerProperties tLayerInMap = new ExtractionLayerProperties(rasterLayer.Name, false, rasterLayer.Name.Substring(0, 6),
                                                                                      tRasterType, "NONE", "NONE", "NONE", null, null, null);
                ExtractionLayerProperties tCurrentConfigForLayer;
                bool alreadyconfigured = m_ExtractionLayerProperties.TryGetValue(rasterLayer.Name, out tCurrentConfigForLayer);
                if (alreadyconfigured)
                {
                    tLayerInMap.Enabled   = tCurrentConfigForLayer.Enabled;
                    tLayerInMap.ParamName = tCurrentConfigForLayer.ParamName;
                    // that's all that needs doing for a raster raster
                }
                m_ExtractionLayerProperties[rasterLayer.Name] = tLayerInMap;
                tPreviouslyConfiguredLayers.Remove(rasterLayer.Name);
            }
            int extSelectedIndex = 0;

            ESRI.ArcGIS.esriSystem.UID featlyrId = new ESRI.ArcGIS.esriSystem.UIDClass();
            featlyrId.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            ESRI.ArcGIS.Carto.IEnumLayer    featureEnumLayer = map.get_Layers(featlyrId, true);
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer     = null;
            while ((featureLayer = featureEnumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer) !=
                   null)
            {
                if (featureLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon &&
                    featureLayer.FeatureClass.FeatureType == ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple)
                {
                    ComboExtentFeatures.Items.Add(featureLayer.Name);
                }
                if (featureLayer.Name == m_ExtentFeatureLayerName)
                {
                    extSelectedIndex = ComboExtentFeatures.Items.Count - 1;
                }
                // now stuff for the extraction layer configuration
                List <string> catfields  = new List <string>();
                List <string> valfields  = new List <string>();
                List <string> measfields = new List <string>();
                catfields.Add("NONE");
                valfields.Add("NONE");
                measfields.Add("NONE");
                ESRI.ArcGIS.Geodatabase.IFields tFLFields = featureLayer.FeatureClass.Fields;

                for (int i = 0; i < tFLFields.FieldCount; i++)
                {
                    ESRI.ArcGIS.Geodatabase.IField        tField     = featureLayer.FeatureClass.Fields.get_Field(i);
                    ESRI.ArcGIS.Geodatabase.esriFieldType tFieldType = tField.Type;
                    switch (tFieldType)
                    {
                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble:
                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeSingle:
                        valfields.Add(tField.Name);
                        measfields.Add(tField.Name);
                        break;

                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger:
                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeSmallInteger:
                        valfields.Add(tField.Name);
                        catfields.Add(tField.Name);
                        measfields.Add(tField.Name);
                        break;

                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString:
                    case ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDate:
                        catfields.Add(tField.Name);
                        break;
                    }
                }
                ExtractionLayerProperties tLayerInMap = new ExtractionLayerProperties(featureLayer.Name, false, featureLayer.Name.Substring(0, 6),
                                                                                      "FeatureLayer", "NONE", "NONE", "NONE", catfields, valfields, measfields);
                ExtractionLayerProperties tCurrentConfigForLayer;
                bool alreadyconfigured = m_ExtractionLayerProperties.TryGetValue(featureLayer.Name, out tCurrentConfigForLayer);
                if (alreadyconfigured)
                {
                    // it is already there - loaded from properties - we will make a new object anyway but will copy over the configured
                    // parameter name, enabled, and selected fields.
                    tLayerInMap.Enabled   = tCurrentConfigForLayer.Enabled;
                    tLayerInMap.ParamName = tCurrentConfigForLayer.ParamName;
                    if (tCurrentConfigForLayer.CategoryFieldName != "NONE" &&
                        featureLayer.FeatureClass.FindField(tCurrentConfigForLayer.CategoryFieldName) != -1)
                    {
                        tLayerInMap.CategoryFieldName = tCurrentConfigForLayer.CategoryFieldName;
                    }
                    if (tCurrentConfigForLayer.ValueFieldName != "NONE" &&
                        featureLayer.FeatureClass.FindField(tCurrentConfigForLayer.ValueFieldName) != -1)
                    {
                        tLayerInMap.ValueFieldName = tCurrentConfigForLayer.ValueFieldName;
                    }
                    if (tCurrentConfigForLayer.MeasureFieldName != "NONE" &&
                        featureLayer.FeatureClass.FindField(tCurrentConfigForLayer.ValueFieldName) != -1)
                    {
                        tLayerInMap.MeasureFieldName = tCurrentConfigForLayer.MeasureFieldName;
                    }
                }
                m_ExtractionLayerProperties[featureLayer.Name] = tLayerInMap;
                // now we need to delete from m_ExtractionLayerProperties any configs that haven't been found in the map
                tPreviouslyConfiguredLayers.Remove(featureLayer.Name);
            }
            foreach (string invalidLayerName in tPreviouslyConfiguredLayers)
            {
                m_ExtractionLayerProperties.Remove(invalidLayerName);
            }
            // now, m_extractionlayerproperties is a dictionary of extractionlayerproperties objects
            // where the objects contain the values from the previously saved lot if they were there
            foreach (ExtractionLayerProperties rowdetails in m_ExtractionLayerProperties.Values)
            {
                //  string[] rowParams = new string[]{
                //      rowdetails.LayerName,rowdetails.Enabled.ToString(),rowdetails.ParamName,rowdetails.CategoryFieldName,rowdetails.ValueFieldName
                //     };
                dataGridView1.Rows.Add();
                int             newRowIdx = dataGridView1.Rows.Count - 1;
                DataGridViewRow tRow      = dataGridView1.Rows[newRowIdx];
                tRow.Cells["LayerName"].Value  = rowdetails.LayerName;
                tRow.Cells["LayerAvail"].Value = rowdetails.Enabled.ToString();
                tRow.Cells["LayerParam"].Value = rowdetails.ParamName;
                if (rowdetails.ExtractionType == "FeatureLayer")
                {
                    DataGridViewComboBoxCell cfcell = (DataGridViewComboBoxCell)tRow.Cells["CatField"];

                    foreach (object itemToAdd in rowdetails.PossibleCategoryFields)
                    {
                        cfcell.Items.Add(itemToAdd);
                    }
                    cfcell.Value = rowdetails.CategoryFieldName;
                    DataGridViewComboBoxCell valcell = (DataGridViewComboBoxCell)tRow.Cells["ValField"];
                    foreach (object itemToAdd in rowdetails.PossibleValueFields)
                    {
                        valcell.Items.Add(itemToAdd);
                    }
                    valcell.Value = rowdetails.ValueFieldName;
                    DataGridViewComboBoxCell meascell = (DataGridViewComboBoxCell)tRow.Cells["MeasField"];
                    foreach (object itemToAdd in rowdetails.PossibleMeasureFields)
                    {
                        meascell.Items.Add(itemToAdd);
                    }
                    meascell.Value = rowdetails.MeasureFieldName;
                    tRow.Cells["MeasField"].Value = rowdetails.MeasureFieldName;
                }
                else
                {
                    tRow.Cells["CatField"].Value     = rowdetails.CategoryFieldName;
                    tRow.Cells["ValField"].Value     = rowdetails.ValueFieldName;
                    tRow.Cells["MeasField"].Value    = rowdetails.MeasureFieldName;
                    tRow.Cells["CatField"].ReadOnly  = true;
                    tRow.Cells["ValField"].ReadOnly  = true;
                    tRow.Cells["MeasField"].ReadOnly = true;
                }
                int rowIdx = dataGridView1.Rows.Add(tRow);
            }
            mapDocument.Close();
            mapDocument = null;
            map         = null;
            ComboFlowAcc.SelectedIndex        = accSelectedIndex;
            ComboFlowDir.SelectedIndex        = dirSelectedIndex;
            ComboExtentFeatures.SelectedIndex = extSelectedIndex;
            m_initAcc = true;
            m_initDir = true;
            m_initExt = true;
            m_GridIsInSyncWithProperties = true;
            radioReadMap.Checked         = m_GetLayersFromMap;
            dataGridView1.Enabled        = radioReadMap.Checked;
        }