コード例 #1
0
        public override bool CalculateIndex(ProgressBar progress)
        {
            if (indexName == "" || strFormula == "")
            {
                return(false);
            }
            try
            {
                progress.Maximum = baseData.zoneValue.Count;
                progress.Value   = 0;
                for (int i = 0; i < baseData.zoneValue.Count; i++)
                {
                    List <string> tempData  = new List <string>();
                    double        tempResut = 0;
                    int[]         oidlist   = baseData.patchIDArray[i];
                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        //获取每个分区的要素集;
                        IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                        IFeatureCursor     featureCursor     = geodatabaseBridge.GetFeatures(baseData.zoneLCA_FC, ref oidlist, true);

                        tempData  = customCal.SearchData(featureCursor);
                        tempResut = calculator.CalculateFormula(tempData);
                        resultList.Add(tempResut);
                    }
                    progress.Value++;
                }
            }
            catch (System.Exception ex)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        ///测试getFeature与getFeatures
        /// </summary>
        /// <param name="featureCls"></param>
        /// <param name="oids"></param>
        /// <param name="fieldIndex"></param>
        public void SearchById(IFeatureClass featureCls, int[] oids, int fieldIndex)
        {
            foreach (var oid in oids)
            {
                var feature = featureCls.GetFeature(oid);
                Console.WriteLine("oid:" + feature.get_Value(fieldIndex));
            }



            using (var comReleaser = new ComReleaser())
            {
                IFeatureCursor featureCursor = featureCls.GetFeatures(oids, true);;
                IFeature       feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    Console.WriteLine("oid:" + feature.get_Value(fieldIndex));
                    feature = featureCursor.NextFeature();
                }
            }

            using (var comReleaser = new ComReleaser())
            {
                IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                IFeatureCursor     featureCursor     = geodatabaseBridge.GetFeatures(featureCls, oids, true);;
                IFeature           feature           = featureCursor.NextFeature();
                while (feature != null)
                {
                    Console.WriteLine("oid:" + feature.get_Value(fieldIndex));
                    feature = featureCursor.NextFeature();
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///     Removes the specified oids from the selection set.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="oids">The oids.</param>
        /// <exception cref="System.ArgumentNullException">oids</exception>
        /// <remarks>
        ///     ESRI states that the RemoveList method on the ISelectionSet should not used from .NET. Instead, call
        ///     IGeoDatabaseBridge2.RemoveList.
        /// </remarks>
        public static void Remove(this ISelectionSet source, params int[] oids)
        {
            if (source == null)
            {
                return;
            }
            if (oids == null)
            {
                throw new ArgumentNullException("oids");
            }

            IGeoDatabaseBridge2 bridge = new GeoDatabaseHelperClass();

            bridge.RemoveList(source, ref oids);
        }
コード例 #4
0
        /// <summary>
        /// 重写计算指标
        /// </summary>
        /// <returns></returns>
        public override bool CalculateIndex(ProgressBar progress)
        {
            try
            {
                //计算每一个分区

                List <string> zones = baseData.zoneValue;
                progress.Maximum = zones.Count * patchClassCac.Count;
                for (int i = 0; i < zones.Count; i++)
                {
                    List <List <double> > temp = new List <List <double> >();
                    string zid     = zones[i];
                    int[]  oidlist = baseData.patchIDArray[i];

                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        for (int j = 0; j < patchClassCac.Count; j++)
                        {
                            IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                            IFeatureCursor     featureCursor     = geodatabaseBridge.GetFeatures(baseData.zoneLCA_FC,
                                                                                                 ref oidlist, true);
                            temp.Add(patchClassCac[j].CaculateClassIndex(featureCursor, baseData));
                            progress.Value++;
                        }
                    }

                    result_list.Add(temp);
                }
            }
            catch (System.Exception ex)
            {
                return(false);
            }



            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                {
                    return;
                }

                IPoint    pointObstruction = null;
                IPolyline polyVisible      = null;
                IPolyline polyInvisible    = null;
                bool      targetIsVisible  = false;

                double finalObserverOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset   = GetOffsetInZUnits(ArcMap.Document.FocusMap, TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary <IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (surface.IsVoidZ(z1))
                    {
                        if (double.IsNaN(z1))
                        {
                            z1 = 0.000001;
                        }
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (surface.IsVoidZ(z2))
                        {
                            if (double.IsNaN(z2))
                            {
                                z2 = 0.000001;
                            }
                        }

                        var fromPoint = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        } as IPoint;
                        var toPoint = new PointClass()
                        {
                            Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true
                        } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                                                 out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass()
                            {
                                Green = 255
                            });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass()
                            {
                                Red = 255
                            });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            var pcol = new PolylineClass() as IPointCollection;
                            pcol.AddPoint(fromPoint);
                            pcol.AddPoint(toPoint);

                            if (targetIsVisible)
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Green = 255
                                });
                            }
                            else
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Red = 255
                                });
                            }
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                    {
                        Blue = 255
                    }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Green = 255
                        });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Red = 255
                        });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong);
            }
            finally
            {
                IsRunning = false;
            }
        }
コード例 #6
0
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;
                IPolyline longestLine = new PolylineClass();

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                //base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                // Determine if selected surface is projected or geographic
                ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                var    geoDataset   = surfaceLayer as IGeoDataset;
                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
                    return;
                }

                if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
                    return;
                }

                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                {
                    return;
                }

                IPoint    pointObstruction = null;
                IPolyline polyVisible      = null;
                IPolyline polyInvisible    = null;
                bool      targetIsVisible  = false;

                double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset   = GetOffsetInZUnits(TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary <IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (double.IsNaN(z1))
                    {
                        System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                        return;
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (double.IsNaN(z2))
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        var fromPoint = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        } as IPoint;
                        var toPoint = new PointClass()
                        {
                            Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true
                        } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                                                 out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        var pcol = new PolylineClass() as IPointCollection;
                        pcol.AddPoint(fromPoint);
                        pcol.AddPoint(toPoint);
                        IPolyline pcolPolyline = pcol as IPolyline;

                        longestLine = (longestLine != null && longestLine.Length < pcolPolyline.Length) ? pcolPolyline : longestLine;

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass()
                            {
                                Green = 255
                            });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass()
                            {
                                Red = 255
                            });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            if (targetIsVisible)
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Green = 255
                                });
                            }
                            else
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Red = 255
                                });
                            }
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                    {
                        Blue = 255
                    }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Green = 255
                        });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Red = 255
                        });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
                ZoomToExtent(longestLine);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong,
                                                     VisibilityLibrary.Properties.Resources.CaptionError);
            }
            finally
            {
                IsRunning = false;
            }
        }
コード例 #7
0
        private void RandomSelection(int layerIndex, int count)
        {
            var layer = _selectableLayers[layerIndex].Layer as IFeatureLayer;
            //Debug.Assert(layer != null, "Selection layer not found");
            if (layer == null)
                return;

            //IFeatureSelection controls which features in a layer are selected
            var selectionLayer = layer as IFeatureSelection;
            if (selectionLayer == null)
                return;

            selectionLayer.Clear();
            //get the oids of just the features in the definition query
            //Don't query the feature class, because it returns all features
            ISelectionSet oids = ((ITable)layer).Select(null,
                                                        esriSelectionType.esriSelectionTypeHybrid,
                                                        esriSelectionOption.esriSelectionOptionNormal, null);
            IGeoDatabaseBridge2 helper = new GeoDatabaseHelperClass();

            if (count < oids.Count - count)
            {
                int[] oidsToAdd = BuildOidArray(oids, count);
                helper.AddList(selectionLayer.SelectionSet, oidsToAdd);
            }
            else
            {
                int[] oidsToRemove = BuildOidArray(oids, oids.Count - count);
                helper.RemoveList(oids, oidsToRemove);
                selectionLayer.SelectionSet = oids;
            }

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
        }
コード例 #8
0
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                    return;

                base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                    return;

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                    return;

                IPoint pointObstruction = null;
                IPolyline polyVisible = null;
                IPolyline polyInvisible = null;
                bool targetIsVisible = false;

                double finalObserverOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary<IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (surface.IsVoidZ(z1))
                    {
                        if (double.IsNaN(z1))
                            z1 = 0.000001;
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (surface.IsVoidZ(z2))
                        {
                            if (double.IsNaN(z2))
                                z2 = 0.000001;
                        }

                        var fromPoint = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true } as IPoint;
                        var toPoint = new PointClass() { Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                            out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass() { Green = 255 });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass() { Red = 255 });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            var pcol = new PolylineClass() as IPointCollection;
                            pcol.AddPoint(fromPoint);
                            pcol.AddPoint(toPoint);

                            if (targetIsVisible)
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Green = 255 });
                            else
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Red = 255 });
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Blue = 255 }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Green = 255 });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Red = 255 });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong);
            }
            finally
            {
                IsRunning = false;
            }
        }
        private void setDynamicDefaults(IObject inObject, string mode)
        {
            try
            {
                //Convert row to feature (test for feature is null before using - this could be a table update)
                IFeature inFeature = inObject as IFeature;

                // Skip Orphan Junctions (saves time)
                if (inFeature != null)
                {
                    INetworkFeature inNetFeat = inObject as INetworkFeature;
                    if ((inNetFeat != null) &&
                        (inFeature.Class.ObjectClassID == inNetFeat.GeometricNetwork.OrphanJunctionFeatureClass.ObjectClassID))
                        return;
                }

                //Get cursor to dynamic values table retriving only
                ICursor tabCursor;
                getDefaultRows(inObject, out tabCursor);
                IRow row = null;
                if (tabCursor != null)
                    row = tabCursor.NextRow();

                //for each row in the matching rows (matched by table name or wildcard) returned from the config table
                while (row != null)
                {
                    //get fieldname
                    string fieldName = row.get_Value(dynTargetField).ToString();

                    //if this field is found in the feature/object being added or modified...
                    int fieldNum = inObject.Fields.FindField(fieldName);
                    if (fieldNum > -1)
                    {
                        // get requested method and any data parameters
                        string valMethod = row.get_Value(dynMethodField).ToString();
                        string valData = row.get_Value(dynDataField).ToString();

                        switch (mode)
                        {
                            case "OnCreate":
                                //Continue to next field in config table if create events were not requested
                                if (row.get_Value(dynCreateField).ToString() == "0")
                                {
                                    row = tabCursor.NextRow();
                                    continue;
                                }
                                break;
                            case "OnChange":
                                // Collect value for changed feature (stored for LAST VALUE method)
                                IRowChanges inChanges = inObject as IRowChanges;
                                bool changed = inChanges.get_ValueChanged(fieldNum);
                                if (changed)
                                    lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                                //Continue to next field in config table if change events were not requested
                                if (row.get_Value(dynChangeField).ToString() == "0")
                                {
                                    row = tabCursor.NextRow();
                                    continue;
                                }
                                break;
                        }

                        // set values as specified
                        switch (valMethod)
                        {
                            case "TIMESTAMP":

                                inObject.set_Value(fieldNum, DateTime.Now);
                                break;

                            case "LAST_VALUE":

                                if (mode == "OnCreate")
                                {
                                    //if (inObject.get_Value(fieldNum) == null)
                                    //{
                                    object lastValue = lastValueProperties.GetProperty(fieldName);
                                    if (lastValue != null)
                                        inObject.set_Value(fieldNum, lastValue);
                                    //}
                                }

                                break;

                            case "FIELD":

                                // verify that field to copy exists
                                int fieldCopy = inObject.Fields.FindField(valData as string);
                                if (fieldCopy > -1)
                                {
                                    //copy value only if current field is empty
                                    string currentValue = inObject.get_Value(fieldNum).ToString();
                                    if (currentValue == "")
                                        inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                }
                                break;

                            case "CURRENT_USER":

                                if (lastEditorName == null)
                                    lastEditorName = getCurrentUser();
                                inObject.set_Value(fieldNum, lastEditorName);
                                break;

                            case "GUID":

                                if (mode == "OnCreate") // SHould only set this once on create to give the object a unique value
                                {
                                    object currentValue = inObject.get_Value(fieldNum);
                                    if (DBNull.Value == currentValue) // Do not overwrite if someone else has already generated
                                    {
                                        Guid g = Guid.NewGuid();
                                        inObject.set_Value(fieldNum, g.ToString("B").ToUpper());
                                    }
                                }

                                break;

                            case "EXPRESSION":

                                if (mode == "OnCreate")
                                {
                                    if (inFeature != null & valData != null)
                                    {
                                        try
                                        {
                                            int calcField = inFeature.Fields.FindField(fieldName);
                                            //if (inFeature.get_Value(calcField) == null)
                                            //{
                                            int[] fids = { inFeature.OID };
                                            IGeoDatabaseBridge gdbBridge = new GeoDatabaseHelperClass();
                                            IFeatureCursor fCursor = (IFeatureCursor)gdbBridge.GetFeatures((IFeatureClass)inFeature.Class, ref fids, false);

                                            ICalculator calc = new CalculatorClass();
                                            calc.Expression = valData;
                                            calc.Field = fieldName;
                                            calc.Cursor = (ICursor)fCursor;
                                            calc.ShowErrorPrompt = false;

                                            ICalculatorCallback calculatorCallback = new CalculatorCallback();
                                            calc.Callback = calculatorCallback;

                                            calc.Calculate();
                                            calculatorCallback = null;
                                            //}
                                        }
                                        catch { }
                                    }
                                }
                                break;

                            default:
                                break;
                        }

                    }
                    row = tabCursor.NextRow();
                }

                if (null != tabCursor)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(tabCursor);
                }
            }
            catch (Exception ex)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Error applying dynamic defaults.", ex.ToString());

                MessageBox.Show("Error: \n" + ex.ToString());
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: l1985q/developer-support
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },
                                                         new esriLicenseExtensionCode[] { });
            //ESRI License Initializer generated code.

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

            IFeatureWorkspace fws = ws as IFeatureWorkspace;

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

            ITableWrite tw = fc as ITableWrite;

            int numRows = 300;

            Int32[] int32Array = new Int32[numRows];

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

            IGeoDatabaseBridge2 gdbBridge2 = new GeoDatabaseHelperClass();

            //IGeoDatabaseBridge2 fc_gdbBridge2 = fc as IGeoDatabaseBridge2;

            bool Recycling = false;

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

            ISet setOfRows = new SetClass();

            IFeature feat;

            feat = featCursor.NextFeature();

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

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

            DateTime dateTimeNow_Start = System.DateTime.Now;

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

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

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

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

            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: ApexGIS/developer-support
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },
            new esriLicenseExtensionCode[] { });
            //ESRI License Initializer generated code.

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

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

            ITableWrite tw = fc as ITableWrite;

            int numRows = 300;
            Int32[] int32Array = new Int32[numRows];

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

            IGeoDatabaseBridge2 gdbBridge2 = new GeoDatabaseHelperClass();

            //IGeoDatabaseBridge2 fc_gdbBridge2 = fc as IGeoDatabaseBridge2;

            bool Recycling = false;

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

            ISet setOfRows = new SetClass();

            IFeature feat;
            feat = featCursor.NextFeature();

            while (feat != null)
            {
                IObject obj = feat as IObject;
                setOfRows.Add(obj);
                feat = featCursor.NextFeature();
            }
            
            // TEST 1: ITableWrite.DeleteRows
            //-------------------------------

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

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

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

            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
コード例 #12
0
ファイル: PatchEcosystem.cs プロジェクト: wblong/GIS_Frag
        public override bool CalculateIndex(ProgressBar progress)
        {
            try
            {
                progress.Maximum = baseData.zoneValue.Count;
                progress.Value   = 0;
                zoneArea         = new ZoneClassArea(baseData);
                for (int i = 0; i < baseData.zoneValue.Count; i++)
                {
                    List <double> temp    = new List <double>();
                    int[]         oidlist = baseData.patchIDArray[i];
                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        SCLASSAREA ClassArea = new SCLASSAREA();    //定义分区结构体;
                        //获取每个分区的要素集;
                        IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                        IFeatureCursor     featureCursor     = geodatabaseBridge.GetFeatures(baseData.zoneLCA_FC, ref oidlist, true);

                        ClassArea           = zoneArea.StatisticClassArea(featureCursor);
                        ClassArea.TotalArea = baseData.zoneArea[i];

                        //普通生态环境评价指标计算;
                        if (indexNameList[0].Count > 0)
                        {
                            dt_Popualtion = MainForm.dt_Population;
                            if (dt_Popualtion != null)
                            {
                                for (int j = 0; j < dt_Popualtion.Rows.Count; j++)
                                {
                                    if (baseData.zoneValue[i].ToString() == dt_Popualtion.Rows[j][0].ToString())
                                    {
                                        population = Convert.ToDouble(dt_Popualtion.Rows[j][1].ToString());
                                    }
                                }
                            }
                            commonIndex = new CommonEcoIndex(ClassArea, indexNameList[0]);
                            commonIndex.ComEcoIndexCal();
                            temp.AddRange(commonIndex.comEcoIndexResult);
                        }

                        //生态功能区生态环境评价指标计算;
                        if (indexNameList[1].Count > 0)
                        {
                            specialIndex = new SpecialEcoIndex(ClassArea, indexNameList[1]);
                            specialIndex.SpecialEcoIndexCal();
                            temp.AddRange(specialIndex.speEcoIndexResult);
                        }
                        //自然保护区生态环境评价指标计算;
                        if (indexNameList[2].Count > 0)
                        {
                            natureIndex = new NatureEcoIndex(ClassArea, indexNameList[2]);
                            natureIndex.NatureEcoIndexCal();
                            temp.AddRange(natureIndex.natEcoIndexResult);
                        }
                        progress.Value++;
                    }
                    indexCalResult.Add(temp);
                }
            }
            catch (System.Exception ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #13
0
        private void setDynamicDefaults(IObject inObject, string mode)
        {
            try
            {
                //Convert row to feature (test for feature is null before using - this could be a table update)
                IFeature inFeature = inObject as IFeature;

                // Skip Orphan Junctions (saves time)
                if (inFeature != null)
                {
                    INetworkFeature inNetFeat = inObject as INetworkFeature;
                    if ((inNetFeat != null) &&
                        (inFeature.Class.ObjectClassID == inNetFeat.GeometricNetwork.OrphanJunctionFeatureClass.ObjectClassID))
                    {
                        return;
                    }
                }

                //Get cursor to dynamic values table retriving only
                ICursor tabCursor;
                getDefaultRows(inObject, out tabCursor);
                IRow row = null;
                if (tabCursor != null)
                {
                    row = tabCursor.NextRow();
                }

                //for each row in the matching rows (matched by table name or wildcard) returned from the config table
                while (row != null)
                {
                    //get fieldname
                    string fieldName = row.get_Value(dynTargetField).ToString();

                    //if this field is found in the feature/object being added or modified...
                    int fieldNum = inObject.Fields.FindField(fieldName);
                    if (fieldNum > -1)
                    {
                        // get requested method and any data parameters
                        string valMethod = row.get_Value(dynMethodField).ToString();
                        string valData   = row.get_Value(dynDataField).ToString();

                        switch (mode)
                        {
                        case "OnCreate":
                            //Continue to next field in config table if create events were not requested
                            if (row.get_Value(dynCreateField).ToString() == "0")
                            {
                                row = tabCursor.NextRow();
                                continue;
                            }
                            break;

                        case "OnChange":
                            // Collect value for changed feature (stored for LAST VALUE method)
                            IRowChanges inChanges = inObject as IRowChanges;
                            bool        changed   = inChanges.get_ValueChanged(fieldNum);
                            if (changed)
                            {
                                lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                            }
                            //Continue to next field in config table if change events were not requested
                            if (row.get_Value(dynChangeField).ToString() == "0")
                            {
                                row = tabCursor.NextRow();
                                continue;
                            }
                            break;
                        }

                        // set values as specified
                        switch (valMethod)
                        {
                        case "TIMESTAMP":

                            inObject.set_Value(fieldNum, DateTime.Now);
                            break;

                        case "LAST_VALUE":

                            if (mode == "OnCreate")
                            {
                                //if (inObject.get_Value(fieldNum) == null)
                                //{
                                object lastValue = lastValueProperties.GetProperty(fieldName);
                                if (lastValue != null)
                                {
                                    inObject.set_Value(fieldNum, lastValue);
                                }
                                //}
                            }


                            break;

                        case "FIELD":

                            // verify that field to copy exists
                            int fieldCopy = inObject.Fields.FindField(valData as string);
                            if (fieldCopy > -1)
                            {
                                //copy value only if current field is empty
                                string currentValue = inObject.get_Value(fieldNum).ToString();
                                if (currentValue == "")
                                {
                                    inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                }
                            }
                            break;

                        case "CURRENT_USER":

                            if (lastEditorName == null)
                            {
                                lastEditorName = getCurrentUser();
                            }
                            inObject.set_Value(fieldNum, lastEditorName);
                            break;

                        case "GUID":

                            if (mode == "OnCreate")     // SHould only set this once on create to give the object a unique value
                            {
                                object currentValue = inObject.get_Value(fieldNum);
                                if (DBNull.Value == currentValue)     // Do not overwrite if someone else has already generated
                                {
                                    Guid g = Guid.NewGuid();
                                    inObject.set_Value(fieldNum, g.ToString("B").ToUpper());
                                }
                            }

                            break;

                        case "EXPRESSION":

                            if (mode == "OnCreate")
                            {
                                if (inFeature != null & valData != null)
                                {
                                    try
                                    {
                                        int calcField = inFeature.Fields.FindField(fieldName);
                                        //if (inFeature.get_Value(calcField) == null)
                                        //{
                                        int[] fids = { inFeature.OID };
                                        IGeoDatabaseBridge gdbBridge = new GeoDatabaseHelperClass();
                                        IFeatureCursor     fCursor   = (IFeatureCursor)gdbBridge.GetFeatures((IFeatureClass)inFeature.Class, ref fids, false);

                                        ICalculator calc = new CalculatorClass();
                                        calc.Expression      = valData;
                                        calc.Field           = fieldName;
                                        calc.Cursor          = (ICursor)fCursor;
                                        calc.ShowErrorPrompt = false;

                                        ICalculatorCallback calculatorCallback = new CalculatorCallback();
                                        calc.Callback = calculatorCallback;

                                        calc.Calculate();
                                        calculatorCallback = null;
                                        //}
                                    }
                                    catch { }
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    row = tabCursor.NextRow();
                }

                if (null != tabCursor)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(tabCursor);
                }
            }
            catch (Exception ex)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Error applying dynamic defaults.", ex.ToString());

                MessageBox.Show("Error: \n" + ex.ToString());
            }
        }
コード例 #14
0
ファイル: PatchLand.cs プロジェクト: wblong/GIS_Frag
        /// <summary>
        /// 重写计算指标
        /// </summary>
        /// <returns></returns>
        public override bool CalculateIndex(ProgressBar progress)
        {
            try
            {
                //计算每一个分区
                List <string> zones = baseData.zoneValue;
                progress.Maximum = zones.Count * patchLandCac.Count;
                for (int i = 0; i < zones.Count; i++)
                {
                    List <double> temp         = new List <double>();
                    string        zid          = zones[i];
                    int[]         oidlist      = baseData.patchIDArray[i];
                    double        zoneArea     = baseData.zoneArea[i];
                    double        zoneLength   = 0.0;
                    double        zoneAreaTrue = 0.0;
                    if (baseData.zone_FC != null)
                    {
                        zoneLength   = (double)baseData.zone_FC.GetFeature(baseData.zoneObjectID[i]).get_Value(baseData.perimeterIndex_zone);
                        zoneAreaTrue = (double)baseData.zone_FC.GetFeature(baseData.zoneObjectID[i]).get_Value(baseData.areaIndex_zone);
                    }

                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        for (int j = 0; j < patchLandCac.Count; j++)
                        {
                            IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                            IFeatureCursor     featureCursor     = geodatabaseBridge.GetFeatures(baseData.zoneLCA_FC,
                                                                                                 ref oidlist, true);
                            switch (patchLandCac[j].Name())
                            {
                            case "UMeshIndex":
                                temp.Add(patchLandCac[j].CaculateLandIndex(featureCursor, baseData) / zoneAreaTrue * 100);
                                break;

                            case "MeshIndex":
                                temp.Add(patchLandCac[j].CaculateLandIndex(featureCursor, baseData) / zoneAreaTrue * 0.000001);
                                break;

                            case "MEffectMeshArea":
                                temp.Add(patchLandCac[j].CaculateLandIndex(featureCursor, baseData) / zoneAreaTrue * 0.000001);
                                break;

                            case "TotalEdge":
                                temp.Add((patchLandCac[j].CaculateLandIndex(featureCursor, baseData) - zoneLength) * 0.5 + zoneLength);
                                break;

                            case "TotalArea":
                                temp.Add(zoneArea);
                                break;

                            case "EdgeDensity":
                                temp.Add(((patchLandCac[j].CaculateLandIndex(featureCursor, baseData) - zoneLength) * 0.5 + zoneLength) / zoneArea);
                                break;

                            default:
                                temp.Add(patchLandCac[j].CaculateLandIndex(featureCursor, baseData));
                                break;
                            }
                            progress.Value++;
                        }
                    }

                    result_list.Add(temp);
                }
            }
            catch (System.Exception ex)
            {
                return(false);
            }



            return(true);
        }
コード例 #15
0
ファイル: CustomIndexCal.cs プロジェクト: wblong/GIS_Frag
        private List <List <double> > GetData(List <string> query)
        {
            string strA = "Area";
            string strP = "Perimeter";
            List <List <double> > data = null;

            #region 查询每个分区的所需数据
            for (int i = 0; i < baseData.zoneValue.Count; i++)
            {
                int[]         oidlist  = baseData.patchIDArray[i];
                List <double> eachArea = null;
                using (ComReleaser comReleaser = new ComReleaser())
                {
                    IGeoDatabaseBridge geodatabaseBridge = new GeoDatabaseHelperClass();
                    //每个分区的要素集;
                    IFeatureCursor featureCursor = geodatabaseBridge.GetFeatures(baseData.zoneLCA_FC,
                                                                                 ref oidlist, true);
                    IFeature pFeature = null;

                    #region 根据计算公式中的查询条件获取当前分区的数据
                    for (int j = 0; j < query.Count; j++)
                    {
                        double zoneData = 0;
                        double tempData = 0;
                        string str      = query[j].Substring(query[j].IndexOf("'") + 1, query[j].LastIndexOf("'") - query[j].IndexOf("'") - 1);
                        if (str == "0000")
                        {
                            //确认查询的是面积;
                            if (query[j].IndexOf(strA) > -1)
                            {
                                tempData = baseData.areaIndex;
                            }
                            //确认查询的是周长;
                            else if (query[j].IndexOf(strP) > -1)
                            {
                                tempData = baseData.perimeterIndex;
                            }
                            eachArea.Add(tempData);
                        }
                        else
                        {
                            while ((pFeature = featureCursor.NextFeature()) != null)
                            {
                                //确认查询的是面积;
                                if (query[j].IndexOf(strA) > -1)
                                {
                                    tempData = (double)pFeature.get_Value(baseData.areaIndex);
                                }
                                //确认查询的是周长;
                                else if (query[j].IndexOf(strP) > -1)
                                {
                                    tempData = (double)pFeature.get_Value(baseData.perimeterIndex);
                                }
                                string code = pFeature.get_Value(baseData.codeIndex).ToString();
                                if (code == str)
                                {
                                    zoneData += tempData;
                                }
                            }
                            eachArea.Add(zoneData);
                        }
                    }
                    #endregion
                }
                data.Add(eachArea);
            }
            #endregion
            return(data);
        }
コード例 #16
0
ファイル: PERFQA_ARCFM.cs プロジェクト: UDCUS/ArcFM_PerfQA
        private bool RemoveFromSelecdtion(string sLayerName, string sOID)
        {
            IMxDocument pMXDoc;
            IEnumLayer pLayers;
            ILayer pLayer;
            IFeatureLayer pFLayer;
            IFeatureSelection pFSel;
            ISelectionSet pSelSet;
            IGeoDatabaseBridge2 pGDBBridge;
            int[] OIDList;

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

                pMXDoc = GetDoc();
                pLayers = pMXDoc.FocusMap.get_Layers(null, true);
                pLayer = pLayers.Next();
                while (pLayer != null)
                {
                    if (pLayer.Name == sLayerName)
                    {
                        if (pLayer is IFeatureLayer)
                        {
                            pFLayer = (IFeatureLayer)pLayer;
                            pFSel = (IFeatureSelection)pFLayer;
                            pSelSet = pFSel.SelectionSet;
                            pGDBBridge = new GeoDatabaseHelperClass();
                            OIDList = new int[1];
                            OIDList[0] = Convert.ToInt32(sOID);
                            pGDBBridge.RemoveList(pSelSet, OIDList);
                        }
                    }
                    pLayer = pLayers.Next();
                }
                SW1.Stop();
                RecordActionTime("REMOVEFROMSELECTION:" , SW1.ElapsedMilliseconds);
                return true;
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("RemoveFromSelection error:" + EX.Message + " " + EX.StackTrace);
                return false;
            }
        }