Esempio n. 1
0
        private static void SetFromMapRendererToRasterLayer(IRasterLayer rasterLayer,
                                                            IObjectFactory objFactory,
                                                            string mapLayerName)
        {
            MapLayersManager layersManager = new MapLayersManager(_map);
            var fromMapRasterLayer         = EsriTools.GetLayer(mapLayerName, _map.FocusMap) as IRasterLayer;

            if (fromMapRasterLayer == null)
            {
                _layersWithDefaultRenderer.Add(rasterLayer.Name);
                return;
            }

            try
            {
                Type   renderType   = typeof(SimpleRendererClass);
                string typeRenderID = renderType.GUID.ToString("B");

                var symbol  = (ISimpleRenderer)objFactory.Create(typeRenderID);
                var objCopy = (IObjectCopy)objFactory.Create("esriSystem.ObjectCopy");

                var copyS = objCopy.Copy(fromMapRasterLayer.Renderer) as IRasterRenderer;
                rasterLayer.Renderer = copyS;
            }
            catch (Exception ex)
            {
                _layersWithDefaultRenderer.Add(rasterLayer.Name);
                logger.WarnEx($"Cannot set rendrer from map for {rasterLayer.Name} layer. Exception: {ex.Message}");
            }
        }
Esempio n. 2
0
        private void PopulateComboBox()
        {
            MapLayersManager mapLayersManager = new MapLayersManager(ArcMapInstance.Document.ActiveView);

            cmbDEMLayer.Items.Clear();
            cmbDEMLayer.Items.AddRange(mapLayersManager.RasterLayers.Select(i => i.Name).ToArray());
        }
Esempio n. 3
0
        private static void SetFromMapRendererToFeatureLayer(IFeatureLayer featureLayer,
                                                             IObjectFactory objFactory,
                                                             string featureClassName)
        {
            MapLayersManager mapLayersManager = new MapLayersManager(_map);
            var layerName = mapLayersManager.GetLayerAliasByFeatureClass(featureClassName);

            if (!String.IsNullOrEmpty(layerName))
            {
                var fromMapGeoFeatureLayer = EsriTools.GetLayer(layerName, _map.FocusMap) as IGeoFeatureLayer;

                if (fromMapGeoFeatureLayer == null)
                {
                    _layersWithDefaultRenderer.Add(featureLayer.Name);
                    return;
                }

                var geoFeatureLayer = featureLayer as IGeoFeatureLayer;

                try
                {
                    Type   renderType   = typeof(SimpleRendererClass);
                    string typeRenderID = renderType.GUID.ToString("B");

                    var objCopy     = (IObjectCopy)objFactory.Create("esriSystem.ObjectCopy");
                    var rendereCopy = objCopy.Copy(fromMapGeoFeatureLayer.Renderer) as IFeatureRenderer;
                    geoFeatureLayer.Renderer = rendereCopy;
                }
                catch (Exception ex)
                {
                    _layersWithDefaultRenderer.Add(featureLayer.Name);
                    logger.WarnEx($"Cannot set rendrer from map for {featureLayer.Name} layer. Exception: {ex.Message}");
                }
            }
        }
        public string[] GetRasterInfo(string rasterName)
        {
            if (String.IsNullOrEmpty(rasterName))
            {
                return(null);
            }

            var mapLayerManager = new MapLayersManager(ArcMap.Document.ActiveView);
            var rasterInfo      = new string[5];
            IRasterFunctionHelper functionHelper = new RasterFunctionHelper();

            var rasterLayer = mapLayerManager.RasterLayers.First(layer => layer.Name.Equals(rasterName));

            var filePath = rasterLayer.FilePath;

            var rasterProps        = rasterLayer.Raster as IRasterProps;
            var defaultRasterProps = rasterLayer.Raster as IRasterDefaultProps;

            var pixelSize         = EsriTools.GetPixelSize(ArcMap.Document.ActiveView);
            var spatialResolution = pixelSize / rasterProps.MeanCellSize().X;

            var heightInPixels = rasterProps.Height;
            var widthInPixels  = rasterProps.Width;

            var heightInKilometres = rasterProps.Extent.Height / EsriTools.GetMetresInMapUnits(1000, ArcMap.Document.FocusMap.SpatialReference);
            var widthInKilometres  = rasterProps.Extent.Width / EsriTools.GetMetresInMapUnits(1000, ArcMap.Document.FocusMap.SpatialReference);

            var area = heightInKilometres * widthInKilometres;

            rasterInfo[0] =
                String.Format(LocalizationContext.Instance
                              .FindLocalizedElement("SolutionSettingsWindow_lbRasterInfoLocationText",
                                                    "розташування: {0}"), filePath);

            rasterInfo[1] =
                String.Format(LocalizationContext.Instance
                              .FindLocalizedElement("SolutionSettingsWindow_lbRasterInfoSpatialResolutionText",
                                                    "просторова роздільна здатність: {0}"), spatialResolution);

            rasterInfo[2] =
                String.Format(LocalizationContext.Instance
                              .FindLocalizedElement("SolutionSettingsWindow_lbRasterInfoAreaText",
                                                    "площа: {0}"), area);

            rasterInfo[3] =
                String.Format(LocalizationContext.Instance
                              .FindLocalizedElement("SolutionSettingsWindow_lbRasterInfoSizeInKilometresText",
                                                    "розмір (км): висота {0}  ширина {1}"), heightInKilometres, widthInKilometres);

            rasterInfo[4] =
                String.Format(LocalizationContext.Instance
                              .FindLocalizedElement("SolutionSettingsWindow_lbRasterInfoSizeInPixelsText",
                                                    "розмір (пікс.): висота {0}  ширина {1}"), heightInPixels, widthInPixels);

            return(rasterInfo);
        }
        public ChooseVectorLayerFromMapModalWindow(IActiveView activeView, bool chooseTitleField = false, string[] layers = null)
        {
            _mapLayersManager = new MapLayersManager(activeView);
            _layers           = layers;

            InitializeComponent();

            chooseTitleFieldPanel.Visible = chooseTitleField;
            chooseTitleFieldPanel.Enabled = chooseTitleField;

            InitializeLayersList();
            LocalizeString();
        }
Esempio n. 6
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            UID toolId = new UIDClass();

            toolId.Value = ThisAddIn.IDs.PickProfileCoordinates;
            var mxdDoc        = ArcMap.Document;
            var screenDisplay = mxdDoc.ActiveView.ScreenDisplay;
            var point         = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
            var pointToSave   = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);

            point.SpatialReference = pointToSave.SpatialReference = mxdDoc.FocusMap.SpatialReference;

            EsriTools.ProjectToWgs84(point);

            var winImpl = AddIn.FromID <DockableWindowMilSpaceProfileCalc.AddinImpl>(ThisAddIn.IDs.DockableWindowMilSpaceProfileCalc);

            var dem = winImpl.MilSpaceProfileCalsController.View.DemLayerName;

            MapLayersManager mngr = new MapLayersManager(mxdDoc.ActiveView);

            //Set Z value using selected DEM
            var rl = mngr.RasterLayers.FirstOrDefault(l => l.Name == dem);

            if (rl != null)
            {
                point.AddZCoordinate(rl.Raster);
                pointToSave.AddZCoordinate(rl.Raster);
            }
            else
            {
                MessageBox.Show(LocalizationContext.Instance.DemLayerNotChosenText, LocalizationContext.Instance.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (winImpl.MilSpaceProfileCalsController.View.ActiveButton == ProfileSettingsPointButtonEnum.PointsFist)
            {
                winImpl.MilSpaceProfileCalsController.SetFirsPointForLineProfile(point, pointToSave);
            }

            if (winImpl.MilSpaceProfileCalsController.View.ActiveButton == ProfileSettingsPointButtonEnum.PointsSecond)
            {
                winImpl.MilSpaceProfileCalsController.SetSecondfPointForLineProfile(point, pointToSave);
            }

            if (winImpl.MilSpaceProfileCalsController.View.ActiveButton == ProfileSettingsPointButtonEnum.CenterFun)
            {
                winImpl.MilSpaceProfileCalsController.SetCenterPointForFunProfile(point, pointToSave);
            }

            var settings = winImpl.MilSpaceProfileCalsController.ProfileSettings[ProfileSettingsTypeEnum.Points];
        }
Esempio n. 7
0
        private Dictionary <ILayer, double> GetAdditionalLayers()
        {
            var selectedLayers = new Dictionary <object, string>();

            if (TransportLayerComboBox.SelectedItem != null)
            {
                selectedLayers.Add(TransportLayerComboBox.SelectedItem, TransportHightTextBox.Text);
            }

            if (BuildingsLayerComboBox.SelectedItem != null)
            {
                selectedLayers.Add(BuildingsLayerComboBox.SelectedItem, BuildingsHight.Text);
            }

            if (PlantsLayerComboBox.SelectedItem != null)
            {
                selectedLayers.Add(PlantsLayerComboBox.SelectedItem, PlantsTextBox.Text);
            }

            if (HydroLayerComboBox.SelectedItem != null)
            {
                selectedLayers.Add(HydroLayerComboBox.SelectedItem, HydroHightTextBox.Text);
            }

            var additionalLayers = new Dictionary <ILayer, double>();

            var mapLayerManager = new MapLayersManager(ArcMap.Document.ActiveView);
            var polygonLayers   = mapLayerManager.PolygonLayers.ToArray();

            foreach (var selectedLayer in selectedLayers)
            {
                double layerHeight;

                if (String.IsNullOrEmpty(selectedLayer.Value) || !Double.TryParse(selectedLayer.Value, out double height))
                {
                    layerHeight = 0;
                }
                else
                {
                    layerHeight = height;
                }

                if (selectedLayer.Key != null)
                {
                    additionalLayers.Add(polygonLayers.First(layer => layer.Name == selectedLayer.Key.ToString()), layerHeight);
                }
            }

            return(additionalLayers);
        }
        private void OnDocumentOpenFillDropdowns()
        {
            this.SurfaceComboBox.Items.Clear();
            this.TransportLayerComboBox.Items.Clear();
            this.HydroLayerComboBox.Items.Clear();
            this.BuildingsLayerComboBox.Items.Clear();
            this.PlantsLayerComboBox.Items.Clear();

            var mapLayerManager = new MapLayersManager(ArcMap.Document.ActiveView);


            PopulateComboBox(SurfaceComboBox, mapLayerManager.RasterLayers);
            PopulateComboBox(TransportLayerComboBox, mapLayerManager.RasterLayers);
            PopulateComboBox(HydroLayerComboBox, mapLayerManager.PolygonLayers);
            PopulateComboBox(BuildingsLayerComboBox, mapLayerManager.PolygonLayers);
            PopulateComboBox(PlantsLayerComboBox, mapLayerManager.PolygonLayers);
        }
Esempio n. 9
0
 internal PointsFromLayerController(IActiveView activeView)
 {
     _mapLayersManager = new MapLayersManager(activeView);
 }
Esempio n. 10
0
 internal GeometriesFromLayerController(IActiveView activeView)
 {
     _mapLayersManager = new MapLayersManager(activeView);
 }
Esempio n. 11
0
        public static List <IObserverPoint> GetObservationPointsFromAppropriateLayer(string layerName,
                                                                                     IActiveView activeView, string titleFieldName = null,
                                                                                     IFeatureClass featureClass = null)
        {
            titleFieldName = titleFieldName ?? "TitleOp";
            var points = new List <IObserverPoint>();

            if (featureClass == null)
            {
                var mapLayersManager = new MapLayersManager(activeView);
                var layer            = mapLayersManager.GetLayer(layerName);

                if (!(layer is IFeatureLayer))
                {
                    return(null);
                }

                var featureLayer = layer as IFeatureLayer;


                featureClass = featureLayer.FeatureClass;
            }

            var fields = featureClass.Fields;

            var oidFieldIndex         = featureClass.FindField(featureClass.OIDFieldName);
            var titleFieldIndex       = (featureClass.FindField(titleFieldName) == -1)? oidFieldIndex : featureClass.FindField(titleFieldName);
            var azimuthBFieldIndex    = featureClass.FindField("AzimuthB");
            var azimuthEFieldIndex    = featureClass.FindField("AzimuthE");
            var anglMinHFieldIndex    = featureClass.FindField("AnglMinH");
            var anglMaxHFieldIndex    = featureClass.FindField("AnglMaxH");
            var innerRadiusFieldIndex = featureClass.FindField("InnerRadius");
            var outerRadiusFieldIndex = featureClass.FindField("OuterRadius");
            var heightIndex           = featureClass.FindField("HRel");


            IQueryFilter queryFilter = new QueryFilter
            {
                WhereClause = $"{featureClass.OIDFieldName} >= 0"
            };

            IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
            IFeature       feature       = featureCursor.NextFeature();

            Func <string, string, string> CreateErrorMessage = (string message, string fieldName) =>
                                                               $"> GetObservationPointsFromAppropriateLayer {message}. Field {fieldName}";

            try
            {
                while (feature != null)
                {
                    var shape = feature.ShapeCopy;

                    var point     = shape as IPoint;
                    var pointCopy = point.Clone();

                    string message;

                    try
                    {
                        if (!Helper.ConvertFromFieldType(
                                fields.Field[oidFieldIndex].Type,
                                feature.Value[oidFieldIndex], out int id, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[oidFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[titleFieldIndex].Type,
                                feature.Value[titleFieldIndex], out string title, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[titleFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[azimuthBFieldIndex].Type,
                                feature.Value[azimuthBFieldIndex], out double azimuthB, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[azimuthBFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[azimuthEFieldIndex].Type,
                                feature.Value[azimuthEFieldIndex], out double azimuthE, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[azimuthEFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[anglMaxHFieldIndex].Type,
                                feature.Value[anglMaxHFieldIndex], out double angleMax, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[anglMaxHFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[anglMinHFieldIndex].Type,
                                feature.Value[anglMinHFieldIndex], out double angleMin, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[anglMinHFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[innerRadiusFieldIndex].Type,
                                feature.Value[innerRadiusFieldIndex], out double innerRadius, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[innerRadiusFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[outerRadiusFieldIndex].Type,
                                feature.Value[outerRadiusFieldIndex], out double outerRadius, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[outerRadiusFieldIndex].AliasName));
                        }

                        if (!Helper.ConvertFromFieldType(
                                fields.Field[heightIndex].Type,
                                feature.Value[heightIndex], out double relativeHeight, out message))
                        {
                            throw new InvalidCastException(CreateErrorMessage(message,
                                                                              fields.Field[heightIndex].AliasName));
                        }

                        points.Add(new ObservationPoint
                        {
                            X              = point.X,
                            Y              = point.Y,
                            Title          = title,
                            Objectid       = id,
                            AzimuthStart   = azimuthB,
                            AzimuthEnd     = azimuthE,
                            AngelMinH      = angleMin,
                            AngelMaxH      = angleMax,
                            InnerRadius    = innerRadius,
                            OuterRadius    = outerRadius,
                            RelativeHeight = relativeHeight
                        });

                        feature = featureCursor.NextFeature();
                    }
                    catch (InvalidCastException ex)
                    {
                        logger.WarnEx(ex.Message);

                        feature = featureCursor.NextFeature();
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorEx($"> GetObservationPointsFromAppropriateLayer Exception. ex.Message:{ex.Message}");
            }
            finally
            {
                Marshal.ReleaseComObject(featureCursor);
            }

            return(points);
        }