private void SetPINValue()
    {
      //The Theory.
      //Select polygons that intersect the sketch.
      //Construct one polyline from the boundaries and intersect with sketch.
      //Sort resulting intersection locations (multipoint) by distance of the intersect
      // from the start of the sketch and create new ordered multipoint.
      //Loop through new ordered multipoint, select underlying parcel and calc pin.

      IFeatureLayer featLayer = m_editLayers.CurrentLayer;
      m_curve = m_edSketch.Geometry as IPolyline;

      //Search parcel polys by graphic to get feature cursor
      ISpatialFilter spatialFilter = new SpatialFilter();
      spatialFilter.Geometry = m_curve;
      spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName;
      spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;

      IFeatureCursor featCursor = featLayer.Search(spatialFilter,true);
      IFeature feature = featCursor.NextFeature();

      //If we have no intersects then exit
      if (feature == null)
        return;
  
      //Make a GeomBag of the polygons boundaries (polylines)
      IGeometryCollection geomBag = new GeometryBagClass();
      object missing = Type.Missing;
      while (feature != null)
      {
        ITopologicalOperator poly = feature.Shape as ITopologicalOperator;
        geomBag.AddGeometry(poly.Boundary,ref missing,ref missing);
        feature = featCursor.NextFeature();
      }

      //Make one polyline from the boundaries
      IPolyline polyLineU = new PolylineClass();
      ITopologicalOperator topoOp = polyLineU as ITopologicalOperator;
      topoOp.ConstructUnion(geomBag as IEnumGeometry);

      //Get the intersections of the boundaries and the curve
      IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection;

      //The point collection is not ordered by distance along the curve so
      //need to create a new collection with this info

      int[] pointOrder = new int[pointCol.PointCount];
      double dac = 0, dfc = 0;
      bool bRS = false;

      for (int i = 0; i < pointCol.PointCount; i++)
      {
        IPoint queryPoint = new PointClass();
        pointCol.QueryPoint(i, queryPoint);
        m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null,ref dac,ref dfc,ref bRS);
        pointOrder[i] = (int)dac;
      }

      //use built in bubble sort
      System.Array.Sort(pointOrder);

      //Loop through the sorted array and calc midpoint between parcel boundaries
      IPointCollection midPoints = new MultipointClass();

      for (int i = 0; i < pointOrder.Length -1; i++)
      {
        //Get the midpoint distance
        double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2;
        
        //create a point at the distance and store in point collection
        IPoint queryPoint = new PointClass();
        m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint);
        midPoints.AddPoint(queryPoint,ref missing,ref missing);
      }

      //If ends of sketch are included then add them as points
      if (chkEnds.Checked)
      {
        object before = 0 as object;
        midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing);
        midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing);
      }

      m_editor.StartOperation();

      //Loop through calculated midpoints, select polygon and calc pin
      for (int i = 0; i < midPoints.PointCount; i++)
      {
        IPoint midPoint = midPoints.get_Point(i);
        spatialFilter = new SpatialFilter();
        spatialFilter.Geometry = midPoint;
        spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;

        featCursor = featLayer.Search(spatialFilter, false);
        while ((feature = featCursor.NextFeature()) != null)
        {
          feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum);
          feature.Store();
          m_lotNum += int.Parse(txtlotinc.Text);
        }
      }
      m_editor.StopOperation("ViperPIN");
      txtlot.Text = m_lotNum.ToString();
    }
        internal void LoadFile(int X, int Y)
        {
            if (CheckRequirments())
            {
                try
                {
                    ESRI.ArcGIS.Display.IScreenDisplay screenDisplay    = (_application.Document as IMxDocument).ActiveView.ScreenDisplay;
                    ESRI.ArcGIS.Geometry.IPoint        point            = screenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                    ESRI.ArcGIS.Carto.IFeatureLayer    tilefeaturelayer = _utilitiesArcMap.FeatureLayer(cboTileIndex.Text);
                    IFeatureClass tilefeatureclass = tilefeaturelayer.FeatureClass;

                    ISpatialFilter spatialfilter = new SpatialFilter();
                    spatialfilter.GeometryField = tilefeatureclass.ShapeFieldName;
                    spatialfilter.Geometry      = point;
                    spatialfilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                    IFeatureCursor tilefeaturecursor = tilefeatureclass.Search(spatialfilter, false);
                    IFeature       tilefeature       = null;

                    while ((tilefeature = tilefeaturecursor.NextFeature()) != null)
                    {
                        object obj = tilefeature.get_Value(_utilitiesArcMap.FindField(tilefeature, this.cboNameField.Text));
                        if (obj != DBNull.Value)
                        {
                            string tilename = obj.ToString();
                            LoadFile(txbFileWorkspace.Text + "\\" + tilename + ".");
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 3
0
        private void QueryBut_Click(object sender, EventArgs e)
        {
            IFeatureClass  featureClass  = this.SelectLayer.FeatureClass;
            ISpatialFilter spatialFilter = new SpatialFilter();
            string         text          = "";
            int            count         = this.DXArray.Count;
            int            num           = 1;

            foreach (string current in this.DXArray)
            {
                text += this.strDX;
                text += " = '";
                text += current;
                text += "'";
                if (num < count)
                {
                    text += " OR ";
                }
                num++;
            }
            spatialFilter.WhereClause = text;
            if (this.GeometrySet.Checked)
            {
                if (this.m_ipGeo != null)
                {
                    spatialFilter.Geometry = (this.m_ipGeo);
                }
                spatialFilter.SpatialRel = (esriSpatialRelEnum)(1);
            }
            IFeatureCursor pCursor = featureClass.Search(spatialFilter, false);

            //修改为插件事件,因为结果显示窗体为插件拥有。
            _plugin.FireQueryResultChanged(new QueryResultArgs(pCursor, (IFeatureSelection)this.SelectLayer, spatialFilter));
        }
Esempio n. 4
0
        async public Task <IRasterLayerCursor> ChildLayers(gView.Framework.Carto.IDisplay display, string filterClause)
        {
            if (_fc == null || display == null || _fdb == null)
            {
                return(new SimpleRasterlayerCursor(new List <IRasterLayer>()));
            }

            double dpm = Math.Max(display.Canvas.DpiX, display.Canvas.DpiY) / 0.0254;
            double pix = display.mapScale / dpm; /*display.dpm;*/                              // [m]

            IEnvelope dispEnvelope = display.DisplayTransformation.TransformedBounds(display); //display.Envelope;

            if (display.GeometricTransformer != null)
            {
                dispEnvelope = (IEnvelope)((IGeometry)display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
            }

            SpatialFilter filter = new SpatialFilter();

            filter.Geometry        = dispEnvelope;
            filter.SubFields       = "*";
            filter.WhereClause     = filterClause;
            filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;

            return(new RasterLayerCursor(this, await _fc.Search(filter) as IFeatureCursor,
                                         dispEnvelope, pix));
        }
Esempio n. 5
0
        // Spatialt filtrerar de objekt e.g. vägar som korsar säkra platser, d.v.s. platser som inte kommer att påverkas av översvämning.
        public IFeatureSelection spatialFilter(IFeatureLayer safeLayer, IFeatureLayer roadLayer)
        {
            try {
                IQueryFilter queryFilter = new QueryFilter();

                IFeatureClass  safeFC      = safeLayer.FeatureClass;
                IFeatureCursor safeCursor  = safeFC.Search(queryFilter, true);
                IFeature       safeFeature = safeCursor.NextFeature();

                ISpatialFilter spatialFilter = new SpatialFilter();
                spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                spatialFilter.Geometry      = safeFeature.Shape;
                spatialFilter.GeometryField = safeFeature.Shape.ToString();

                IFeatureSelection fSelect = (IFeatureSelection)roadLayer;
                while (safeFeature != null)
                {
                    fSelect.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
                    safeFeature = safeCursor.NextFeature();
                }

                mxDoc.ActiveView.Refresh();
                return(fSelect);
            } catch (Exception ex) {
                MessageBox.Show(ex.StackTrace);
                return(null);
            }
        }
Esempio n. 6
0
        public bool Buffer(string layerName, string sWhere, int iSize, IMap iMap)
        {
            IFeatureClass featureClass;
            IFeature      feature;
            IGeometry     geometry;

            DataOperator  dataOperator = new DataOperator(iMap);
            IFeatureLayer featureLayer = (IFeatureLayer)dataOperator.GetLayerByName(layerName);

            featureClass = featureLayer.FeatureClass;
            IQueryFilter queryFilter = new QueryFilter();

            queryFilter.WhereClause = sWhere;
            IFeatureCursor featureCursor;

            featureCursor = (IFeatureCursor)featureClass.Search(queryFilter, false);
            int count = featureClass.FeatureCount(queryFilter);

            feature  = featureCursor.NextFeature();
            geometry = feature.Shape;

            ITopologicalOperator ipTO        = (ITopologicalOperator)geometry;
            IGeometry            iGeomBuffer = ipTO.Buffer(iSize);

            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry   = iGeomBuffer;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;

            IFeatureSelection featureSelection = (IFeatureSelection)featureLayer;

            featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);

            return(true);
        }
Esempio n. 7
0
    protected override void OnStopStreaming()
    {
        if (aligner != null)
        {
            aligner.Dispose();
            aligner = null;
        }

        if (decimationFilter != null)
        {
            decimationFilter.Dispose();
            decimationFilter = null;
        }

        if (spatialFilter != null)
        {
            spatialFilter.Dispose();
            spatialFilter = null;
        }

        if (temporalFilter != null)
        {
            temporalFilter.Dispose();
            temporalFilter = null;
        }
    }
Esempio n. 8
0
        protected override void Execute()
        {
            var featureClass = Workspace.OpenFeatureClass(SearchArgs.LayerName.Trim());

            var spatFilter = new SpatialFilter
            {
                SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin,
                Geometry   = SearchArgs.Point
            };

            var fCursor = featureClass.Search(spatFilter, true);

            var fields  = featureClass.Fields;
            var feature = fCursor.NextFeature();

            if (feature == null)
            {
                Result = null;

                return;
            }

            Result =
                SearchArgs.AttributeList.Select(
                    x =>
                    new FieldValueMap(x.Trim(),
                                      CommandExecutor.ExecuteCommand(new GetValueForFieldCommand(x, fields, feature))))
                .ToArray();
        }
Esempio n. 9
0
        async public Task <List <IRasterLayer> > QueryChildLayers(IGeometry geometry, string filterClause)
        {
            List <IRasterLayer> childlayers = new List <IRasterLayer>();

            if (_fc == null || _fdb == null)
            {
                return(childlayers);
            }

            SpatialFilter filter = new SpatialFilter();

            filter.Geometry        = geometry;
            filter.SubFields       = "*";
            filter.WhereClause     = filterClause;
            filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;

            using (IRasterLayerCursor cursor = new RasterLayerCursor(
                       this, await _fc.Search(filter) as IFeatureCursor))
            {
                IRasterLayer layer;
                while ((layer = await cursor.NextRasterLayer()) != null)
                {
                    childlayers.Add(layer);
                }
            }
            return(childlayers);
        }
Esempio n. 10
0
        public static void QueryFeaturesTest()
        {
            MapServiceFidTests.Initialize();
            LayerDescription layerDescription = null;

            LayerDescription[] layerDescriptions = MapServiceFidTests._mapinfo.DefaultMapDescription.LayerDescriptions;
            for (int i = 0; i < layerDescriptions.Length; i++)
            {
                LayerDescription layerDescription2 = layerDescriptions[i];
                if (layerDescription2.LayerID == 13)
                {
                    layerDescription = layerDescription2;
                    break;
                }
            }
            string        geomFieldName = MapServiceFidTests.GetGeomFieldName(MapServiceFidTests._mapinfo, layerDescription.LayerID);
            SpatialFilter spatialfilter = MapServiceFidTests.BuildSpatialFilter((EnvelopeN)MapServiceFidTests._mapinfo.Extent, geomFieldName, MapServiceFidTests._mapinfo.DefaultMapDescription.SpatialReference);

            MapServiceFidTests.completeSpRef = MapServiceFidTests._mapinfo.DefaultMapDescription.SpatialReference;
            int num = 4326;

            MapServiceFidTests.wkidSpRef = MapServiceFidTests.SpRefFromWKID(ref num);
            string wKT = MapServiceFidTests.completeSpRef.WKT;

            MapServiceFidTests.wktSpRef = MapServiceFidTests.SpRefFromWKT(ref wKT);
            string text = "PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0],AUTHORITY[\"EPSG\",3857]]";

            MapServiceFidTests.alternateSpRef = MapServiceFidTests.SpRefFromWKT(ref text);
            MapServiceFidTests.TestAlt(layerDescription, spatialfilter);
        }
Esempio n. 11
0
        public static void TheTest(LayerDescription activelayerdesc, SpatialFilter spatialfilter, SpatialReference sp1, SpatialReference sp2)
        {
            string oIDFieldName = MapServiceFidTests.GetOIDFieldName(MapServiceFidTests._mapinfo, activelayerdesc.LayerID);

            spatialfilter.OutputSpatialReference = sp1;
            EnvelopeN envelopeN = spatialfilter.FilterGeometry as EnvelopeN;

            envelopeN.SpatialReference   = sp2;
            spatialfilter.FilterGeometry = envelopeN;
            FIDSet      fIDSet      = MapServiceFidTests.BuildFIDSet(MapServiceFidTests.name, activelayerdesc, spatialfilter);
            QueryFilter queryFilter = MapServiceFidTests.BuildQueryFromFIDSet(fIDSet, sp1);

            queryFilter.OutputSpatialReference = sp1;
            RecordSet        recordSet        = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, false);
            RecordSet        rs               = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, true);
            int              num              = MapServiceFidTests.FindGeometryFieldIndex(recordSet);
            SpatialReference spatialReference = recordSet.Fields.FieldArray[num].GeometryDef.SpatialReference;

            recordSet = MapServiceFidTests.ProjectRecordSet(MapServiceFidTests._mapinfo.FullExtent, recordSet, num, spatialReference, sp2);
            rs        = MapServiceFidTests.ProjectRecordSet(MapServiceFidTests._mapinfo.FullExtent, rs, num, spatialReference, sp2);
            FIDSet fIDSet2 = MapServiceFidTests.BuildDeltaFIDSet(fIDSet, recordSet, oIDFieldName);

            while (fIDSet2.FIDArray.Length > 0)
            {
                queryFilter = MapServiceFidTests.BuildQueryFromFIDSet(fIDSet2, sp1);
                queryFilter.OutputSpatialReference = sp1;
                recordSet = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, false);
                rs        = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, true);
                fIDSet2   = MapServiceFidTests.BuildDeltaFIDSet(fIDSet2, recordSet, oIDFieldName);
            }
        }
Esempio n. 12
0
        public static SpatialFilter BuildSpatialFilter(EnvelopeN env, string geomField, SpatialReference spRef)
        {
            SpatialFilter result;

            try
            {
                SpatialFilter spatialFilter = new SpatialFilter();
                env.SpatialReference         = spRef;
                spatialFilter.FilterGeometry = env;
                if (!string.IsNullOrEmpty(geomField))
                {
                    spatialFilter.GeometryFieldName = geomField;
                }
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
                if (!string.IsNullOrEmpty(env.SpatialReference.WKT))
                {
                    string wKT = env.SpatialReference.WKT;
                    spatialFilter.OutputSpatialReference = MapServiceFidTests.SpRefFromWKT(ref wKT);
                }
                else if (env.SpatialReference.WKIDSpecified)
                {
                    int wKID = env.SpatialReference.WKID;
                    spatialFilter.OutputSpatialReference = MapServiceFidTests.SpRefFromWKID(ref wKID);
                }
                result = spatialFilter;
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// find the strongest signal
        /// </summary>
        public void reCalculateSignal()
        {
            IFeatureWorkspace pFWorkspace   = (IFeatureWorkspace)_workspace;
            IFeatureClass     pTowerRangeFC = pFWorkspace.OpenFeatureClass("sde.TowerRange");

            ISpatialFilter pSFilter = new SpatialFilter();

            pSFilter.Geometry   = DeviceLocation;
            pSFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            // pSFilter.SubFields = "TOWERID, MAX(RANGE)";
            IFeatureCursor pFCursor = pTowerRangeFC.Search(pSFilter, true);
            IFeature       pFeature = pFCursor.NextFeature();

            Bars = 0;
            while (pFeature != null)
            {
                int    bars = pFeature.get_Value(pFeature.Fields.FindField("RANGE"));
                string tid  = pFeature.get_Value(pFeature.Fields.FindField("TOWERID"));
                if (bars > Bars)
                {
                    Tower t = new Tower();
                    t.ID           = tid;
                    connectedTower = t;
                    Bars           = bars;
                }

                pFeature = pFCursor.NextFeature();
            }
        }
Esempio n. 14
0
        private IFeature FindFeature(IPoint ipoint_0)
        {
            IFeature  feature  = null;
            double    mapUnits = Common.ConvertPixelsToMapUnits((IActiveView)_context.FocusMap, this.double_0);
            IEnvelope envelope = ipoint_0.Envelope;

            envelope.Height = mapUnits;
            envelope.Width  = mapUnits;
            envelope.CenterAt(ipoint_0);
            ISpatialFilter spatialFilterClass = new SpatialFilter()
            {
                Geometry   = envelope,
                SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            };

            for (int i = 0; i < _context.FocusMap.LayerCount; i++)
            {
                IFeatureLayer layer = _context.FocusMap.Layer[i] as IFeatureLayer;
                if (layer != null && layer.Visible && layer.FeatureClass != null &&
                    layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    spatialFilterClass.GeometryField = layer.FeatureClass.ShapeFieldName;
                    IFeatureCursor featureCursor = layer.Search(spatialFilterClass, false);
                    this.GetProximityFeature(ipoint_0, featureCursor, ref feature);
                    ComReleaser.ReleaseCOMObject(featureCursor);
                }
            }
            return(feature);
        }
Esempio n. 15
0
        public string GetFeatureVal(IPoint pPoint, IFeatureLayer pFLayer, string strField)
        {
            string         functionReturnValue;
            ISpatialFilter pSpatialFilter;

            pSpatialFilter            = new SpatialFilter();
            pSpatialFilter.Geometry   = pPoint;
            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            IFeatureCursor pFeatureCursor;

            pFeatureCursor = pFLayer.Search(pSpatialFilter, true);

            IFeature pFeature;

            pFeature = pFeatureCursor.NextFeature();

            if ((pFeature != null))
            {
                functionReturnValue = pFeature.Value[pFeatureCursor.FindField(strField)].ToString();
            }
            else
            {
                functionReturnValue = "Undefined";
            }
            return(functionReturnValue);
        }
Esempio n. 16
0
        private IFeature isGeometrySearched(IFeatureClass iFeatureClass, IGeometry searchGeo, esriSpatialRelEnum SpatialRel)
        {
            IFeatureCursor iFeatureCursor = null;
            IFeature       iFeature       = null;
            ISpatialFilter iSpatialFilter = null;

            try
            {
                iSpatialFilter            = new SpatialFilter();
                iSpatialFilter.Geometry   = searchGeo;
                iSpatialFilter.SpatialRel = SpatialRel;
                iFeatureCursor            = iFeatureClass.Search(iSpatialFilter, false);
                iFeature = iFeatureCursor.NextFeature();
                if (iFeature != null)
                {
                    return(iFeature);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            finally
            {
                //注意不要释放了IFeature外面还要用
                m_SDEUtils.ReleaseComObject(iFeatureCursor);
                m_SDEUtils.ReleaseComObject(iSpatialFilter);
            }
        }
Esempio n. 17
0
        public bool Buffer(string layerName, string sWhere, int iSize, IMap imap)
        {
            IFeatureClass pFcl;
            IFeature      pF;
            IGeometry     pGt;
            DataOperator  pDo = new DataOperator(imap, null);
            IFeatureLayer pFl = (IFeatureLayer)pDo.GetLayerbyName(layerName);

            pFcl = pFl.FeatureClass;
            IQueryFilter pQf = new QueryFilterClass();

            pQf.WhereClause = sWhere;
            IFeatureCursor pFc;

            pFc = (IFeatureCursor)pFcl.Search(pQf, false);
            int count = pFcl.FeatureCount(pQf);

            pF  = pFc.NextFeature();
            pGt = pF.Shape;
            ITopologicalOperator pTo       = (ITopologicalOperator)pGt;
            IGeometry            pGtBuffer = pTo.Buffer(iSize);
            ISpatialFilter       pSf       = new SpatialFilter();

            pSf.Geometry   = pGtBuffer;
            pSf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;
            IFeatureSelection pFs = (IFeatureSelection)pFl;

            pFs.SelectFeatures(pSf, esriSelectionResultEnum.esriSelectionResultNew, false);
            return(true);
        }
        public MigrateMapToFeatureDatabaseDialog(IMapDocument doc, IMap map)
        {
            InitializeComponent();

            _doc = doc;
            _map = map;

            #region Filter
            //All Features
            //Selected Features
            //Features in actual extent
            cmbExport.Items.Add(new ExportMethodItem("All Features", null));

            if (map.Display.Envelope != null)
            {
                SpatialFilter dispFilter = new SpatialFilter();
                dispFilter.SubFields = "*";

                dispFilter.FilterSpatialReference = map.Display.SpatialReference;
                dispFilter.Geometry        = map.Display.Envelope;
                dispFilter.SpatialRelation = spatialRelation.SpatialRelationIntersects;

                cmbExport.Items.Add(new ExportMethodItem("Features in actual extent", dispFilter));
            }

            if (cmbExport.SelectedIndex == -1)
            {
                cmbExport.SelectedIndex = 0;
            }
            #endregion
        }
Esempio n. 19
0
        public bool QueryInter(string srcLayerName, string tgtLayerName, IMap iMap, esriSpatialRelationEnum spatialRel)
        {
            DataOperator   dataOperator = new DataOperator(iMap);
            IFeatureLayer  iSrcLayer    = (IFeatureLayer)dataOperator.GetLayerByName(srcLayerName);
            IFeatureLayer  iTgtLayer    = (IFeatureLayer)dataOperator.GetLayerByName(tgtLayerName);
            IGeometry      geom;
            IFeature       feature;
            IFeatureCursor featureCursor;
            IFeatureClass  srcFeatClass;
            IQueryFilter   queryFilter = new QueryFilter();

            queryFilter.WhereClause = "CONTINENT='Asia'";
            featureCursor           = iTgtLayer.FeatureClass.Search(queryFilter, false);
            feature      = featureCursor.NextFeature();
            geom         = feature.Shape;
            srcFeatClass = iSrcLayer.FeatureClass;
            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry    = geom;
            spatialFilter.WhereClause = "POPULATION=1060000";
            spatialFilter.SpatialRel  = (esriSpatialRelEnum)spatialRel;
            IFeatureSelection featureSelect = (IFeatureSelection)iSrcLayer;

            featureSelect.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
            return(true);
        }
Esempio n. 20
0
        public Tower GetNearestTower(IPoint pPoint, int buffer)
        {
            ITopologicalOperator pTopo = (ITopologicalOperator)pPoint;

            IGeometry pBufferedPoint = pTopo.Buffer(buffer);

            ISpatialFilter pSFilter = new SpatialFilter();

            pSFilter.Geometry   = pBufferedPoint;
            pSFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            //query the geodatabase..
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)_workspace;

            IFeatureClass fcTower = pFeatureWorkspace.OpenFeatureClass("Towers");

            IFeatureCursor pFCursor      = fcTower.Search(pSFilter, true);
            IFeature       pTowerFeature = pFCursor.NextFeature();

            if (pTowerFeature == null)
            {
                return(null);
            }

            return(GetTower(pTowerFeature));
        }
Esempio n. 21
0
        public static ArrayList GetIntersectFeature(IGeoFeatureLayer pLayer, IGeometry pGeom)
        {
            ArrayList list = new ArrayList();

            if (pLayer != null)
            {
                if ((pGeom == null) || pGeom.IsEmpty)
                {
                    return(list);
                }
                ISpatialReference reference = (pLayer.FeatureClass as IGeoDataset).SpatialReference;
                if (reference != null)
                {
                    pGeom.SpatialReference = reference;
                    pGeom.SnapToSpatialReference();
                }
                ISpatialFilter filter = new SpatialFilter();
                filter.Geometry   = pGeom;
                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor o = pLayer.FeatureClass.Search(filter, false);
                for (IFeature feature = o.NextFeature(); feature != null; feature = o.NextFeature())
                {
                    list.Add(feature);
                }
                Marshal.ReleaseComObject(o);
            }
            return(list);
        }
Esempio n. 22
0
        private static bool FeatureLayerIdentify(IBasicMap ibasicMap_0, IFeatureLayer ifeatureLayer_0,
                                                 IGeometry igeometry_0, IList <object> ilist_0)
        {
            bool           flag;
            ISpatialFilter spatialFilterClass = new SpatialFilter()
            {
                Geometry   = igeometry_0,
                SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            };
            ISpatialFilter spatialFilter = spatialFilterClass;

            try
            {
                IFeatureCursor featureCursor = ifeatureLayer_0.FeatureClass.Search(spatialFilter, false);
                for (IFeature i = featureCursor.NextFeature(); i != null; i = featureCursor.NextFeature())
                {
                    AEFeatureIdentifyObject aEFeatureIdentifyObject = new AEFeatureIdentifyObject()
                    {
                        BasicMap = ibasicMap_0,
                        Feature  = i
                    };
                    ilist_0.Add(aEFeatureIdentifyObject);
                }
                flag = true;
                return(flag);
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            flag = false;
            return(flag);
        }
Esempio n. 23
0
        public void SelectByLocayion(ComboBox C28, ComboBox C24, ComboBox C25, ComboBox C26, ComboBox C27)
        {
            IFeatureLayer IntersectedLayer = axMapControl1.ActiveView.FocusMap.get_Layer(C28.SelectedIndex) as IFeatureLayer;
            IFeatureLayer BigLayer         = axMapControl1.ActiveView.FocusMap.get_Layer(C24.SelectedIndex) as IFeatureLayer;
            IQueryFilter  MyQueryFilter    = new QueryFilter();
            string        ValueOfCond      = C27.SelectedItem.ToString();
            char          FirstChar        = ValueOfCond[0];
            int           Value1           = 48;
            int           Value2           = 57;

            if (FirstChar >= Value1 && FirstChar <= Value2)
            {
                MyQueryFilter.WhereClause = C25.SelectedItem.ToString() + C26.SelectedItem.ToString() + C27.SelectedItem.ToString();
            }
            else
            {
                MyQueryFilter.WhereClause = C25.SelectedItem.ToString() + C26.SelectedItem.ToString() + "'" + C27.SelectedItem.ToString() + "'";
            }

            IFeatureCursor    ResultOfSearch      = BigLayer.FeatureClass.Search(MyQueryFilter, true);
            IFeature          SingleFeature       = ResultOfSearch.NextFeature();
            ISpatialFilter    MySpatialFilter     = new SpatialFilter();
            IFeatureSelection MyIFeatureSelection = IntersectedLayer as IFeatureSelection;

            while (SingleFeature != null)
            {
                MySpatialFilter.Geometry   = SingleFeature.Shape;
                MySpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                MyIFeatureSelection.SelectFeatures(MySpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
                axMapControl1.Refresh();
                SingleFeature = ResultOfSearch.NextFeature();
            }
        }
        private void SetupFilters(out DecimationFilter decimate, out SpatialFilter spatial, out ThresholdFilter threshold)
        {
            // Colorizer is used to visualize depth data
            colorizer = new Colorizer();
            // Decimation filter reduces the amount of data (while preserving best samples)
            decimate = new DecimationFilter();
            decimate.Options[Option.FilterMagnitude].Value = 1.0F;//change scall

            // Define spatial filter (edge-preserving)
            spatial = new SpatialFilter();
            spatial.Options[Option.HolesFill].Value         = 1.0F; //change resolution on the edge of image
            spatial.Options[Option.FilterMagnitude].Value   = 5.0F;
            spatial.Options[Option.FilterSmoothAlpha].Value = 1.0F;
            spatial.Options[Option.FilterSmoothDelta].Value = 50.0F;



            // Aline color to depth

            //align_to = new Align(Stream.Depth);

            //try to define depth max
            threshold = new ThresholdFilter();
            threshold.Options[Option.MinDistance].Value = 0;
            threshold.Options[Option.MaxDistance].Value = 1;
        }
Esempio n. 25
0
        private IGeometry mergeSmallGeos(IGeometry geo)
        {
            ITopologicalOperator4 tp4    = (ITopologicalOperator4)geo;
            IGeometryCollection   geoCol = new PolygonClass();
            IGeometry             bGeo   = tp4.Boundary;
            ISpatialFilter        spFilt = new SpatialFilter();

            spFilt.Geometry      = bGeo;
            spFilt.SearchOrder   = esriSearchOrder.esriSearchOrderSpatial;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            spFilt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains;
            spFilt.WhereClause   = "Shape_Area <= " + minarea;
            spFilt.SubFields     = ftrCls.ShapeFieldName;
            IFeatureCursor ftrCur  = ftrCls.Search(spFilt, false);
            IFeature       ftr     = ftrCur.NextFeature();
            int            cntTest = 0;

            while (ftr != null)
            {
                IGeometry sGeo = ftr.ShapeCopy;
                geoCol.AddGeometry(sGeo);
                ftr.Delete();
                ftr = ftrCur.NextFeature();
                cntTest++;
            }
            if (cntTest > 0)
            {
                tp4.ConstructUnion((IEnumGeometry)geoCol);
            }
            return((IGeometry)tp4);
        }
Esempio n. 26
0
        private static List <IPolyline> GetIntersection(IPolyline polyline, ILayer layer)
        {
            var resultPolylines = new List <IPolyline>();

            var layerWehereDef = (layer as IFeatureLayerDefinition).DefinitionExpression;

            ISpatialFilter spatialFilter = new SpatialFilter
            {
                Geometry    = polyline,
                SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects,
                WhereClause = layerWehereDef
            };

            var featureClass = (layer as IFeatureLayer).FeatureClass;

            var highwayCursor = featureClass.Search(spatialFilter, false);

            var feature = highwayCursor.NextFeature();

            while (feature != null)
            {
                resultPolylines.AddRange(GetFeatureIntersection(feature, polyline));
                feature = highwayCursor.NextFeature();
            }

            Marshal.ReleaseComObject(highwayCursor);

            return(resultPolylines);
        }
Esempio n. 27
0
        public static string ReturnCounty(IFeatureClass SiteLayer, IFeatureClass intersectLayer, string fieldName)
        {//Returns a string saying what County and State the SiteLayer is in
            // Get the feature and its geometry given an Object ID.
            IFeature  stateFeature  = SiteLayer.GetFeature(0);
            IGeometry queryGeometry = stateFeature.Shape;

            IFeature intersectFeature = intersectLayer.GetFeature(0);

            // Create the spatial filter.
            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry      = queryGeometry;
            spatialFilter.GeometryField = intersectLayer.ShapeFieldName;
            spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
            spatialFilter.SubFields     = fieldName;

            // Find the position of the field provided the fieldName variable
            int nameFieldPosition = intersectLayer.FindField(fieldName);

            // Execute the query and iterate through the cursor's results.
            IFeatureCursor highwayCursor  = intersectLayer.Search(spatialFilter, false);
            IFeature       highwayFeature = null;

            while ((highwayFeature = highwayCursor.NextFeature()) != null)
            {
                name = Convert.ToString(highwayFeature.get_Value(nameFieldPosition));
            }

            // The cursors is no longer needed, so dispose of it.
            Marshal.ReleaseComObject(highwayCursor);

            return(name);
        }
Esempio n. 28
0
        public override int GetFeatureCount(string where, IGeometry shape)
        {
            SpatialFilter spatialFilter = new SpatialFilter(shape, where);

            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            return(_service.MapServer.QueryFeatureCount(DataFrame.Name, _mapLayerInfo.LayerID, spatialFilter));
        }
        private void SetupFilters(out DecimationFilter decimate, out SpatialFilter spatial, out TemporalFilter temp, out HoleFillingFilter holeFill, out ThresholdFilter threshold)
        {
            // Colorizer is used to visualize depth data
            colorizer = new Colorizer();
            // Decimation filter reduces the amount of data (while preserving best samples)
            decimate = new DecimationFilter();
            decimate.Options[Option.FilterMagnitude].Value = 1.0F;//change scall

            // Define spatial filter (edge-preserving)
            spatial = new SpatialFilter();
            // Enable hole-filling
            // Hole filling is an agressive heuristic and it gets the depth wrong many times
            // However, this demo is not built to handle holes
            // (the shortest-path will always prefer to "cut" through the holes since they have zero 3D distance)
            spatial.Options[Option.HolesFill].Value         = 1.0F; //change resolution on the edge of image
            spatial.Options[Option.FilterMagnitude].Value   = 5.0F;
            spatial.Options[Option.FilterSmoothAlpha].Value = 1.0F;
            spatial.Options[Option.FilterSmoothDelta].Value = 50.0F;

            // Define temporal filter
            temp = new TemporalFilter();

            // Define holefill filter
            holeFill = new HoleFillingFilter();

            // Aline color to depth

            //align_to = new Align(Stream.Depth);

            //try to define depth max
            threshold = new ThresholdFilter();
            threshold.Options[Option.MinDistance].Value = 0;
            threshold.Options[Option.MaxDistance].Value = 1;
        }
Esempio n. 30
0
        private void method_1(CHitAnalyse.Delegate1 delegate1)
        {
            CommonUtils.AppContext = this.m_app;
            this.list_0.Clear();
            this.baselineSimpleLine = this.SimplifyPolyline(this.baselineShape);
            IGeometry      geometry           = ((ITopologicalOperator)this.baselineShape).Buffer(this.double_2);
            ISpatialFilter spatialFilterClass = new SpatialFilter();

            spatialFilterClass.Geometry   = (geometry);
            spatialFilterClass.SpatialRel = (esriSpatialRelEnum)(1);
            if (this.m_listLayers.Count >= 1)
            {
                foreach (IFeatureLayer mListLayer in this.m_listLayers)
                {
                    if (!mListLayer.Visible)
                    {
                        continue;
                    }
                    IFeatureClass featureClass = mListLayer.FeatureClass;
                    if ((featureClass.AliasName == this.baselineFC.AliasName
                        ? true
                        : featureClass.ShapeType != esriGeometryType.esriGeometryPolyline))
                    {
                        continue;
                    }
                    spatialFilterClass.GeometryField = featureClass.ShapeFieldName;
                    delegate1(featureClass.Search(spatialFilterClass, false));
                }
            }
        }
Esempio n. 31
0
        private IGeoDataset GetBeforeGeo(IFeatureClass fc)
        {
            IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

            IFields fields = fc.Fields;
            int     index  = fields.FindFieldByAliasName("高程");
            IField  field  = fields.get_Field(index);

            ISpatialFilter filter = new SpatialFilter();

            filter.Geometry   = geo;
            filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

            IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();

            pFcd.Create(fc, filter, field.Name);

            //定义搜索半径
            IRasterRadius pRadius = new RasterRadiusClass();
            object        Missing = Type.Missing;

            pRadius.SetVariable(12, ref Missing);

            //设置栅格图像的单位大小
            object cellSizeProvider         = 5;
            IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;

            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);

            return(outGeoDataset);
        }
 private void getData()
 {
     IMxDocument mxDoc = ArcMap.Document;
     IMap map = mxDoc.FocusMap;
     IActiveView av = (IActiveView)map;
     esriUtil.mapserviceutility mpServ = new esriUtil.mapserviceutility();
     ISpatialFilter spFlt = new SpatialFilter();
     spFlt.Geometry = (IGeometry)av.Extent;
     spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;
     //MessageBox.Show(spFlt.Geometry.SpatialReference.Name+ "Extent Width:Height = " + spFlt.Geometry.Envelope.Width.ToString()+":"+spFlt.Geometry.Envelope.Height.ToString());
     mpServ.getDbFtrClassesThatNeedUpdating(spFlt);
 }
Esempio n. 33
0
 /// <summary>
 /// Realiza uma busca espacial retornando um cursor apenas
 /// no layer específico. A relação é "Está contido"
 /// </summary>
 /// <param name="polyBuffer">Geometria do buffer que circunda a pesquisa</param>
 /// <param name="flayer">FeatureLayer que se deseja selecionar</param>
 /// <returns>Cursor com o resultado da busca espacial</returns>
 public static IFeatureCursor BuscaEspacial(IGeometry polyBuffer, IFeatureLayer flayer)
 {
     ISpatialFilter sf = new SpatialFilter();
     sf.Geometry = polyBuffer;
     sf.GeometryField = "Shape";
     sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
     IFeatureCursor fc = null;
     try
     {
         fc = flayer.FeatureClass.Search(sf, false);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     return fc;
 }
        public List<RelatedCurve> GetTangentCurveMatchFeatures(IFeatureClass FeatureClass, IFeature inFeature, IPolycurve inPolycurve, string WhereClause,
                                                int idxRadius, int idxCenterPointID,
                                                double SegementLength, out List<RelatedLine> tangentLines)
            //double AngleToleranceTangentCompareInDegrees, double StraightLinesBreakLessThanInDegrees, 
            //double MaximumDeltaInDegrees, double ExcludeTangentsShorterThan,
            //                                     out int outFoundTangentCurvesCount, ref List<RelatedCurve> CurveInfoFromNeighbours)
        {
            List<RelatedCurve> CurveInfoFromNeighbours = new List<RelatedCurve>();
            tangentLines = new List<RelatedLine>();

            ILine pOriginalChord = (ILine)new Line();
            pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
            IVector3D vecOriginalSelected = (IVector3D)new Vector3D();
            vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

            IGeometryBag pGeomBag = (IGeometryBag)new GeometryBag();
            IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

            IGeometry MultiPartPolyLine = (IGeometry)new Polyline(); //qi
            IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
            ISpatialReference spatialRef = pGeoDS.SpatialReference;
            MultiPartPolyLine.SpatialReference = spatialRef;

            IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

            ILine inGeomTangentLineAtEnd = new Line(); //new
            ILine inGeomTangentLineAtStart = new Line(); //new
            object objMissing = Type.Missing;

            for (int i = 0; i < 2; i++)
            {
                ILine pThisLine = null;
                if (i == 0)
                {
                    //Add line tangent at end point
                    inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, CurveByInferenceSettings.Instance.TangentQueryLength, inGeomTangentLineAtEnd);
                    pThisLine = new Line();
                    pThisLine.PutCoords(inGeomTangentLineAtEnd.FromPoint, inGeomTangentLineAtEnd.ToPoint);
                    pGeomColl.AddGeometry(pThisLine);
                }
                else
                {
                    //Add line tangent at start point
                    inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, CurveByInferenceSettings.Instance.TangentQueryLength, inGeomTangentLineAtStart);
                    pThisLine = new Line();
                    pThisLine.PutCoords(inGeomTangentLineAtStart.FromPoint, inGeomTangentLineAtStart.ToPoint);
                    pGeomColl.AddGeometry(pThisLine);
                }
                //Create a new path for each line.

                ISegmentCollection newPath = (ISegmentCollection)new Path();
                newPath.AddSegment((ISegment)pThisLine, ref objMissing, ref objMissing);
                //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
                geometryCollection2.AddGeometry(newPath as IGeometry, ref objMissing, ref objMissing);
            }

            //now buffer the tangent lines
            IGeometryCollection outBufferedGeometryCol = (IGeometryCollection)new GeometryBag();
            for (int jj = 0; jj < geometryCollection2.GeometryCount; jj++)
            {
                IPath pPath = geometryCollection2.get_Geometry(jj) as IPath;
                IGeometryCollection pPolyL = (IGeometryCollection)new Polyline();
                pPolyL.AddGeometry((IGeometry)pPath);

                ITopologicalOperator topologicalOperator = (ITopologicalOperator)pPolyL;
                IPolygon pBuffer = topologicalOperator.Buffer(CurveByInferenceSettings.Instance.TangentQueryBuffer) as IPolygon;
                outBufferedGeometryCol.AddGeometry(pBuffer, ref objMissing, ref objMissing);
            }
            ITopologicalOperator pUnionedBuffers = null;
            pUnionedBuffers = new Polygon() as ITopologicalOperator;
            pUnionedBuffers.ConstructUnion((IEnumGeometry)outBufferedGeometryCol);

            ISpatialFilter pSpatFilt = new SpatialFilter();
            pSpatFilt.WhereClause = WhereClause;
            pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

            pSpatFilt.Geometry = (IGeometry)pUnionedBuffers;

            IFeatureCursor pFeatCursLines = null;
            try
            {
                pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
            }
            catch (Exception ex)
            {
                messageBox.Show(ex.Message);
                return CurveInfoFromNeighbours;
            }
            IVector3D foundGeomVector = (IVector3D)new Vector3D();
            IFeature foundFeature = null;
            bool bHasTangentStraightLineAtJunction = false;

            //A list of relative orientation values that have large breaks
            List<RelativeOrientation> lstLargeBreak = new List<RelativeOrientation>();

            while ((foundFeature = pFeatCursLines.NextFeature()) != null)
            {
                if (inFeature.OID == foundFeature.OID)
                {
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }

                IGeometry foundLineGeom = foundFeature.ShapeCopy;
                IPolyline foundPolyLine = foundLineGeom as IPolyline4;
                IPolycurve foundPolyCurve = foundLineGeom as IPolycurve;
                RelativeOrientation iRelativeOrientation = GetRelativeOrientation(foundPolyCurve, inPolycurve);
                //iRelativeOrientation == 1 --> closest points are original TO and found TO
                //iRelativeOrientation == 2 --> closest points are original TO and found FROM
                //iRelativeOrientation == 3 --> closest points are original FROM and found TO
                //iRelativeOrientation == 4 --> closest points are original FROM and found FROM

                double foundRadius = (foundFeature.get_Value(idxRadius) is DBNull) ? 0 : (double)foundFeature.get_Value(idxRadius);
                int? foundCentriodID = (foundFeature.get_Value(idxCenterPointID) is DBNull) ? null : (int?)foundFeature.get_Value(idxCenterPointID);

                //if the found feature has the same start and endpoints, assume that the feature is the same.  If that feature has radius and centerpoint information
                //assume that feature is unchanged and update the current feature with the found feature.
                if (iRelativeOrientation == RelativeOrientation.Same || iRelativeOrientation == RelativeOrientation.Reverse)
                {
                    if (foundRadius > 0 && foundCentriodID.HasValue)
                    {
                        //Curved line
                        double adjustedRadius = iRelativeOrientation == RelativeOrientation.Same ? foundRadius : -1 * foundRadius;

                        CurveInfoFromNeighbours.Clear();
                        CurveInfoFromNeighbours.Add(new RelatedCurve(foundFeature.OID, adjustedRadius, foundCentriodID.Value, iRelativeOrientation));
                        Marshal.ReleaseComObject(foundFeature);
                        Marshal.FinalReleaseComObject(pFeatCursLines);
                        return CurveInfoFromNeighbours;
                    }
                    else if (foundPolyLine.Length > inPolycurve.Length * CurveByInferenceSettings.Instance.TangentOverlapScaleFactor)
                    {
                        //straight line
                        CurveInfoFromNeighbours.Clear();

                        Marshal.ReleaseComObject(foundFeature);
                        Marshal.FinalReleaseComObject(pFeatCursLines);
                        return CurveInfoFromNeighbours;

                    }
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }

                /******************************
                 * 
                 *   Compare chord of the in geometry vs the found geometry
                 * 
                 * ****************************/


                ILine foundChord = new Line();
                foundChord.PutCoords(foundPolyCurve.FromPoint, foundPolyCurve.ToPoint);

                //Not sure about this, but it looks like this may be sensitive to the order in which the records are returned

                //first check for likelihood that subject line is supposed to stay straight, by geometry chord bearing angle break test
                //compare the in geometries chord with the found geometries chord
                foundGeomVector.PolarSet(foundChord.Angle, 0, 1);
                double chordsAngleDelta = Math.Abs(Math.Acos(foundGeomVector.DotProduct(vecOriginalSelected)) * 180 / Math.PI); //in degrees

                //large angle break non-tangent, greater than 3 degrees
                if (chordsAngleDelta > CurveByInferenceSettings.Instance.dLargeAngleBreakInDegrees && chordsAngleDelta < (180 - CurveByInferenceSettings.Instance.dLargeAngleBreakInDegrees))
                {
                    if (!lstLargeBreak.Contains(iRelativeOrientation))
                    {
                        lstLargeBreak.Add(iRelativeOrientation);

                        //check to see if there is already a related curve for the current relative orientation
                        //if(CurveInfoFromNeighbours.Any(w=>w.Orientation == iRelativeOrientation))
                        //{
                        //    bHasTangentStraightLineAtJunction = true;
                        //}
                    }

                }

                double ExcludeTangentsShorterThan = SegementLength * CurveByInferenceSettings.Instance.ExcludeTangentsShorterThanScaler;
                
                /*
                if(foundPolyCurve.Length < ExcludeTangentsShorterThan)
                {
                    //exclude short segements
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }
                else if (!foundCentriodID.HasValue && foundRadius == 0)
                {
                    //attribute straight line, check the geometry to see if it is tangent at the endpoint
                    if (chordsAngleDelta <= CurveByInferenceSettings.Instance.StraightLinesBreakLessThanInDegrees || (180 - chordsAngleDelta) < CurveByInferenceSettings.Instance.StraightLinesBreakLessThanInDegrees)
                    {
                        if (lstLargeBreak.Contains(iRelativeOrientation))
                            bHasTangentStraightLineAtJunction = true;
                    }
                }
                else if (foundCentriodID.HasValue && foundRadius != 0)
                {
                    //attribute curved line
                    if ((inPolycurve.Length / foundRadius * 180 / Math.PI) > CurveByInferenceSettings.Instance.MaximumDeltaInDegrees)
                    {
                        //if the resulting curve ('in feature' length with 'found feature' radius) would have a central angle more than MaximumDeltaInDegrees degrees then skip
                        Marshal.ReleaseComObject(foundFeature);
                        continue;
                    }
                }
                else
                {
                    //invalid state, curves should have both centriod and radius, straigh lines should have niether.
                    Marshal.ReleaseComObject(foundFeature);
                    throw new Exception(string.Format("Invalid attribute state")); 
                }
                 */

                if ((chordsAngleDelta <= CurveByInferenceSettings.Instance.StraightLinesBreakLessThanInDegrees || (180 - chordsAngleDelta) < CurveByInferenceSettings.Instance.StraightLinesBreakLessThanInDegrees)
                    && !foundCentriodID.HasValue && foundRadius == 0 && !(foundPolyCurve.Length < ExcludeTangentsShorterThan))
                {
                    if (lstLargeBreak.Contains(iRelativeOrientation))
                        bHasTangentStraightLineAtJunction = true;
                }

                if (!foundCentriodID.HasValue || foundRadius == 0 || foundPolyCurve.Length < ExcludeTangentsShorterThan)
                {
                    //staight line
                    if (foundPolyCurve.Length > ExcludeTangentsShorterThan)
                    {
                        //vecOriginalSelected

                        //ISegmentCollection collection = (ISegmentCollection)polyline;
                        //ISegment segement = collection.get_Segment(collection.SegmentCount - 1);
                        ILine line = new Line();

                        double Angle = 0.0;
                        switch (iRelativeOrientation)
                        {
                            case RelativeOrientation.To_From:
                                foundPolyLine.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1.0, line);
                                Angle = line.Angle;
                                break;
                            case RelativeOrientation.From_From:
                                foundPolyLine.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1.0, line);
                                Angle = (line.Angle > 0) ? line.Angle - Math.PI : line.Angle + Math.PI;
                                break;
                            case RelativeOrientation.To_To:
                                foundPolyLine.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1.0, line);
                                Angle = (line.Angle > 0) ? line.Angle - Math.PI : line.Angle + Math.PI;
                                break;
                            case RelativeOrientation.From_To:
                                foundPolyLine.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1.0, line);
                                Angle = line.Angle;
                                break;
                        }

                        IVector3D foundVector = new Vector3D() as IVector3D;
                        foundVector.PolarSet(Angle, 0, 1);
                        double dVectDiff = Math.Acos(vecOriginalSelected.DotProduct(foundVector));

                        //Console.WriteLine("Add Straight Line: {0}, {1} -> {2}", foundFeature.OID, line.Angle, ((ILine)segement).Angle);
                        tangentLines.Add(new RelatedLine(foundFeature.OID, toDegrees(Angle), toDegrees(dVectDiff), iRelativeOrientation));
                    }
                    //if the feature has a null centrpointID then skip.
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }

                if (Math.Abs(inPolycurve.Length / foundRadius * 180 / Math.PI) > CurveByInferenceSettings.Instance.MaximumDeltaInDegrees)
                {
                    //if the resulting curve ('in feature' length with 'found feature' radius) would have a central angle more than MaximumDeltaInDegrees degrees then skip
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }

                /******************************
                 * 
                 *   Compare two lines, one from each in geometry and found geometry taken at the closes ends of the lines
                 *   Ie, compare the slopes of the two lines where they touch (or at least where they closest).
                 * 
                 * ****************************/

                //if geometry of curve neighbor curves have been cracked then there can be more than one segment
                //however since all segments would be circular arcs, just need to test the first segment
                ISegmentCollection pFoundLineGeomSegs = foundLineGeom as ISegmentCollection;
                ISegment pSeg = pFoundLineGeomSegs.get_Segment(0);
                if (!(pSeg is ICircularArc))
                {
                    Marshal.ReleaseComObject(foundFeature);
                    continue;
                }

                IVector3D vect1 = (IVector3D)new Vector3D();
                IVector3D vect2 = (IVector3D)new Vector3D();
                ILine tang = new Line();
                double dUnitSignChange = 1;
                if (iRelativeOrientation == RelativeOrientation.To_To) //closest points are original TO and found TO
                {
                    dUnitSignChange = -1;
                    vect1.PolarSet(inGeomTangentLineAtEnd.Angle, 0, 1);
                    foundPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
                    vect2.PolarSet(tang.Angle, 0, 1);
                }
                else if (iRelativeOrientation == RelativeOrientation.To_From)//closest points are original TO and found FROM
                {
                    vect1.PolarSet(inGeomTangentLineAtEnd.Angle, 0, 1);
                    foundPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
                    vect2.PolarSet(tang.Angle, 0, 1);
                }
                else if (iRelativeOrientation == RelativeOrientation.From_To)//closest points are original FROM and found TO
                {
                    vect1.PolarSet(inGeomTangentLineAtStart.Angle, 0, 1);
                    foundPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
                    vect2.PolarSet(tang.Angle, 0, 1);
                }
                else if (iRelativeOrientation == RelativeOrientation.From_From)//closest points are original FROM and found FROM
                {
                    dUnitSignChange = -1;
                    vect1.PolarSet(inGeomTangentLineAtStart.Angle, 0, 1);
                    foundPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
                    vect2.PolarSet(tang.Angle, 0, 1);
                }

                double tangentAngleDelta = Math.Abs(Math.Acos(vect1.DotProduct(vect2)) * 180 / Math.PI); //in degrees
                if (tangentAngleDelta < CurveByInferenceSettings.Instance.AngleToleranceTangentCompareInDegrees || (180 - tangentAngleDelta) < CurveByInferenceSettings.Instance.AngleToleranceTangentCompareInDegrees)
                {

                    double inferredRadius = foundRadius * dUnitSignChange;
                    CurveInfoFromNeighbours.Add(new RelatedCurve(foundFeature.OID, inferredRadius, foundCentriodID.Value, iRelativeOrientation));
                }
                Marshal.ReleaseComObject(foundFeature);
            }
            Marshal.FinalReleaseComObject(pFeatCursLines);

            if (bHasTangentStraightLineAtJunction)
                CurveInfoFromNeighbours.Clear(); //open to logic change to be less conservative

            //Original source didn't clear the list before, returing all the found records by reference.
            //calling procedure didn't do anything with those features though, only consumed the features if true was returned

            return CurveInfoFromNeighbours;
        }
        List<RelatedCurve> GetParallelCurveMatchFeatures(IFeatureClass FeatureClass, IFeature inFeature, IPolycurve inPolycurve, string WhereClause)
            //double AngleToleranceTangentCompareInDegrees, double OrthogonalSearchDistance,
            //                                        out int outFoundLinesCount, out int outFoundParallelCurvesCount, ref List<RelatedCurve> CurveInfoFromNeighbours)
        {
            List<RelatedCurve> CurveInfoFromNeighbours = new List<RelatedCurve>();

            ILine inGeomChord = (ILine)new Line();
            inGeomChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
            IVector3D inGeomVector = (IVector3D)new Vector3D();
            inGeomVector.PolarSet(inGeomChord.Angle, 0, 1);

            //generate line segments that are perpendicular to the in feature at half way

            IGeometryBag queryGeomBag = (IGeometryBag)new GeometryBag();
            IGeometryCollection queryGeomPartCollection = (IGeometryCollection)queryGeomBag;

            IGeometry queryMultiPartPolyLine = (IGeometry)new Polyline(); //qi
            IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
            ISpatialReference spatialRef = pGeoDS.SpatialReference;
            queryMultiPartPolyLine.SpatialReference = spatialRef;

            IGeometryCollection queryGeomCollection = queryMultiPartPolyLine as IGeometryCollection;

            ILine pNormalLine = (ILine)new Line(); //new
            for (int i = -1; i < 2; i = i + 2)
            {
                double dOffset = CurveByInferenceSettings.Instance.OrthogonalSearchDistance * i;

                inPolycurve.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, dOffset, pNormalLine);
                ILine pThisLine = (ILine)new Line();

                pThisLine.PutCoords(pNormalLine.FromPoint, pNormalLine.ToPoint);
                queryGeomPartCollection.AddGeometry(pThisLine);

                //Although each line is connected to the other, create a new path for each line 
                //this allows for future changes in case the input needs to be altered to separate paths.

                ISegmentCollection newPath = (ISegmentCollection)new Path();
                object obj = Type.Missing;
                newPath.AddSegment((ISegment)pThisLine, ref obj, ref obj);
                //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
                queryGeomCollection.AddGeometry(newPath as IGeometry, ref obj, ref obj);
            }

            //search for records that intersect these perpendicular geometries
            IQueryFilter filter = new SpatialFilter();
            filter.SubFields = String.Format("{0}, {1}, {2}, {3}", FeatureClass.OIDFieldName, CurveByInferenceSettings.Instance.RadiusFieldName, CurveByInferenceSettings.Instance.CenterpointIDFieldName, FeatureClass.ShapeFieldName);
            ISpatialFilter spatialFilter = (ISpatialFilter)filter;
            
            //Can't add any additional filtering on centerpointid and radius field because the straight lines are needed
            spatialFilter.WhereClause = WhereClause;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            spatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

            spatialFilter.Geometry = queryGeomBag;

            IFeatureCursor pFeatCursLines = null;
            try
            {
                pFeatCursLines = FeatureClass.Search(spatialFilter, false);
            }
            catch (Exception ex)
            {
                messageBox.Show(ex.Message);
                return CurveInfoFromNeighbours;
            }

            int idxCenterPointID = pFeatCursLines.Fields.FindField(CurveByInferenceSettings.Instance.CenterpointIDFieldName);
            int idxRadius = pFeatCursLines.Fields.FindField(CurveByInferenceSettings.Instance.RadiusFieldName);

            IPoint midpoint = new Point();
            inPolycurve.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, midpoint);
            double lengthFiler = inPolycurve.Length * 3;
            double closestStraighLine = Double.MaxValue;
            IFeature pFeat = null;
            while ((pFeat = pFeatCursLines.NextFeature()) != null)
            {
                if (inFeature.OID == pFeat.OID)
                    continue;

                IGeometry pFoundLineGeom = pFeat.ShapeCopy;
                IPolyline pFoundPolyline = pFoundLineGeom as IPolyline;

                ITopologicalOperator6 pTopoOp6 = (ITopologicalOperator6)queryMultiPartPolyLine;
                IGeometry intersectionPoint = pTopoOp6.IntersectEx(pFoundLineGeom, false, esriGeometryDimension.esriGeometry0Dimension);
                if (intersectionPoint == null || intersectionPoint.IsEmpty)
                {
                    // there isn't actually an intersection between the features
                    Marshal.ReleaseComObject(pFeat);
                    continue;
                }

                //distance from intersection of tangent line and found feature to the start point of the tangent line
                 
                double distanceToLine = ((IProximityOperator)intersectionPoint).ReturnDistance(midpoint);

                //if the feature has no radius attribute, skip.
                double dRadius = pFeat.get_Value(idxRadius) is DBNull ? 0 : (double)pFeat.get_Value(idxRadius);
                int? centerpointID = pFeat.get_Value(idxCenterPointID) is DBNull ? null : (int?)pFeat.get_Value(idxCenterPointID);
                if (dRadius == 0 || centerpointID == null)
                {//null centrpointID so skip.
                    if (closestStraighLine > distanceToLine && pFoundPolyline.Length > lengthFiler)
                    {
                        closestStraighLine = distanceToLine;
                        CurveInfoFromNeighbours.RemoveAll(w=>w.DistanceToLine > closestStraighLine);
                    }
                    Marshal.ReleaseComObject(pFeat);
                    continue;
                }

                //out past a straight line
                if (closestStraighLine < distanceToLine)
                    continue;

                ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
                bool bHasCurves = false;
                pFoundLineGeomSegs.HasNonLinearSegments(ref bHasCurves);
                if (!bHasCurves)
                {
                    Marshal.ReleaseComObject(pFeat);
                    continue;
                }

                IPointCollection5 PtColl = (IPointCollection5)intersectionPoint;
                if (PtColl.PointCount > 1)
                {
                    // the intersection isn't a point
                    Marshal.ReleaseComObject(pFeat);
                    continue;
                }
                IPolycurve pPolyCurve4Tangent = pFoundLineGeom as IPolycurve;

                for (int j = 0; j < PtColl.PointCount; j++)
                {
                    IPoint p = PtColl.get_Point(j);
                    IPoint outPoint = (IPoint)new Point();
                    double dDistanceAlong = 0;
                    double dDistanceFromCurve = 0;
                    bool bOffsetRight = true;

                    //work out if the point is to the left or right of the original 
                    inPolycurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
                      ref dDistanceAlong, ref dDistanceFromCurve, ref bOffsetRight);

                    ILine pTangent = (ILine)new Line();
                    dDistanceAlong = 0;
                    dDistanceFromCurve = 0;
                    bool bOnRight = true;

                    pPolyCurve4Tangent.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
                      ref dDistanceAlong, ref dDistanceFromCurve, ref bOnRight);
                    pPolyCurve4Tangent.QueryTangent(esriSegmentExtension.esriNoExtension, dDistanceAlong, false, 100, pTangent);

                    //compare the tangent bearing with the normal to check for orthogonality
                    IVector3D vecTangent = (IVector3D)new Vector3D();
                    vecTangent.PolarSet(pTangent.Angle, 0, 1);

                    IVector3D vecNormal = (IVector3D)new Vector3D();
                    vecNormal.PolarSet(pNormalLine.Angle, 0, 1);

                    ILine pHitDistanceForRadiusDifference = (ILine)new Line();
                    pHitDistanceForRadiusDifference.PutCoords(pNormalLine.FromPoint, outPoint);
                    double dRadiusDiff = pHitDistanceForRadiusDifference.Length;

                    double dDotProd = vecTangent.DotProduct(vecNormal);
                    double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
                    dAngleCheck = Math.Abs(dAngleCheck - 90);

                    if (dAngleCheck < CurveByInferenceSettings.Instance.AngleToleranceTangentCompareInDegrees)
                    {
                        //work out concavity orientation with respect to the original line using the radius sign and dot product
                        dDotProd = inGeomVector.DotProduct(vecTangent);
                        double dTangentCheck = Math.Acos(dDotProd) * 180 / Math.PI; // in degrees
                        //dTangentCheck at this point should be close to 0 or 180 degrees.
                        
                        bool bIsConvex = ((dTangentCheck < 90 && dRadius < 0 && !bOffsetRight) ||
                                          (dTangentCheck > 90 && dRadius > 0 && !bOffsetRight) ||
                                          (dTangentCheck < 90 && dRadius > 0 && bOffsetRight) ||
                                          (dTangentCheck > 90 && dRadius < 0 && bOffsetRight));

                        double dUnitSignChange = 1;

                        if (!bIsConvex)
                            dUnitSignChange = -1;

                        double dDerivedRadius = (Math.Abs(dRadius)) + dRadiusDiff * dUnitSignChange;

                        dUnitSignChange = 1;
                        //now compute inferred left/right for candidate
                        if (bIsConvex && !bOffsetRight)
                            dUnitSignChange = -1;

                        if (!bIsConvex && bOffsetRight)
                            dUnitSignChange = -1;

                        dDerivedRadius = dDerivedRadius * dUnitSignChange;

                        //string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," + centerpointID.ToString() + "," + dRadiusDiff.ToString("#.000");
                        CurveInfoFromNeighbours.Add(new RelatedCurve(pFeat.OID, dDerivedRadius, centerpointID.Value, distanceToLine, RelativeOrientation.Parallel));
                    }
                }

                Marshal.ReleaseComObject(pFeat);
            }
            Marshal.FinalReleaseComObject(pFeatCursLines);

            return CurveInfoFromNeighbours;
        }
Esempio n. 36
0
File: Home.cs Progetto: gistop/aegis
        private void ClickSelectFeature(ref IMap m_pMap, int x, int y)
        {
            // get the layer
            IFeatureLayer pFeatureLayer = m_pMap.get_Layer(0) as IFeatureLayer;
            if (pFeatureLayer == null) return;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;//get the feature
            if (pFeatureClass == null) return;
            //get mouse position
            IActiveView pActiveView = m_pMap as IActiveView;
            IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            //Use a 4 pixel buffer around the cursor for feature search
            double length;
            length = ConvertPixelsToMapUnits(pActiveView, 4);
            ITopologicalOperator pTopo = pPoint as ITopologicalOperator;
            IGeometry pBuffer = pTopo.Buffer(length);//建立4个地图单位的缓冲区
            IGeometry pGeometry = pBuffer.Envelope;//确定鼠标周围隐藏的选择框

            //新建一个空间约束器
            ISpatialFilter pSpatialFilter;
            IQueryFilter pFilter;
            //设置查询约束条件
            pSpatialFilter = new SpatialFilter();
            pSpatialFilter.Geometry = pGeometry;

            switch (pFeatureClass.ShapeType)
            {
                case esriGeometryType.esriGeometryPoint:
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                    break;
                case esriGeometryType.esriGeometryPolyline:
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                    break;
                case esriGeometryType.esriGeometryPolygon:
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    break;
                default:
                    break;
            }
            pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
            pFilter = pSpatialFilter;
            //Do the Search 从图层中查询出满足约束条件的元素
            IFeatureCursor pCursor = pFeatureLayer.Search(pFilter, false);

            //select
            IFeature pFeature = pCursor.NextFeature();
            m_pMap.SelectFeature(pFeatureLayer, pFeature);
            while (pFeature != null)
            {
                m_pMap.SelectFeature(pFeatureLayer, pFeature);
                pFeature = pCursor.NextFeature();
            }

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
        }
        //Start the logic for finding the cross streets.
        public string FindStreets(IPoint point, IFeatureClass featureClass, int StreetField, string StreetName, string join)
        {
            ISpatialFilter pSFilter = new SpatialFilter();
            IFeatureCursor pFCursor;
            IFeature pFeature = default(IFeature);
            Collection<string> cValues = new Collection<string>();
            string sValue = null;
            string sResult = null;
            bool bFound = false;

            pSFilter.GeometryField = featureClass.ShapeFieldName;
            pSFilter.Geometry = point;
            pSFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            pFCursor = featureClass.Search(pSFilter, false);
            pFeature = pFCursor.NextFeature();
            do
            {

                sValue = (string)pFeature.Value[StreetField];
                if (sValue != StreetName)
                {
                    bFound = false;
                    for(int i = 0; i <cValues.Count; i++)
                    {
                        if (sValue == cValues[i])
                        {
                            bFound = true;
                            break;
                        }
                    }


                    if (!bFound)
                    {
                        cValues.Add(sValue);
                        if (cValues.Count == 1)
                        {
                            sResult = sValue;
                        }
                        else
                        {
                            sResult = sResult + sJoin + sValue;
                        }
                    }
                }
                pFeature = pFCursor.NextFeature();

            } while (!(pFeature == null));

            return sResult;
        }
Esempio n. 38
0
 /// <summary>
 /// Gats the map spatial query data.
 /// </summary>
 /// <param name="mapServer">The map server.</param>
 /// <param name="inputGeometry">The input geometry.</param>
 /// <param name="layerName">Name of the layer.</param>
 /// <param name="maxRecords">The max records.</param>
 /// <param name="returnGeometry">if set to <c>true</c> [return geometry].</param>
 /// <param name="assetType">Type of the asset.</param>
 /// <returns></returns>
 private MapCustomDataTable GatMapSpatialQueryData(MapServerProxy mapServer, 
 ESRI.ArcGIS.ADF.Web.Geometry.Geometry inputGeometry,
 string layerName, int maxRecords, bool returnGeometry, string assetType)
 {
     #region "Local Variables"
     DataTable objDataTable = null;
     MapCustomDataTable objCustomDataTable = null;
     int intLayerID = -1;
     SpatialFilter objSpatailFil;
     MapProcessManager objMapController = null;
     ESRI.ArcGIS.ADF.StringCollection objStrColl = null;
     string strFields = string.Empty;
     ESRI.ArcGIS.ADF.ArcGISServer.RecordSet objRS = null;
     #endregion
     try
     {
         if (!string.IsNullOrEmpty(layerName))
         {
             intLayerID = GetLayerID(mapServer, layerName);
             if (intLayerID != -1)
             {
                 objMapController = new MapProcessManager();
                 objStrColl = new ESRI.ArcGIS.ADF.StringCollection();
                 //creating spatial filter
                 objSpatailFil = new SpatialFilter();
                 //setting geometry to spatial filter
                 objSpatailFil.FilterGeometry = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfGeometry(inputGeometry);
                 objSpatailFil.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                 objStrColl = objMapController.GetSubFields(layerName);
                 foreach (string strColumnName in objStrColl)
                 {
                     if (!string.IsNullOrEmpty(strFields))
                         strFields = strFields + "," + strColumnName;
                     else
                         strFields = strColumnName;
                 }
                 if (objStrColl != null && objStrColl.Count > 0) objSpatailFil.SubFields = strFields;
                 //obtaining queried data table
                 objRS = mapServer.QueryFeatureData(mapServer.GetMapName(0), intLayerID, objSpatailFil);
                 objDataTable = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToDataTable(objRS);
                 //formatting data table
                 if (objDataTable != null && objDataTable.Rows.Count > 0 && returnGeometry == false)
                 {
                     objCustomDataTable = FormatDataTable(objDataTable, layerName,
                          maxRecords, assetType);
                 }
             }
         }
     }
     catch
     {
         throw;
     }
     finally
     {
         if (objDataTable != null) objDataTable.Dispose();
         if (objCustomDataTable != null) objCustomDataTable.Dispose();
     }
     return objCustomDataTable;
 }
Esempio n. 39
0
        private IFeatureCursor GetFeatureCursor(IGeometry pGeometry, IFeatureClass pFeatureClass)
        {
            //空间过虑器的创建
            ISpatialFilter pSpatialFilter = new SpatialFilter();
            pSpatialFilter.Geometry = pGeometry;
            //空间过虑器几何体实体
            //空间过虑器参照系

            //空间过虑器空间数据字段名
            pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
            //空间过虑器空间关系类型
            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            //相交
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);

            return pFeatureCursor;
        }
        private void OnSketchFinished()
        {
            //Use the geometry from the sketch and make a narrow buffer to search for fabric lines contained within the buffer
              IBufferConstruction pBuffConst = new BufferConstruction();
              IGeometry pGeom = pBuffConst.Buffer(m_edSketch.Geometry, 0.1);
              ISpatialFilter pSpatFilter = new SpatialFilter();
              pSpatFilter.Geometry = pGeom;
              pSpatFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

              //set up for reporting information about the lines
              string sReportString = "";
              int iTotalLineCount = 0;
              int iCurveCount = 0;
              int iMultiSegmentCount = 0;

              //Create a feature cursor to query the fabric lines table
              IFeatureCursor pFeatCurs = m_pFabricLines.Search(pSpatFilter, false);
              IFeature pFeat = pFeatCurs.NextFeature();

              while (pFeat != null)
              {
            //loop through the found lines
            //count all the lines
            iTotalLineCount++;
            ISegmentCollection pSegColl = (ISegmentCollection)pFeat.Shape;
            if (pSegColl.SegmentCount > 1) //count lines that have more than 1 segment
              iMultiSegmentCount++;
            else
            {
              if (pSegColl.get_Segment(0) is ICircularArc)
            iCurveCount++; //count lines that have a single circular arc geometry segment
            }
            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCurs.NextFeature();
              }
              Marshal.ReleaseComObject(pFeatCurs);

              //report the results
              sReportString += "\nTotal parcel lines: " + iTotalLineCount.ToString();
              sReportString += "\nCurve parcel lines: " + iCurveCount.ToString();
              sReportString += "\nMulti segment parcel lines: " + iMultiSegmentCount.ToString();

              MessageBox.Show(sReportString, "Sample: Trace Report");
        }
Esempio n. 41
0
 /// <summary>
 /// Realiza uma busca espacial retornando um cursor apenas
 /// no layer específico. A relação é "Está contido"
 /// </summary>
 /// <param name="polyBuffer">Geometria do buffer que circunda a pesquisa</param>
 /// <param name="flayer">Feature Class que se deseja selecionar</param>
 /// <param name="spatialEnum">Relação espacial de consulta</param>
 /// <param name="whereClause">Condition beyond the spatial filter</param>
 /// <returns>Cursor com o resultado da busca espacial</returns>
 public static IFeatureCursor BuscaEspacial(IGeometry polyBuffer,
                                         IFeatureLayer flayer,
                                         esriSpatialRelEnum spatialEnum)
 {
     ISpatialFilter sf = new SpatialFilter();
     sf.Geometry = polyBuffer;
     sf.GeometryField = "Shape";
     sf.SpatialRel = spatialEnum;
     IFeatureCursor fc = null;
     //sf.WhereClause = (flayer as IFeatureLayerDefinition).DefinitionExpression;
     try
     {
         fc = flayer.FeatureClass.Search(sf, false);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     return fc;
 }
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {

            try
            {
                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass() as IGPUtilities3;

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

                // decode in the input layers
                IGPParameter in_SourceFeatureClassParameter = paramvalues.get_Element(in_sourceFeatureClassNumber) as IGPParameter;
                IGPValue in_SourceFeatureGPValue = gpUtilities3.UnpackGPValue(in_SourceFeatureClassParameter) as IGPValue;

                IFeatureClass sourceFeatureClass = null;
                IQueryFilter queryFilter = null;

                gpUtilities3.DecodeFeatureLayer((IGPValue)in_SourceFeatureGPValue, out sourceFeatureClass, out queryFilter);

                if (sourceFeatureClass == null)
                {
                    message.AddError(120027, resourceManager.GetString("GPTools_OSMGPFeatureComparison_source_nullpointer"));
                    return;
                }

                IGPParameter in_NumberOfIntersectionsFieldParameter = paramvalues.get_Element(in_sourceIntersectionFieldNumber) as IGPParameter;
                IGPValue in_NumberOfIntersectionsFieldGPValue = gpUtilities3.UnpackGPValue(in_NumberOfIntersectionsFieldParameter) as IGPValue;

                IGPParameter in_SourceRefIDFieldParameter = paramvalues.get_Element(in_sourceRefIDsFieldNumber) as IGPParameter;
                IGPValue in_SourceRefIDFieldGPValue = gpUtilities3.UnpackGPValue(in_SourceRefIDFieldParameter) as IGPValue;

                IGPParameter in_MatchFeatureClassParameter = paramvalues.get_Element(in_MatchFeatureClassNumber) as IGPParameter;
                IGPValue in_MatchFeatureGPValue = gpUtilities3.UnpackGPValue(in_MatchFeatureClassParameter) as IGPValue;

                IFeatureClass matchFeatureClass = null;
                IQueryFilter matchQueryFilter = null;

                gpUtilities3.DecodeFeatureLayer((IGPValue)in_MatchFeatureGPValue, out matchFeatureClass, out matchQueryFilter);


                if (matchFeatureClass == null)
                {
                    message.AddError(120028, resourceManager.GetString("GPTools_OSMGPFeatureComparison_match_nullpointer"));
                    return;
                }

                if (queryFilter != null)
                {
                    if (((IGeoDataset)matchFeatureClass).SpatialReference != null)
                    {
                        queryFilter.set_OutputSpatialReference(sourceFeatureClass.ShapeFieldName, ((IGeoDataset)matchFeatureClass).SpatialReference);
                    }
                }


                IWorkspace sourceWorkspace = ((IDataset) sourceFeatureClass).Workspace;
                IWorkspaceEdit sourceWorkspaceEdit = sourceWorkspace as IWorkspaceEdit;

                if (sourceWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    sourceWorkspaceEdit = sourceWorkspace as IWorkspaceEdit;
                    sourceWorkspaceEdit.StartEditing(false);
                    sourceWorkspaceEdit.StartEditOperation();
                }

                // get an overall feature count as that determines the progress indicator
                int featureCount = ((ITable)sourceFeatureClass).RowCount(queryFilter);

                // set up the progress indicator
                IStepProgressor stepProgressor = TrackCancel as IStepProgressor;

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

                int numberOfIntersectionsFieldIndex = sourceFeatureClass.FindField(in_NumberOfIntersectionsFieldGPValue.GetAsText());
                int sourceRefIDFieldIndex = sourceFeatureClass.FindField(in_SourceRefIDFieldGPValue.GetAsText());

                ISpatialFilter matchFCSpatialFilter = new SpatialFilter();
                matchFCSpatialFilter.GeometryField = matchFeatureClass.ShapeFieldName;
                matchFCSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                matchFCSpatialFilter.WhereClause = matchQueryFilter.WhereClause;

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    IFeatureCursor sourceFeatureCursor = sourceFeatureClass.Search(queryFilter, false);
                    comReleaser.ManageLifetime(sourceFeatureCursor);

                    IFeature sourceFeature = null;

                    while ((sourceFeature = sourceFeatureCursor.NextFeature()) != null)
                    {
                        int numberOfIntersections = 0;
                        string intersectedFeatures = String.Empty;

                        IPolyline sourceLine = sourceFeature.Shape as IPolyline;

                        matchFCSpatialFilter.Geometry = sourceLine;

                        using (ComReleaser innerReleaser = new ComReleaser())
                        {
                            IFeatureCursor matchFeatureCursor = matchFeatureClass.Search(matchFCSpatialFilter, false);
                            innerReleaser.ManageLifetime(matchFeatureCursor);

                            IFeature matchFeature = null;

                            while ((matchFeature = matchFeatureCursor.NextFeature()) != null)
                            {
                                IPointCollection intersectionPointCollection = null;
                                try
                                {
                                    ITopologicalOperator topoOperator = sourceLine as ITopologicalOperator;

                                    if (topoOperator.IsSimple == false)
                                    {
                                        ((ITopologicalOperator2)topoOperator).IsKnownSimple_2 = false;
                                        topoOperator.Simplify();
                                    }

                                    IPolyline matchPolyline = matchFeature.Shape as IPolyline;

                                    if (queryFilter != null)
                                    {
                                        matchPolyline.Project(sourceLine.SpatialReference);
                                    }

                                    if (((ITopologicalOperator)matchPolyline).IsSimple == false)
                                    {
                                        ((ITopologicalOperator2)matchPolyline).IsKnownSimple_2 = false;
                                        ((ITopologicalOperator)matchPolyline).Simplify();
                                    }

                                    intersectionPointCollection = topoOperator.Intersect(matchPolyline, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection;
                                }
                                catch (Exception ex)
                                {
                                    message.AddWarning(ex.Message);
                                    continue;
                                }

                                if (intersectionPointCollection != null && intersectionPointCollection.PointCount > 0)
                                {
                                    numberOfIntersections = numberOfIntersections + intersectionPointCollection.PointCount;

                                    if (String.IsNullOrEmpty(intersectedFeatures))
                                    {
                                        intersectedFeatures = matchFeature.OID.ToString();
                                    }
                                    else
                                    {
                                        intersectedFeatures = intersectedFeatures + "," + matchFeature.OID.ToString();
                                    }
                                }
                            }

                            if (numberOfIntersectionsFieldIndex > -1)
                            {
                                sourceFeature.set_Value(numberOfIntersectionsFieldIndex, numberOfIntersections);
                            }

                            if (sourceRefIDFieldIndex > -1)
                            {
                                if (intersectedFeatures.Length > sourceFeatureClass.Fields.get_Field(sourceRefIDFieldIndex).Length)
                                {
                                    sourceFeature.set_Value(sourceRefIDFieldIndex, intersectedFeatures.Substring(0, sourceFeatureClass.Fields.get_Field(sourceRefIDFieldIndex).Length));
                                }
                                else
                                {
                                    sourceFeature.set_Value(sourceRefIDFieldIndex, intersectedFeatures);
                                }
                            }
                        }

                        try
                        {
                            sourceFeature.Store();
                        }
                        catch (Exception ex)
                        {
                            message.AddWarning(ex.Message);
                        }

                        if (stepProgressor != null)
                        {
                            // update the progress UI
                            stepProgressor.Step();
                        }

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

                    }
                }

                if (sourceWorkspaceEdit != null)
                {
                    sourceWorkspaceEdit.StopEditOperation();
                    sourceWorkspaceEdit.StopEditing(true);
                }

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

            }
            catch (Exception ex)
            {
                message.AddAbort(ex.Message);
            }

        }
 /// <summary>
 /// 查询分段巷道覆盖的线的序号
 /// </summary>
 /// <params name="geom"></params>
 /// <params name="sql"></params>
 /// <params name="featurelyr"></params>
 /// <params name="hdwid"></params>
 /// <returns></returns>
 public int[] GetCenterLineXHNew(IGeometry geom, string sql, IFeatureLayer featurelyr, double hdwid)
 {
     IFeature feature = null;
     IFeatureClass featureclass = featurelyr.FeatureClass;
     IFeatureCursor feacursor = null;
     if (featureclass != null)
     {
         //获得与面相交的巷道分段中心线
         ISpatialFilter filter = new SpatialFilter();
         filter.Geometry = geom;
         filter.WhereClause = sql;
         filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
         feacursor = featureclass.Search(filter, false);
         IFeature newfea = feacursor.NextFeature();
         IFeature afea = null;
         List<IFeature> listfea = new List<IFeature>();
         while (newfea != null)
         {
             listfea.Add(newfea);
             newfea = feacursor.NextFeature();
         }
         //if (listfea.Count > 1)
         //{   //对中心线做buffer,取buffer与巷道面交集大的为当前巷道下的中心线
         //    for (int i = 0; i < listfea.Count - 1; i++)
         //    {
         //        newfea = listfea[i];
         //        IPolyline polyline = newfea.ShapeCopy as IPolyline;
         //        double interarea = GetIntersectGeoArea(geom, polyline, hdwid);
         //        afea = listfea[i + 1];
         //        IPolyline apolyline = afea.ShapeCopy as IPolyline;
         //        double ainterarea = GetIntersectGeoArea(geom, apolyline, hdwid);
         //        if (ainterarea > interarea)
         //        { feature = afea; }
         //        else
         //        { feature = newfea; }
         //    }
         //}
         //else
         //{ feature = listfea[0]; }
         feature = listfea[0];
     }
     int m = feature.Fields.FindField(GIS_Const.FIELD_XH);
     int xh = Convert.ToInt16(feature.get_Value(m).ToString());
     m = feature.Fields.FindField(GIS_Const.FIELD_ID);
     int id = Convert.ToInt16(feature.get_Value(m).ToString());
     int[] result = new int[2] { xh, id };
     return result;
 }
 private void selectfeature(int x, int y)
 {
     IMap imap = axMapControl1.Map;
     imap.ClearSelection();
     int errorflag = 0;
     sightbutton.Checked = false; trainstationbutton.Checked = false; supermarketbutton.Checked = false; bankbutton.Checked = false;
     governmentbutton.Checked = false; hospitalbutton.Checked = false; secondroadbutton.Checked = false; waterregionbutton.Checked = false;
     railwaybutton.Checked = false; recreationbutton.Checked = false; hotelbutton.Checked = false; sightbutton.Checked = false;
     mainroadbutton.Checked = false; busstationbutton.Checked = false;
     IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
     mapLayers.DeleteLayer(trainstationlayer); mapLayers.DeleteLayer(mainroadlayer); mapLayers.DeleteLayer(secondroadlayer);
     mapLayers.DeleteLayer(busstationlayer); mapLayers.DeleteLayer(waterregionlayer); mapLayers.DeleteLayer(railwaylayer);
     mapLayers.DeleteLayer(supermarketlayer); mapLayers.DeleteLayer(banklayer); mapLayers.DeleteLayer(governmentlayer);
     mapLayers.DeleteLayer(hospitallayer); mapLayers.DeleteLayer(recreationlayer); mapLayers.DeleteLayer(hotellayer);
     mapLayers.DeleteLayer(sightlayer); mapLayers.DeleteLayer(addresslayer);
     IActiveView pActiveView = imap as IActiveView;
     IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
     //Use a 4 pixel buffer around the cursor for feature search
     double length;
     length = ConvertPixelsToMapUnits(pActiveView, 4);
     ITopologicalOperator pTopo = pPoint as ITopologicalOperator;
     IGeometry pBuffer = pTopo.Buffer(length);//建立4个地图单位的缓冲区
     IGeometry pGeometry = pBuffer.Envelope;//确定鼠标周围隐藏的选择框
     //新建一个空间约束器
     ISpatialFilter pSpatialFilter;
     IQueryFilter pFilter;
     //设置查询约束条件
     pSpatialFilter = new SpatialFilter();
     pSpatialFilter.Geometry = pGeometry;
     try
     {
         IFeatureLayer pFeatureLayer = mainroadlayer as IFeatureLayer;
         IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
         switch (pFeatureClass.ShapeType)
         {
             case esriGeometryType.esriGeometryPoint:
                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                 break;
             case esriGeometryType.esriGeometryPolyline:
                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                 break;
             case esriGeometryType.esriGeometryPolygon:
                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                 break;
             default:
                 break;
         }
         pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
         pFilter = pSpatialFilter;
         //Do the Search 从图层中查询出满足约束条件的元素
         IFeatureCursor pCursor = mainroadlayer.Search(pFilter, false);
         //select
         IFeature ifeature = pCursor.NextFeature();
         if (ifeature == null) throw new Exception();
         while (ifeature != null)
         {
             imap.SelectFeature(pFeatureLayer, ifeature);
             ifeature = pCursor.NextFeature();
         }
         axMapControl1.AddLayer(mainroadlayer);
         this.mainroadbutton.Checked = true;
         imap.SelectFeature(mainroadlayer, ifeature);
     }
     catch (Exception)
     {
         errorflag++;
         try
         {
             IFeatureLayer pFeatureLayer = waterregionlayer as IFeatureLayer;
             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
             switch (pFeatureClass.ShapeType)
             {
                 case esriGeometryType.esriGeometryPoint:
                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                     break;
                 case esriGeometryType.esriGeometryPolyline:
                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                     break;
                 case esriGeometryType.esriGeometryPolygon:
                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                     break;
                 default:
                     break;
             }
             pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
             pFilter = pSpatialFilter;
             //Do the Search 从图层中查询出满足约束条件的元素
             IFeatureCursor pCursor = waterregionlayer.Search(pFilter, false);
             //select
             IFeature ifeature = pCursor.NextFeature();
             if (ifeature == null) throw new Exception();
             while (ifeature != null)
             {
                 imap.SelectFeature(pFeatureLayer, ifeature);
                 ifeature = pCursor.NextFeature();
             }
             axMapControl1.AddLayer(waterregionlayer);
             this.waterregionbutton.Checked = true;
             imap.SelectFeature(waterregionlayer, ifeature);
         }
         catch (Exception)
         {
             errorflag++;
             try
             {
                 IFeatureLayer pFeatureLayer = secondroadlayer as IFeatureLayer;
                 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                 switch (pFeatureClass.ShapeType)
                 {
                     case esriGeometryType.esriGeometryPoint:
                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                         break;
                     case esriGeometryType.esriGeometryPolyline:
                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                         break;
                     case esriGeometryType.esriGeometryPolygon:
                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                         break;
                     default:
                         break;
                 }
                 pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                 pFilter = pSpatialFilter;
                 //Do the Search 从图层中查询出满足约束条件的元素
                 IFeatureCursor pCursor = secondroadlayer.Search(pFilter, false);
                 //select
                 IFeature ifeature = pCursor.NextFeature();
                 if (ifeature == null) throw new Exception();
                 while (ifeature != null)
                 {
                     imap.SelectFeature(pFeatureLayer, ifeature);
                     ifeature = pCursor.NextFeature();
                 }
                 axMapControl1.AddLayer(secondroadlayer);
                 this.secondroadbutton.Checked = true;
                 imap.SelectFeature(secondroadlayer, ifeature);
             }
             catch (Exception)
             {
                 errorflag++;
                 try
                 {
                     IFeatureLayer pFeatureLayer = addresslayer as IFeatureLayer;
                     IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                     switch (pFeatureClass.ShapeType)
                     {
                         case esriGeometryType.esriGeometryPoint:
                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                             break;
                         case esriGeometryType.esriGeometryPolyline:
                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                             break;
                         case esriGeometryType.esriGeometryPolygon:
                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                             break;
                         default:
                             break;
                     }
                     pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                     pFilter = pSpatialFilter;
                     //Do the Search 从图层中查询出满足约束条件的元素
                     IFeatureCursor pCursor = addresslayer.Search(pFilter, false);
                     //select
                     IFeature ifeature = pCursor.NextFeature();
                     if (ifeature == null) throw new Exception();
                     while (ifeature != null)
                     {
                         imap.SelectFeature(pFeatureLayer, ifeature);
                         ifeature = pCursor.NextFeature();
                     }
                     axMapControl1.AddLayer(addresslayer);
                     this.addressbutton.Checked = true;
                     imap.SelectFeature(addresslayer, ifeature);
                 }
                 catch (Exception)
                 {
                     errorflag++;
                     try
                     {
                         IFeatureLayer pFeatureLayer = trainstationlayer as IFeatureLayer;
                         IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                         switch (pFeatureClass.ShapeType)
                         {
                             case esriGeometryType.esriGeometryPoint:
                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                 break;
                             case esriGeometryType.esriGeometryPolyline:
                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                 break;
                             case esriGeometryType.esriGeometryPolygon:
                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                 break;
                             default:
                                 break;
                         }
                         pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                         pFilter = pSpatialFilter;
                         //Do the Search 从图层中查询出满足约束条件的元素
                         IFeatureCursor pCursor = trainstationlayer.Search(pFilter, false);
                         //select
                         IFeature ifeature = pCursor.NextFeature();
                         if (ifeature == null) throw new Exception();
                         while (ifeature != null)
                         {
                             imap.SelectFeature(pFeatureLayer, ifeature);
                             ifeature = pCursor.NextFeature();
                         }
                         axMapControl1.AddLayer(trainstationlayer);
                         this.trainstationbutton.Checked = true;
                         imap.SelectFeature(trainstationlayer, ifeature);
                     }
                     catch (Exception)
                     {
                         errorflag++;
                         try
                         {
                             IFeatureLayer pFeatureLayer = supermarketlayer as IFeatureLayer;
                             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                             switch (pFeatureClass.ShapeType)
                             {
                                 case esriGeometryType.esriGeometryPoint:
                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                     break;
                                 case esriGeometryType.esriGeometryPolyline:
                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                     break;
                                 case esriGeometryType.esriGeometryPolygon:
                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                     break;
                                 default:
                                     break;
                             }
                             pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                             pFilter = pSpatialFilter;
                             //Do the Search 从图层中查询出满足约束条件的元素
                             IFeatureCursor pCursor = supermarketlayer.Search(pFilter, false);
                             //select
                             IFeature ifeature = pCursor.NextFeature();
                             if (ifeature == null) throw new Exception();
                             while (ifeature != null)
                             {
                                 imap.SelectFeature(pFeatureLayer, ifeature);
                                 ifeature = pCursor.NextFeature();
                             }
                             axMapControl1.AddLayer(supermarketlayer);
                             this.supermarketbutton.Checked = true;
                             imap.SelectFeature(supermarketlayer, ifeature);
                         }
                         catch (Exception)
                         {
                             errorflag++;
                             try
                             {
                                 IFeatureLayer pFeatureLayer = banklayer as IFeatureLayer;
                                 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                 switch (pFeatureClass.ShapeType)
                                 {
                                     case esriGeometryType.esriGeometryPoint:
                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                         break;
                                     case esriGeometryType.esriGeometryPolyline:
                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                         break;
                                     case esriGeometryType.esriGeometryPolygon:
                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                         break;
                                     default:
                                         break;
                                 }
                                 pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                 pFilter = pSpatialFilter;
                                 //Do the Search 从图层中查询出满足约束条件的元素
                                 IFeatureCursor pCursor = banklayer.Search(pFilter, false);
                                 //select
                                 IFeature ifeature = pCursor.NextFeature();
                                 if (ifeature == null) throw new Exception();
                                 while (ifeature != null)
                                 {
                                     imap.SelectFeature(pFeatureLayer, ifeature);
                                     ifeature = pCursor.NextFeature();
                                 }
                                 axMapControl1.AddLayer(banklayer);
                                 this.bankbutton.Checked = true;
                                 imap.SelectFeature(banklayer, ifeature);
                             }
                             catch (Exception)
                             {
                                 errorflag++;
                                 try
                                 {
                                     IFeatureLayer pFeatureLayer = governmentlayer as IFeatureLayer;
                                     IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                     switch (pFeatureClass.ShapeType)
                                     {
                                         case esriGeometryType.esriGeometryPoint:
                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                             break;
                                         case esriGeometryType.esriGeometryPolyline:
                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                             break;
                                         case esriGeometryType.esriGeometryPolygon:
                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                             break;
                                         default:
                                             break;
                                     }
                                     pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                     pFilter = pSpatialFilter;
                                     //Do the Search 从图层中查询出满足约束条件的元素
                                     IFeatureCursor pCursor = governmentlayer.Search(pFilter, false);
                                     //select
                                     IFeature ifeature = pCursor.NextFeature();
                                     if (ifeature == null) throw new Exception();
                                     while (ifeature != null)
                                     {
                                         imap.SelectFeature(pFeatureLayer, ifeature);
                                         ifeature = pCursor.NextFeature();
                                     }
                                     axMapControl1.AddLayer(governmentlayer);
                                     this.governmentbutton.Checked = true;
                                     imap.SelectFeature(governmentlayer, ifeature);
                                 }
                                 catch (Exception)
                                 {
                                     errorflag++;
                                     try
                                     {
                                         IFeatureLayer pFeatureLayer = hospitallayer as IFeatureLayer;
                                         IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                         switch (pFeatureClass.ShapeType)
                                         {
                                             case esriGeometryType.esriGeometryPoint:
                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                 break;
                                             case esriGeometryType.esriGeometryPolyline:
                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                 break;
                                             case esriGeometryType.esriGeometryPolygon:
                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                 break;
                                             default:
                                                 break;
                                         }
                                         pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                         pFilter = pSpatialFilter;
                                         //Do the Search 从图层中查询出满足约束条件的元素
                                         IFeatureCursor pCursor = hospitallayer.Search(pFilter, false);
                                         //select
                                         IFeature ifeature = pCursor.NextFeature();
                                         if (ifeature == null) throw new Exception();
                                         while (ifeature != null)
                                         {
                                             imap.SelectFeature(pFeatureLayer, ifeature);
                                             ifeature = pCursor.NextFeature();
                                         }
                                         axMapControl1.AddLayer(hospitallayer);
                                         this.hospitalbutton.Checked = true;
                                         imap.SelectFeature(hospitallayer, ifeature);
                                     }
                                     catch (Exception)
                                     {
                                         errorflag++;
                                         try
                                         {
                                             IFeatureLayer pFeatureLayer = railwaylayer as IFeatureLayer;
                                             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                             switch (pFeatureClass.ShapeType)
                                             {
                                                 case esriGeometryType.esriGeometryPoint:
                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                     break;
                                                 case esriGeometryType.esriGeometryPolyline:
                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                     break;
                                                 case esriGeometryType.esriGeometryPolygon:
                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                     break;
                                                 default:
                                                     break;
                                             }
                                             pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                             pFilter = pSpatialFilter;
                                             //Do the Search 从图层中查询出满足约束条件的元素
                                             IFeatureCursor pCursor = railwaylayer.Search(pFilter, false);
                                             //select
                                             IFeature ifeature = pCursor.NextFeature();
                                             if (ifeature == null) throw new Exception();
                                             while (ifeature != null)
                                             {
                                                 imap.SelectFeature(pFeatureLayer, ifeature);
                                                 ifeature = pCursor.NextFeature();
                                             }
                                             axMapControl1.AddLayer(railwaylayer);
                                             this.railwaybutton.Checked = true;
                                             imap.SelectFeature(railwaylayer, ifeature);
                                         }
                                         catch (Exception)
                                         {
                                             errorflag++;
                                             try
                                             {
                                                 IFeatureLayer pFeatureLayer = recreationlayer as IFeatureLayer;
                                                 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                                 switch (pFeatureClass.ShapeType)
                                                 {
                                                     case esriGeometryType.esriGeometryPoint:
                                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                         break;
                                                     case esriGeometryType.esriGeometryPolyline:
                                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                         break;
                                                     case esriGeometryType.esriGeometryPolygon:
                                                         pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                         break;
                                                     default:
                                                         break;
                                                 }
                                                 pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                                 pFilter = pSpatialFilter;
                                                 //Do the Search 从图层中查询出满足约束条件的元素
                                                 IFeatureCursor pCursor = recreationlayer.Search(pFilter, false);
                                                 //select
                                                 IFeature ifeature = pCursor.NextFeature();
                                                 if (ifeature == null) throw new Exception();
                                                 while (ifeature != null)
                                                 {
                                                     imap.SelectFeature(pFeatureLayer, ifeature);
                                                     ifeature = pCursor.NextFeature();
                                                 }
                                                 axMapControl1.AddLayer(recreationlayer);
                                                 this.recreationbutton.Checked = true;
                                                 imap.SelectFeature(recreationlayer, ifeature);
                                             }
                                             catch (Exception)
                                             {
                                                 errorflag++;
                                                 try
                                                 {
                                                     IFeatureLayer pFeatureLayer = hotellayer as IFeatureLayer;
                                                     IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                                     switch (pFeatureClass.ShapeType)
                                                     {
                                                         case esriGeometryType.esriGeometryPoint:
                                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                             break;
                                                         case esriGeometryType.esriGeometryPolyline:
                                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                             break;
                                                         case esriGeometryType.esriGeometryPolygon:
                                                             pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                             break;
                                                         default:
                                                             break;
                                                     }
                                                     pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                                     pFilter = pSpatialFilter;
                                                     //Do the Search 从图层中查询出满足约束条件的元素
                                                     IFeatureCursor pCursor = hotellayer.Search(pFilter, false);
                                                     //select
                                                     IFeature ifeature = pCursor.NextFeature();
                                                     if (ifeature == null) throw new Exception();
                                                     while (ifeature != null)
                                                     {
                                                         imap.SelectFeature(pFeatureLayer, ifeature);
                                                         ifeature = pCursor.NextFeature();
                                                     }
                                                     axMapControl1.AddLayer(hotellayer);
                                                     this.hotelbutton.Checked = true;
                                                     imap.SelectFeature(hotellayer, ifeature);
                                                 }
                                                 catch (Exception)
                                                 {
                                                     errorflag++;
                                                     try
                                                     {
                                                         IFeatureLayer pFeatureLayer = sightlayer as IFeatureLayer;
                                                         IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                                         switch (pFeatureClass.ShapeType)
                                                         {
                                                             case esriGeometryType.esriGeometryPoint:
                                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                                 break;
                                                             case esriGeometryType.esriGeometryPolyline:
                                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                                 break;
                                                             case esriGeometryType.esriGeometryPolygon:
                                                                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                 break;
                                                             default:
                                                                 break;
                                                         }
                                                         pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                                         pFilter = pSpatialFilter;
                                                         //Do the Search 从图层中查询出满足约束条件的元素
                                                         IFeatureCursor pCursor = sightlayer.Search(pFilter, false);
                                                         //select
                                                         IFeature ifeature = pCursor.NextFeature();
                                                         if (ifeature == null) throw new Exception();
                                                         while (ifeature != null)
                                                         {
                                                             imap.SelectFeature(pFeatureLayer, ifeature);
                                                             ifeature = pCursor.NextFeature();
                                                         }
                                                         axMapControl1.AddLayer(sightlayer);
                                                         this.sightbutton.Checked = true;
                                                         imap.SelectFeature(sightlayer, ifeature);
                                                     }
                                                     catch (Exception)
                                                     {
                                                         errorflag++;
                                                         try
                                                         {
                                                             IFeatureLayer pFeatureLayer = busstationlayer as IFeatureLayer;
                                                             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                                                             switch (pFeatureClass.ShapeType)
                                                             {
                                                                 case esriGeometryType.esriGeometryPoint:
                                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                                                                     break;
                                                                 case esriGeometryType.esriGeometryPolyline:
                                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                                                                     break;
                                                                 case esriGeometryType.esriGeometryPolygon:
                                                                     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                     break;
                                                                 default:
                                                                     break;
                                                             }
                                                             pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
                                                             pFilter = pSpatialFilter;
                                                             //Do the Search 从图层中查询出满足约束条件的元素
                                                             IFeatureCursor pCursor = busstationlayer.Search(pFilter, false);
                                                             //select
                                                             IFeature ifeature = pCursor.NextFeature();
                                                             if (ifeature == null) throw new Exception();
                                                             while (ifeature != null)
                                                             {
                                                                 imap.SelectFeature(pFeatureLayer, ifeature);
                                                                 ifeature = pCursor.NextFeature();
                                                             }
                                                             axMapControl1.AddLayer(busstationlayer);
                                                             this.busstationbutton.Checked = true;
                                                             imap.SelectFeature(busstationlayer, ifeature);
                                                         }
                                                         catch (Exception)
                                                         {
                                                             errorflag++;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         axMapControl1.ActiveView.Refresh();
         if (errorflag == 14)
             MessageBox.Show("没有选取到点!");
     }
 }
Esempio n. 45
0
        private bool SpatialSelectByAttribute(string sLayerName, string sQuery, string sMinX, string sMinY, string sMaxX, string sMaxY)
        {
            IEnumLayer pLayers;
            ILayer pLayer;
            IFeatureLayer pFLayer;
            IFeatureSelection pFLSel;
            ISelectionSet pSelSet;
            IEnvelope pEnv;
            IMxDocument pMXDoc;
            ISpatialFilter pSF;
            IFeatureClass pFC;

            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;
                            pFLSel = (IFeatureSelection)pFLayer;
                            pFC = pFLayer.FeatureClass;
                            pEnv = new EnvelopeClass();
                            //pEnv.SpatialReference = pFC.
                            pEnv.PutCoords(System.Convert.ToDouble(sMinX), System.Convert.ToDouble(sMinY), System.Convert.ToDouble(sMaxX), System.Convert.ToDouble(sMaxY));
                            pSF = new SpatialFilter();
                            pSF.WhereClause = sQuery;
                            pSF.Geometry = pEnv;
                            pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                            pFLSel.SelectFeatures(pSF, esriSelectionResultEnum.esriSelectionResultNew, false);
                            pSelSet = pFLSel.SelectionSet;
                            SW1.Stop();
                            RecordActionTime ("SpatialSelectbyAttribute Features (" + pSelSet.Count + ")" ,SW1.ElapsedMilliseconds);
                            return true;
                        }
                    }
                    pLayer = pLayers.Next();
                }
                return false;
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("Failed:" + EX.Message);
                return false;
            }
        }
 private IGeometry mergeSmallGeos(IGeometry geo)
 {
     ITopologicalOperator4 tp4 = (ITopologicalOperator4)geo;
     IGeometryCollection geoCol = new PolygonClass();
     IGeometry bGeo = tp4.Boundary;
     ISpatialFilter spFilt = new SpatialFilter();
     spFilt.Geometry = bGeo;
     spFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;
     spFilt.GeometryField = ftrCls.ShapeFieldName;
     spFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
     spFilt.WhereClause = "Shape_Area <= " + minarea;
     spFilt.SubFields = ftrCls.ShapeFieldName;
     IFeatureCursor ftrCur = ftrCls.Search(spFilt, false);
     IFeature ftr = ftrCur.NextFeature();
     int cntTest = 0;
     while (ftr != null)
     {
         IGeometry sGeo = ftr.ShapeCopy;
         geoCol.AddGeometry(sGeo);
         ftr.Delete();
         ftr = ftrCur.NextFeature();
         cntTest++;
     }
     if (cntTest > 0)
     {
         tp4.ConstructUnion((IEnumGeometry)geoCol);
     }
     return (IGeometry)tp4;
 }
Esempio n. 47
0
        private void KalibreerVormpuntenOpBasisVanRaaien(IFeatureSelection FeatureSelectionMShape)
        {
            IPolygon buffer;
            int featurecount = FeatureSelectionMShape.SelectionSet.Count;
            int featurecounter = 0;
            double m_begin = 0;
            double m_eind = 0;

            ICursor SelectionCursor = null;

            if (featurecount == 0)
            {
                SelectionCursor = ((FeatureSelectionMShape as IFeatureLayer).FeatureClass.Search(null, false)) as ICursor;
                featurecount = (FeatureSelectionMShape as IFeatureLayer).FeatureClass.FeatureCount(null);
            }
            else
            {
                FeatureSelectionMShape.SelectionSet.Search(null, false, out SelectionCursor);
            }

            try
            {
                IFeature feature = SelectionCursor.NextRow() as IFeature;

                string sleutel1 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel1)));
                string sleutel2 = null;
                if (this.mshape_sleutel2 != "")
                {
                    sleutel2 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel2)));
                }

                IPolyline Polyline = null;
                IPolyline RaaiExtended = null;
                string hmwaarde = "";
                double hmgetal = 0;

                while (feature != null)
                {
                    // Vraag de lijn op
                    Polyline = feature.ShapeCopy as IPolyline;
                    m_begin = (Polyline as IPointCollection).get_Point(0).M;
                    m_eind = (Polyline as IPointCollection).get_Point((Polyline as IPointCollection).PointCount-1).M;

                    // bestaande measures wissen
                    (Polyline as IMAware).DropMs();

                    buffer = (Polyline as ITopologicalOperator).Buffer(Properties.Settings.Default.raai_afstand) as IPolygon;

                    // Selecteer alle LRS lijnen binnen de zoekafstand
                    ISpatialFilter SpatialFilter = new SpatialFilter();
                    IQueryFilter QueryFilter = SpatialFilter;
                    IFeature FeatureRaai = null;

                    SpatialFilter.Geometry = buffer;
                    SpatialFilter.GeometryField = fcRaai.ShapeFieldName;
                    string whereclause = Properties.Settings.Default.raai_selectie;
                    SpatialFilter.WhereClause = string.Format(whereclause, sleutel1, sleutel2);
                    SpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                    ESRI.ArcGIS.Geodatabase.IFeatureCursor FeatureCursorRaaien = fcRaai.Search(QueryFilter, false);

                    try
                    {
                        FeatureRaai = FeatureCursorRaaien.NextFeature();

                        // this._ArcObjectsHelper.AddGraphicToMap((ArcMap.Document as IMxDocument).FocusMap, Polyline, System.Drawing.Color.Red, System.Drawing.Color.Red);
                        while (FeatureRaai != null)
                        {
                            RaaiExtended = FeatureRaai.ShapeCopy as IPolyline;
                            hmwaarde = Convert.ToString(FeatureRaai.get_Value(FeatureRaai.Fields.FindField(Properties.Settings.Default.raai_hmgetal)));
                            if (!(double.TryParse(hmwaarde, NumberStyles.Float, CultureInfo.InvariantCulture, out hmgetal)))
                            {
                                if (this.MarkeerRaaiMetOngeldigeHmwaarde)
                                { _ArcObjectsHelper.AddGraphicToMap(FeatureRaai.ShapeCopy, this.KleurRaaiMetOngeldigeHmwaarde); }
                                continue;
                            }

                            if (between(m_begin, m_eind, hmgetal))
                            {
                                _ArcObjectsHelper.ScaleRaai(ref RaaiExtended);
                                _ArcObjectsHelper.InsertPointAtIntersection(ref Polyline, RaaiExtended as IGeometry, hmgetal);
                            }

                            FeatureRaai = FeatureCursorRaaien.NextFeature();

                        }

                    }
                    catch (System.Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                        logger.LogException(LogLevel.Trace, "FOUT", ex);
                        throw;
                    }
                    finally
                    {
                        FeatureRaai = null;
                        QueryFilter = null;
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(FeatureCursorRaaien);
                    }

                    // bijwerken measures met oorspronkelijke begin- en eindmeasure
                    this.ResetBeginEnEindMeasure(Polyline, m_begin, m_eind, true);

                    // controleer of de lijn monotoon op- of aflopend is
                    bool bNietMonotoon = false;
                    #region Controleer of de lijn monotoon oplopend of aflopend is en markeer de lijn.
                    int MMonotonicity = ((Polyline as IMSegmentation3).MMonotonicity);
                    if (MMonotonicity == 5 || MMonotonicity == 7 || MMonotonicity == 15)
                    {
                        bNietMonotoon = true;
                        if (this.MarkeerLijnNietMonotoon)
                        {
                            _ArcObjectsHelper.AddGraphicToMap(Polyline, this.KleurLijnNietMonotoon);
                        }
                    }

                    if ((bNietMonotoon) && (this.OpslaanLijnNietMonotoon))
                    {
                        feature.Shape = Polyline;
                        feature.Store();
                    }
                    else if (!bNietMonotoon)
                    {
                        feature.Shape = Polyline;
                        feature.Store();
                    }
                    #endregion

                    // voortgang
                    featurecounter += 1;
                    this.progress = (100 * featurecounter) / featurecount;

                    feature = SelectionCursor.NextRow() as IFeature;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                throw;
            }
            finally
            {
                ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(SelectionCursor);
            }
        }
Esempio n. 48
0
        private void KalibreerVormpuntenOpBasisVanSpoorhartlijn(IFeatureSelection FeatureSelectionMShape)
        {
            #region Bepaal de overlappende extent van raaien en selectie
            IGeoDataset GeoDatasetMShape = flMShape as IGeoDataset;
            IGeoDataset GeodatasetLRS = fcLRS as IGeoDataset;

            IEnvelope pQueryingGeometryFullExtent = GeoDatasetMShape.Extent;
            pQueryingGeometryFullExtent.Union(GeodatasetLRS.Extent);
            pQueryingGeometryFullExtent.Expand(10000, 10000, false);
            #endregion Bepaal de overlappende extent van raaien en selectie

            int featurecount = FeatureSelectionMShape.SelectionSet.Count;
            int featurecounter = 0;

            ICursor SelectionCursor = null;

            if (featurecount == 0)
            {
                SelectionCursor = ((FeatureSelectionMShape as IFeatureLayer).FeatureClass.Search(null, false)) as ICursor;
                featurecount = (FeatureSelectionMShape as IFeatureLayer).FeatureClass.FeatureCount(null);
            }
            else
            {
                FeatureSelectionMShape.SelectionSet.Search(null, false, out SelectionCursor);
            }

            IPolyline Polyline = null;
            IPolygon buffer = null;
            IPointCollection PointCollection = null;

            IList<IPolyline> PolylinesLRS = null;

            try
            {

                IFeature feature = SelectionCursor.NextRow() as IFeature;
                while (feature != null)
                {

                    Polyline = feature.ShapeCopy as IPolyline;
                    PointCollection = Polyline as IPointCollection;

                    #region lees de begin- en eindkilometrering en het selectie criterium
                    double m_begin = (Polyline as IPointCollection).get_Point(0).M;
                    double m_eind = (Polyline as IPointCollection).get_Point((Polyline as IPointCollection).PointCount - 1).M;
                    string sleutel1 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel1)));
                    string sleutel2 = null;
                    if (this.mshape_sleutel2 != "")
                    {
                        sleutel2 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel2)));
                    }

                    #endregion

                    // Selecteer alle LRS lijnen binnen de zoekafstand
                    ISpatialFilter SpatialFilter = new SpatialFilter();
                    IQueryFilter QueryFilter = SpatialFilter;

                    buffer = (Polyline as ITopologicalOperator).Buffer(Properties.Settings.Default.mshape_maxafstand) as IPolygon;

                    SpatialFilter.Geometry = buffer;
                    SpatialFilter.GeometryField = fcLRS.ShapeFieldName;
                    string whereclauseLRS = Properties.Settings.Default.lrs_selectie;
                    SpatialFilter.WhereClause = string.Format(whereclauseLRS, sleutel1, sleutel2);
                    SpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;

                    ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = fcLRS.Search(QueryFilter, false);

                    try
                    {
                        PolylinesLRS = new List<IPolyline>();
                        IFeature featureLRS = featureCursor.NextFeature();
                        while (featureLRS != null)
                        {
                            PolylinesLRS.Add(featureLRS.ShapeCopy as IPolyline);
                            featureLRS = featureCursor.NextFeature();
                        }

                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);
                    }

                    // Controleer of er een spoorhartlijn (LRS) in de buurt ligt. Zo niet, dan evt. markeren
                    if ((PolylinesLRS.Count == 0) && (this.MarkeerLijnBuitenZoekAfstand))
                    {
                        _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Polyline, this.KleurLijnBuitenZoekAfstand, this.KleurLijnBuitenZoekAfstand);
                        // Als er geen spoorhartlijn (LRS) in de buurt ligt, dan hoeven ook niet alle vormpunten doorlopen te worden.
                        continue; // while (feature != null)
                    }

                    #region Doorloop alle vormpunten en werk de vormpunten bij
                    bool bUpdated = false;
                    bool bNietMonotoon = false;
                    bool outPointGevonden = false;
                    double pDistance = 0;

                    for (int i = 1; i < PointCollection.PointCount-1; i++) // sla het eerste en het laatste punt over
                    {
                        // zoek de dichtstbijzijnde feature, eventueel aangevuld met geocode in een queryfilter
                        IPoint Point = PointCollection.get_Point(i);
                        IPoint outPoint = new ESRI.ArcGIS.Geometry.Point();
                        outPointGevonden = false;
                        pDistance = double.PositiveInfinity;
                        bUpdated = false;

                        this.ZoekPuntOpSpoorhartlijn(Point, PolylinesLRS, m_begin, m_eind, out outPoint, out outPointGevonden, out pDistance);
                        if (this.LogVormpunten)
                        {
                            if (outPointGevonden)
                            { this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, outPoint.X, outPoint.Y, outPoint.M); }
                            else
                            { this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, Point.X, Point.Y, Point.M); }
                        }

                        // Als er een punt gevonden is, binnen de zoekafstand en binnen het kilometerinterval
                        if (outPointGevonden)
                        {
                            if (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000))
                            {
                                if (MarkeerVormpuntMetAfwijking)
                                { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking); }
                            }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }

                            Point.M = outPoint.M;

                            PointCollection.UpdatePoint(i, Point);
                            bUpdated = true;
                        }
                        else if ((!outPointGevonden) && (outPoint != null)) // er is wel een punt gevonden, maar niet binnen het kilometerinterval.
                        {
                            // Als er een punt buiten het kilometerinterval gevonden is, binnen de zoekafstand, markeer het punt dan
                            if ((this.MarkeerVormpuntMetAfwijking) && (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000)))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking); }

                            if ((this.MarkeerVormpuntBuitenInterval) && !(between(m_begin, m_eind, outPoint.M, (TolerantieVormpuntBuitenInterval / 1000))))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenInterval, this.KleurVormpuntBuitenInterval); }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }

                        }
                        else if (!outPointGevonden) // er is geen punt gevonden binnen de zoekafstand
                        {
                            if (this.MarkeerVormpuntBuitenZoekAfstand)
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }
                        }

                        #region Markeer de bijgewerkte en niet bijgewerkte punten
                        if ((bUpdated) && (this.MarkeerVormpuntBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBijgewerkt, this.KleurVormpuntBijgewerkt);
                        }
                        if (!(bUpdated) && (this.MarkeerVormpuntNietBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntNietBijgewerkt, this.KleurVormpuntNietBijgewerkt);
                        }
                        #endregion

                    }
                    #endregion // doorloop de vormpunten

                    #region Reset begin- en eindkilometer
                    this.ResetBeginEnEindMeasure(Polyline, m_begin, m_eind, false);
                    #endregion

                    #region Controleer of de lijn monotoon oplopend of aflopend is en markeer de lijn.
                    int MMonotonicity = ((PointCollection as IMSegmentation3).MMonotonicity);
                    if (MMonotonicity == 5 || MMonotonicity == 7 || MMonotonicity == 15)
                    {
                        bNietMonotoon = true;
                        if (this.MarkeerLijnNietMonotoon)
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, PointCollection as IPolyline, this.KleurLijnNietMonotoon, this.KleurLijnNietMonotoon);
                        }
                    }

                    if ((bNietMonotoon) && (this.OpslaanLijnNietMonotoon))
                    {
                        feature.Shape = (PointCollection as IGeometry);
                        // UpdateCursor.UpdateFeature(feature);
                    }
                    else if (!bNietMonotoon)
                    {
                        feature.Shape = (PointCollection as IGeometry);
                    }
                    #endregion

                    // Voortgang
                    featurecounter += 1;
                    this.progress = (100 * featurecounter) / featurecount;

                    // Bijwerken
                    feature.Store();

                    // Volgende feature
                    feature = SelectionCursor.NextRow() as IFeature;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                throw;
            }
            finally
            {
                ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(SelectionCursor);
            }
        }
Esempio n. 49
0
        private IFeatureCursor FindFeatures(IGeometry geometry, IFeatureClass featureClass, esriSpatialRelEnum spatialRelationship, IMap map)
        {
            //1 = esriSpatialRelIntersects
            //7 = esriSpatialWithin
            //8 = esriSpatialRelContains

            ISpatialFilter spatialFilter = new SpatialFilter();
            spatialFilter.Geometry = geometry;
            spatialFilter.set_OutputSpatialReference(featureClass.ShapeFieldName, map.SpatialReference);
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.SpatialRel = spatialRelationship;

            IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
            return featureCursor;
        }
Esempio n. 50
0
        private void OnCreationFinishedGenesis(IObject obj)
        {
            ISpatialFilter spatialFilter = new SpatialFilter();
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            IGeometry geometryOfFeature = ((IFeature) obj).Shape;
            if (geometryOfFeature.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                IPoint pointStart = ((IPolyline) geometryOfFeature).ToPoint;
                IPoint pointEnd = ((IPolyline) geometryOfFeature).FromPoint;
                //MessageBox.Show(String.Format("The starting X: {0} and y:{1}", pointStart.X, pointStart.Y));
                //MessageBox.Show(String.Format("The ending X: {0} and y:{1}", pointEnd.X, pointEnd.Y));

                IFeatureLayer pointLayer = (IFeatureLayer) GetPointFeature();

                ITable table = ((IFeature) obj).Table;
                IFeatureClass fc = table as IFeatureClass;
                if ((fc.AliasName) == "Lines")
                {
                    spatialFilter.Geometry = pointStart;
                    spatialFilter.GeometryField = fc.ShapeFieldName;

                    IFeatureCursor allPoints = (pointLayer.FeatureClass).Search(spatialFilter, false);
                    IFeature point = null;
                    if (allPoints.NextFeature() == null)
                    {
                        IFeature featureInsert = (pointLayer.FeatureClass).CreateFeature();
                        featureInsert.Shape = pointStart;
                        featureInsert.Store();
                    }

                    spatialFilter.Geometry = pointEnd;
                    spatialFilter.GeometryField = fc.ShapeFieldName;

                    allPoints = (pointLayer.FeatureClass).Search(spatialFilter, false);
                    point = null;
                    if (allPoints.NextFeature() == null)
                    {
                        IFeature featureInsert = (pointLayer.FeatureClass).CreateFeature();
                        featureInsert.Shape = pointEnd;
                        featureInsert.Store();

                    }
                    allPoints.Flush();

                    //spatialFilter.Geometry = ((IFeature) pointLayer.FeatureClass).ShapeCopy;
                    //spatialFilter.GeometryField = fc.ShapeFieldName;

                    //IFeatureCursor featureCursor = ((IFeatureClass) pointStart).Search(spatialFilter, false);
                    //IFeature pointsInCursor = null;
                    //while ((pointsInCursor = featureCursor.NextFeature()) != null)
                    //{
                    //    MessageBox.Show(pointsInCursor.get_Value(0));
                    //}
                }
            }
        }
        //public static void SplitLinesAtClick(IApplication app, string SplitSuspendAA, double SplitAtLocationSnap, double SkipDistance, IPoint SplitPoint, bool onlySelectedFeatures, bool ignoreTolerence, bool logEditOperation)
        //{
        //    ESRI.ArcGIS.Framework.ICommandItem pCmd = null;
        //    ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null;
        //    ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
        //    ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null;
        //    ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
        //    IMxDocument mxdoc = null;
        //    IEditor editor = null;
        //    IEditLayers eLayers = null;
        //    IMap map = null;
        //    IFeatureLayer fLayer = null;
        //    IFeatureSelection fSel = null;
        //    UID geoFeatureLayerID = null;
        //    IEnumLayer enumLayer = null;
        //    ILayer layer = null;
        //    List<IFeatureLayer> lineLayers = null;
        //    IHitTest hitTest = null;
        //    ISpatialFilter pSpatFilt = null;
        //    ICursor lineCursor = null;
        //    IFeatureCursor lineFCursor = null;
        //    ITopologicalOperator topoOp = null;
        //    IPolygon poly = null;
        //    IFeatureSelection lineSel = null;
        //    IFeature lineFeature = null;
        //    IFeatureEdit2 featureEdit = null;
        //    IPoint pHitPnt = null;
        //    ITopologicalOperator topoOpEndStart = null;
        //    IPolygon polyEndStart = null;
        //    IRelationalOperator relOp = null;
        //    ICurve curve = null;
        //    List<MergeSplitGeoNetFeatures> m_Config = null;
        //    ISet pSet = null;
        //    IFeature pSplitResFeat = null;
        //    try
        //    {
        //        m_Config = ConfigUtil.GetMergeSplitConfig();
        //        if (SplitSuspendAA.ToUpper() == "TRUE")
        //        {
        //            pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app);
        //            if (pCmd != null)
        //            {
        //                pCmd.Execute();
        //            }
        //        }
        //        mxdoc = (IMxDocument)app.Document;
        //        editor = Globals.getEditor(app);
        //        if (editor.EditState != esriEditState.esriStateEditing)
        //        {
        //            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_4"));
        //            return;
        //        }
        //        //Get enumeration of editable layers
        //        eLayers = (IEditLayers)editor;
        //        map = editor.Map;
        //        int i = 0;
        //        //Get enumeration of feature layers
        //        geoFeatureLayerID = new UIDClass();
        //        geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
        //        enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);
        //        layer = enumLayer.Next();
        //        // Create list of visible, editable line layers
        //        lineLayers = new List<IFeatureLayer>();
        //        enumLayer.Reset();
        //        layer = enumLayer.Next();
        //        while (!(layer == null))
        //        {
        //            fLayer = (IFeatureLayer)layer;
        //            if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
        //               && (fLayer.Visible))
        //            {
        //                if (eLayers.IsEditable(fLayer))
        //                {
        //                    if (onlySelectedFeatures)
        //                    {
        //                        fSel = (IFeatureSelection)fLayer;
        //                        if (fSel.SelectionSet.Count > 0)
        //                            lineLayers.Add(fLayer);
        //                    }
        //                    else
        //                    {
        //                        lineLayers.Add(fLayer);
        //                    }
        //                }
        //            }
        //            layer = enumLayer.Next();
        //        }
        //        //ProgressBar
        //        progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
        //        // Create a CancelTracker
        //        trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();
        //        // Set the properties of the Step Progressor
        //        System.Int32 int32_hWnd = app.hWnd;
        //        stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
        //        stepProgressor.MinRange = 1;
        //        stepProgressor.MaxRange = 1;
        //        stepProgressor.StepValue = 1;
        //        stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_7");
        //        // Create the ProgressDialog. This automatically displays the dialog
        //        progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast
        //        // Set the properties of the ProgressDialog
        //        progressDialog.CancelEnabled = true;
        //        progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_8");
        //        progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_7");
        //        progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
        //        //Create an edit operation enabling undo/redo
        //        if (logEditOperation)
        //            editor.StartOperation();
        //        try
        //        {
        //            topoOp = SplitPoint as ITopologicalOperator;
        //            if (ignoreTolerence)
        //            {
        //                poly = topoOp.Buffer(Globals.ConvertFeetToMapUnits(1, app)) as IPolygon;
        //            }
        //            else
        //            {
        //                poly = topoOp.Buffer(Globals.ConvertFeetToMapUnits(SplitAtLocationSnap, app)) as IPolygon;
        //            }
        //            foreach (IFeatureLayer lineLayer in lineLayers)
        //            {
        //                if (onlySelectedFeatures)
        //                {
        //                    lineSel = lineLayer as IFeatureSelection;
        //                    lineSel.SelectionSet.Search(null, false, out lineCursor);
        //                    lineFCursor = lineCursor as IFeatureCursor;
        //                }
        //                else
        //                {
        //                    pSpatFilt = new SpatialFilter();
        //                    pSpatFilt.GeometryField = lineLayer.FeatureClass.ShapeFieldName;
        //                    pSpatFilt.Geometry = poly;
        //                    pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
        //                    lineFCursor = lineLayer.Search(pSpatFilt, false);
        //                    //lineFCursor = lineCursor as IFeatureCursor;
        //                }
        //                IList<MergeSplitFlds> pFldsNames = new List<MergeSplitFlds>();
        //                if (m_Config.Count > 0)
        //                {
        //                    foreach (A4LGSharedFunctions.Field FldNam in m_Config[0].Fields)
        //                    {
        //                        int idx = Globals.GetFieldIndex(lineLayer.FeatureClass.Fields, FldNam.Name);
        //                        if (idx > -1)
        //                            pFldsNames.Add(new MergeSplitFlds(FldNam.Name, idx, "", FldNam.MergeRule, FldNam.SplitRule));
        //                    }
        //                }
        //                lineFeature = lineFCursor.NextFeature();
        //                while (!(lineFeature == null))
        //                {
        //                    featureEdit = lineFeature as IFeatureEdit2;
        //                    hitTest = lineFeature.ShapeCopy as IHitTest;
        //                    pHitPnt = new PointClass();
        //                    double pHitDist = -1;
        //                    int pHitPrt = -1;
        //                    int pHitSeg = -1;
        //                    bool pHitSide = false;
        //                    bool hit = hitTest.HitTest(SplitPoint, SplitAtLocationSnap, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, pHitDist, pHitPrt, pHitSeg, pHitSide);
        //                    if (hit)
        //                    {
        //                        if (ignoreTolerence == true && (pHitDist == 0.0 || pHitDist == -1.0))
        //                        {
        //                            //Split feature
        //                            topoOpEndStart = pHitPnt as ITopologicalOperator;
        //                            polyEndStart = topoOpEndStart.Buffer(SkipDistance) as IPolygon;
        //                            relOp = polyEndStart as IRelationalOperator;
        //                            curve = lineFeature.Shape as ICurve;
        //                            if (!(relOp.Contains(curve.FromPoint)) &&
        //                                !(relOp.Contains(curve.ToPoint)))
        //                            {
        //                                Globals.FlashGeometry(pHitPnt, Globals.GetColor(255, 0, 0), mxdoc.ActiveView.ScreenDisplay, 150);
        //                                double dblHighVal = 0;
        //                                double dblLowVal = 0;
        //                                int intHighIdx = -1;
        //                                int intLowIdx = -1;
        //                                foreach (MergeSplitFlds FldNam in pFldsNames)
        //                                {
        //                                    FldNam.Value = lineFeature.get_Value(FldNam.FieldIndex).ToString();
        //                                    if (FldNam.SplitType.ToUpper() == "MAX")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblHighVal = Convert.ToDouble(FldNam.Value);
        //                                                intHighIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                    else if (FldNam.SplitType.ToUpper() == "MIN")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblLowVal = Convert.ToDouble(FldNam.Value);
        //                                                intLowIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                }
        //                                if (intHighIdx > -1 && intLowIdx > -1)
        //                                {
        //                                    double len = ((ICurve)(lineFeature.Shape as IPolyline)).Length;
        //                                    double splitDist = Globals.PointDistanceOnLine(pHitPnt, lineFeature.Shape as IPolyline, 2, out pHitPnt);
        //                                    double percentSplit = splitDist / len;
        //                                    double dblMidVal;
        //                                    if (m_Config[0].SplitFormatString == "")
        //                                    {
        //                                        dblMidVal = dblLowVal + ((dblHighVal - dblLowVal) * percentSplit);
        //                                    }
        //                                    else
        //                                    {
        //                                        dblMidVal = Convert.ToDouble(string.Format(m_Config[0].SplitFormatString, dblLowVal + ((dblHighVal - dblLowVal) * percentSplit)));
        //                                    }
        //                                    //Split feature
        //                                    pSet = featureEdit.SplitWithUpdate(pHitPnt);
        //                                    if (pSet.Count == 1)
        //                                    {
        //                                        while ((pSplitResFeat = pSet.Next() as IFeature) != null)
        //                                        {
        //                                            if ((pSplitResFeat.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intHighIdx, dblMidVal);
        //                                            }
        //                                            else if ((pSplitResFeat.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intLowIdx, dblMidVal);
        //                                            }
        //                                        }
        //                                    }
        //                                    if ((lineFeature.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intHighIdx, dblMidVal);
        //                                    }
        //                                    else if ((lineFeature.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intLowIdx, dblMidVal);
        //                                    }
        //                                }
        //                                else
        //                                    featureEdit.SplitWithUpdate(pHitPnt);
        //                                //mxdoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, hitTest, mxdoc.ActiveView.Extent);
        //                                mxdoc.ActiveView.Refresh();
        //                                //mxdoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, curve, mxdoc.ActiveView.Extent);
        //                            }
        //                            topoOpEndStart = null;
        //                            polyEndStart = null;
        //                            relOp = null;
        //                            curve = null;
        //                        }
        //                        else if (ignoreTolerence == false)
        //                        {
        //                            //Split feature
        //                            topoOpEndStart = pHitPnt as ITopologicalOperator;
        //                            polyEndStart = topoOpEndStart.Buffer(SkipDistance) as IPolygon;
        //                            relOp = polyEndStart as IRelationalOperator;
        //                            curve = lineFeature.ShapeCopy as ICurve;
        //                            if (!(relOp.Contains(curve.FromPoint)) &&
        //                                !(relOp.Contains(curve.ToPoint)))
        //                            {
        //                                //Split feature
        //                                Globals.FlashGeometry(pHitPnt, Globals.GetColor(255, 0, 0), mxdoc.ActiveView.ScreenDisplay, 150);
        //                                double dblHighVal = 0;
        //                                double dblLowVal = 0;
        //                                int intHighIdx = -1;
        //                                int intLowIdx = -1;
        //                                foreach (MergeSplitFlds FldNam in pFldsNames)
        //                                {
        //                                    FldNam.Value = lineFeature.get_Value(FldNam.FieldIndex).ToString();
        //                                    if (FldNam.SplitType.ToUpper() == "MAX")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblHighVal = Convert.ToDouble(FldNam.Value);
        //                                                intHighIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                    else if (FldNam.SplitType.ToUpper() == "MIN")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblLowVal = Convert.ToDouble(FldNam.Value);
        //                                                intLowIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                }
        //                                if (intHighIdx > -1 && intLowIdx > -1)
        //                                {
        //                                    double len = ((ICurve)(lineFeature.Shape as IPolyline)).Length;
        //                                    double splitDist = Globals.PointDistanceOnLine(pHitPnt, lineFeature.Shape as IPolyline, 2, out pHitPnt);
        //                                    double percentSplit = splitDist / len;
        //                                    double dblMidVal;
        //                                    if (m_Config[0].SplitFormatString == "")
        //                                    {
        //                                        dblMidVal = dblLowVal + ((dblHighVal - dblLowVal) * percentSplit);
        //                                    }
        //                                    else
        //                                    {
        //                                        dblMidVal = Convert.ToDouble(string.Format(m_Config[0].SplitFormatString, dblLowVal + ((dblHighVal - dblLowVal) * percentSplit)));
        //                                    }
        //                                    //Split feature
        //                                    pSet = featureEdit.SplitWithUpdate(pHitPnt);
        //                                    if (pSet.Count == 1)
        //                                    {
        //                                        while ((pSplitResFeat = pSet.Next() as IFeature) != null)
        //                                        {
        //                                            if ((pSplitResFeat.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intHighIdx, dblMidVal);
        //                                            }
        //                                            else if ((pSplitResFeat.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intLowIdx, dblMidVal);
        //                                            }
        //                                        }
        //                                    }
        //                                    if ((lineFeature.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intHighIdx, dblMidVal);
        //                                    }
        //                                    else if ((lineFeature.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intLowIdx, dblMidVal);
        //                                    }
        //                                }
        //                                else
        //                                    featureEdit.SplitWithUpdate(pHitPnt);
        //                            }
        //                            topoOpEndStart = null;
        //                            polyEndStart = null;
        //                            relOp = null;
        //                            curve = null;
        //                        }
        //                    }
        //                    if (lineFeature != null)
        //                    {
        //                        System.Runtime.InteropServices.Marshal.ReleaseComObject(lineFeature);
        //                    }
        //                    lineFeature = lineFCursor.NextFeature();
        //                }
        //                if (lineCursor != null)
        //                {
        //                    System.Runtime.InteropServices.Marshal.ReleaseComObject(lineCursor);
        //                }
        //                System.Runtime.InteropServices.Marshal.ReleaseComObject(lineFCursor);
        //            }
        //            //Update progress bar
        //            i += 1;
        //            progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_8");
        //            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = app.StatusBar;
        //            statusBar.set_Message(0, i.ToString());
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1"));
        //            if (logEditOperation)
        //                editor.AbortOperation();
        //            return;
        //        }
        //        finally
        //        {
        //            mxdoc.ActiveView.Refresh();
        //            progressDialog.HideDialog();
        //        }
        //        //Stop the edit operation
        //        if (logEditOperation)
        //            editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_9"));
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1"));
        //        return;
        //    }
        //    finally
        //    {
        //        if (progressDialog != null)
        //            progressDialog.HideDialog();
        //        if (SplitSuspendAA.ToUpper() == "TRUE")
        //        {
        //            pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app);
        //            if (pCmd != null)
        //            {
        //                pCmd.Execute();
        //            }
        //        }
        //        pCmd = null;
        //        progressDialog = null;
        //        progressDialogFactory = null;
        //        trackCancel = null;
        //        stepProgressor = null;
        //        mxdoc = null;
        //        editor = null;
        //        eLayers = null;
        //        map = null;
        //        fLayer = null;
        //        fSel = null;
        //        geoFeatureLayerID = null;
        //        enumLayer = null;
        //        layer = null;
        //        lineLayers = null;
        //        hitTest = null;
        //        pSpatFilt = null;
        //        lineCursor = null;
        //        lineFCursor = null;
        //        topoOp = null;
        //        poly = null;
        //        lineSel = null;
        //        lineFeature = null;
        //        featureEdit = null;
        //        pHitPnt = null;
        //        topoOpEndStart = null;
        //        polyEndStart = null;
        //        relOp = null;
        //        curve = null;
        //    }
        //}
        //public static void SplitLines(IApplication app, string SplitSuspendAA, double SplitAtLocationSnap, double SkipDistance)
        //{
        //    IProgressDialogFactory progressDialogFactory = null;
        //    ITrackCancel trackCancel = null;
        //    IStepProgressor stepProgressor = null;
        //    IProgressDialog2 progressDialog = null;
        //    ICommandItem pCmd = null;
        //    IEditLayers eLayers = null;
        //    IEditor editor = null;
        //    IMxDocument mxdoc = null;
        //    IMap map = null;
        //    IFeatureLayer fLayer = null;
        //    IFeatureSelection fSel = null;
        //    UID geoFeatureLayerID = null;
        //    IEnumLayer enumLayer = null;
        //    List<IFeatureLayer> pointLayers = null;
        //    ILayer layer = null;
        //    List<IFeatureLayer> lineLayers;
        //    List<MergeSplitGeoNetFeatures> m_Config = null;
        //    IPoint pSplitPnt = null;
        //    ISet pSet = null;
        //    IFeature pSplitResFeat = null;
        //    try
        //    {
        //        m_Config = ConfigUtil.GetMergeSplitConfig();
        //        if (SplitSuspendAA.ToUpper() == "TRUE")
        //        {
        //            pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app);
        //            if (pCmd != null)
        //            {
        //                pCmd.Execute();
        //            }
        //        }
        //        editor = Globals.getEditor(app);
        //        if (editor.EditState != esriEditState.esriStateEditing)
        //        {
        //            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_5"));
        //            return;
        //        }
        //        //Get enumeration of editable layers
        //        eLayers = (IEditLayers)editor;
        //        mxdoc = (IMxDocument)app.Document;
        //        map = editor.Map;
        //        int i = 0;
        //        int total = 0;
        //        //Get enumeration of feature layers
        //        geoFeatureLayerID = new UIDClass();
        //        geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
        //        enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);
        //        // Create list of visible point layers with selected feature(s)
        //        pointLayers = new List<IFeatureLayer>();
        //        lineLayers = new List<IFeatureLayer>();
        //        enumLayer.Reset();
        //        layer = enumLayer.Next();
        //        while (layer != null)
        //        {
        //            fLayer = (IFeatureLayer)layer;
        //            if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
        //               && (fLayer.Visible))
        //            {
        //                fSel = fLayer as IFeatureSelection;
        //                if (fSel.SelectionSet.Count > 0)
        //                {
        //                    total += fSel.SelectionSet.Count;
        //                    pointLayers.Add(fLayer);
        //                }
        //            }
        //            else if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
        //                && (fLayer.Visible))
        //            {
        //                if (eLayers.IsEditable(fLayer))
        //                    lineLayers.Add(fLayer);
        //            }
        //            layer = enumLayer.Next();
        //        }
        //        //ProgressBar
        //        progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
        //        // Create a CancelTracker
        //        trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();
        //        // Set the properties of the Step Progressor
        //        System.Int32 int32_hWnd = app.hWnd;
        //        stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
        //        stepProgressor.MinRange = 0;
        //        stepProgressor.MaxRange = total;
        //        stepProgressor.StepValue = 1;
        //        stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_10");
        //        // Create the ProgressDialog. This automatically displays the dialog
        //        progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor;
        //        // Set the properties of the ProgressDialog
        //        progressDialog.CancelEnabled = true;
        //        progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_11") + i.ToString() + A4LGSharedFunctions.Localizer.GetString("Of") + total.ToString() + ".";
        //        progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_9");
        //        progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
        //        //Create an edit operation enabling undo/redo
        //        editor.StartOperation();
        //        ICursor pointCursor = null;
        //        IFeatureSelection pointSel = null;
        //        IFeature pointFeature = null;
        //        ISpatialFilter sFilter = null;
        //        IFeatureSelection lineSel = null;
        //        IFeatureCursor lineCursor = null;
        //        IFeature lineFeature = null;
        //        IFeatureEdit2 featureEdit = null;
        //        //Determine if point is at end of this line (if so skip)
        //        ITopologicalOperator topoOp = null;
        //        IPolygon poly = null;
        //        IRelationalOperator relOp = null;
        //        ICurve curve = null;
        //        try
        //        {
        //            // step through all points and split the lines that intersect them
        //            foreach (IFeatureLayer pointLayer in pointLayers)
        //            {
        //                pointSel = pointLayer as IFeatureSelection;
        //                pointSel.SelectionSet.Search(null, false, out pointCursor);
        //                pointFeature = pointCursor.NextRow() as IFeature;
        //                while (!(pointFeature == null))
        //                {
        //                    foreach (IFeatureLayer lineLayer in lineLayers)
        //                    {
        //                        sFilter = new SpatialFilterClass();
        //                        sFilter.Geometry = pointFeature.ShapeCopy;
        //                        sFilter.GeometryField = lineLayer.FeatureClass.ShapeFieldName;
        //                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
        //                        lineSel = lineLayer as IFeatureSelection;
        //                        lineCursor = lineLayer.Search(sFilter, false);
        //                        lineFeature = lineCursor.NextFeature();
        //                        IList<MergeSplitFlds> pFldsNames = new List<MergeSplitFlds>();
        //                        if (m_Config.Count > 0)
        //                        {
        //                            foreach (A4LGSharedFunctions.Field FldNam in m_Config[0].Fields)
        //                            {
        //                                int idx = Globals.GetFieldIndex(lineLayer.FeatureClass.Fields, FldNam.Name);
        //                                if (idx > -1)
        //                                    pFldsNames.Add(new MergeSplitFlds(FldNam.Name, idx, "", FldNam.MergeRule,FldNam.SplitRule));
        //                            }
        //                        }
        //                        while (!(lineFeature == null))
        //                        {
        //                            featureEdit = lineFeature as IFeatureEdit2;
        //                            //Determine if point is at end of this line (if so skip)
        //                            topoOp = pointFeature.Shape as ITopologicalOperator;
        //                            poly = topoOp.Buffer(SkipDistance) as IPolygon;
        //                            relOp = poly as IRelationalOperator;
        //                            curve = lineFeature.Shape as ICurve;
        //                            if (!(relOp.Contains(curve.FromPoint)) &
        //                                !(relOp.Contains(curve.ToPoint)))
        //                            {
        //                                 pSplitPnt = pointFeature.ShapeCopy as IPoint;
        //                                 double dblHighVal = 0;
        //                                 double dblLowVal = 0;
        //                                 int intHighIdx = -1;
        //                                 int intLowIdx = -1;
        //                                foreach (MergeSplitFlds FldNam in pFldsNames)
        //                                {
        //                                    FldNam.Value= lineFeature.get_Value(FldNam.FieldIndex).ToString();
        //                                    if (FldNam.SplitType.ToUpper() == "MAX")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblHighVal = Convert.ToDouble(FldNam.Value);
        //                                                intHighIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                    else if (FldNam.SplitType.ToUpper() == "MIN")
        //                                    {
        //                                        if (FldNam.Value != null)
        //                                        {
        //                                            if (FldNam.Value != "")
        //                                            {
        //                                                dblLowVal = Convert.ToDouble(FldNam.Value);
        //                                                intLowIdx = FldNam.FieldIndex;
        //                                            }
        //                                        }
        //                                    }
        //                                }
        //                                if (intHighIdx > -1 && intLowIdx > -1)
        //                                {
        //                                    double len = ((ICurve)(lineFeature.Shape as IPolyline)).Length;
        //                                    double splitDist = Globals.PointDistanceOnLine(pSplitPnt, lineFeature.Shape as IPolyline, 2, out pSplitPnt);
        //                                    double percentSplit = splitDist / len;
        //                                    double dblMidVal;
        //                                    if (m_Config[0].SplitFormatString == "")
        //                                    {
        //                                        dblMidVal = dblLowVal + ((dblHighVal - dblLowVal) * percentSplit);
        //                                    }
        //                                    else
        //                                    {
        //                                        dblMidVal = Convert.ToDouble(string.Format(m_Config[0].SplitFormatString, dblLowVal + ((dblHighVal - dblLowVal) * percentSplit)));
        //                                    }
        //                                    //Split feature
        //                                    pSet = featureEdit.SplitWithUpdate(pSplitPnt);
        //                                    if (pSet.Count == 1)
        //                                    {
        //                                        while ((pSplitResFeat = pSet.Next() as IFeature) != null)
        //                                        {
        //                                            if ((pSplitResFeat.ShapeCopy as IPolyline).FromPoint.X == pSplitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).FromPoint.Y == pSplitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intHighIdx, dblMidVal);
        //                                            }
        //                                            else if ((pSplitResFeat.ShapeCopy as IPolyline).ToPoint.X == pSplitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).ToPoint.Y == pSplitPnt.Y)
        //                                            {
        //                                                pSplitResFeat.set_Value(intLowIdx, dblMidVal);
        //                                            }
        //                                        }
        //                                    }
        //                                    if ((lineFeature.ShapeCopy as IPolyline).FromPoint.X == pSplitPnt.X && (lineFeature.ShapeCopy as IPolyline).FromPoint.Y == pSplitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intHighIdx, dblMidVal);
        //                                    }
        //                                    else if ((lineFeature.ShapeCopy as IPolyline).ToPoint.X == pSplitPnt.X && (lineFeature.ShapeCopy as IPolyline).ToPoint.Y == pSplitPnt.Y)
        //                                    {
        //                                        lineFeature.set_Value(intLowIdx, dblMidVal);
        //                                    }
        //                                }else
        //                                    pSet = featureEdit.SplitWithUpdate(pSplitPnt);
        //                                pSplitPnt = null;
        //                            }
        //                            lineFeature = lineCursor.NextFeature();
        //                        }
        //                        System.Runtime.InteropServices.Marshal.ReleaseComObject(lineCursor);
        //                    }
        //                    //Update progress bar
        //                    i += 1;
        //                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_11") + i.ToString() + A4LGSharedFunctions.Localizer.GetString("Of") + total.ToString() + ".";
        //                    stepProgressor.Step();
        //                    ESRI.ArcGIS.esriSystem.IStatusBar statusBar = app.StatusBar;
        //                    statusBar.set_Message(0, i.ToString());
        //                    //Check if the cancel button was pressed. If so, stop process
        //                    if (!trackCancel.Continue())
        //                    {
        //                        break;
        //                    }
        //                    pointFeature = (IFeature)pointCursor.NextRow();
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            editor.AbortOperation();
        //            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_5") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_5"));
        //            return;
        //        }
        //        finally
        //        {
        //            if (pointCursor != null)
        //            {
        //                System.Runtime.InteropServices.Marshal.ReleaseComObject(pointCursor);
        //            }
        //            pointCursor = null;
        //            pointSel = null;
        //            pointFeature = null;
        //            sFilter = null;
        //            lineSel = null;
        //            lineCursor = null;
        //            lineFeature = null;
        //            featureEdit = null;
        //            topoOp = null;
        //            poly = null;
        //            relOp = null;
        //            curve = null;
        //        }
        //        progressDialog.HideDialog();
        //        //Stop the edit operation
        //        editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_9"));
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_5") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_5"));
        //        return;
        //    }
        //    finally
        //    {
        //        pSet = null;
        //        pSplitPnt = null;
        //        if (SplitSuspendAA.ToUpper() == "TRUE")
        //        {
        //            pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app);
        //            if (pCmd != null)
        //            {
        //                pCmd.Execute();
        //            }
        //            pCmd = null;
        //        }
        //        if (progressDialog != null)
        //            progressDialog.HideDialog();
        //        progressDialogFactory = null;
        //        trackCancel = null;
        //        stepProgressor = null;
        //        progressDialog = null;
        //        pCmd = null;
        //        eLayers = null;
        //        editor = null;
        //        mxdoc = null;
        //        map = null;
        //        fLayer = null;
        //        fSel = null;
        //        geoFeatureLayerID = null;
        //        enumLayer = null;
        //        pointLayers = null;
        //        layer = null;
        //        lineLayers = null;
        //        pSplitResFeat = null;
        //    }
        //}
        public static void SplitLinesAtClick(IApplication app, string SplitSuspendAA, double SplitAtLocationSnap, double SkipDistance, IPoint SplitPoint, bool onlySelectedFeatures, bool ignoreTolerence, bool logEditOperation)
        {
            ESRI.ArcGIS.Framework.ICommandItem pCmd = null;
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null;
            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
            IMxDocument mxdoc = null;
            IEditor editor = null;
            IEditLayers eLayers = null;
            IMap map = null;
            IFeatureLayer fLayer = null;
            IFeatureSelection fSel = null;
            UID geoFeatureLayerID = null;
            IEnumLayer enumLayer = null;
            ILayer layer = null;
            List<IFeatureLayer> lineLayers = null;

            ISpatialFilter pSpatFilt = null;
            ICursor lineCursor = null;
            IFeatureCursor lineFCursor = null;
            ITopologicalOperator topoOp = null;

            IPolygon poly = null;
            IFeatureSelection lineSel = null;
            IFeature lineFeature = null;

            List<MergeSplitGeoNetFeatures> m_Config = null;

            //IHitTest hitTest = null;
            //IFeatureEdit2 featureEdit = null;

            //IPoint pHitPnt = null;
            //ITopologicalOperator topoOpEndStart = null;
            //IPolygon polyEndStart = null;
            //IRelationalOperator relOp = null;
            //ICurve curve = null;
            //ISet pSet = null;
            //IFeature pSplitResFeat = null;

            try
            {
                m_Config = ConfigUtil.GetMergeSplitConfig();

                if (SplitSuspendAA.ToUpper() == "TRUE")
                {
                    pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app);
                    if (pCmd != null)
                    {
                        pCmd.Execute();
                    }
                }
                mxdoc = (IMxDocument)app.Document;
                editor = Globals.getEditor(app);

                if (editor.EditState != esriEditState.esriStateEditing)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_4"));
                    return;
                }

                //Get enumeration of editable layers
                eLayers = (IEditLayers)editor;

                map = editor.Map;

                int i = 0;

                //Get enumeration of feature layers
                geoFeatureLayerID = new UIDClass();
                geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);

                layer = enumLayer.Next();

                // Create list of visible, editable line layers
                lineLayers = new List<IFeatureLayer>();
                enumLayer.Reset();
                layer = enumLayer.Next();
                while (!(layer == null))
                {
                    fLayer = (IFeatureLayer)layer;
                    if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                       && (fLayer.Visible))
                    {
                        if (eLayers.IsEditable(fLayer))
                        {
                            if (onlySelectedFeatures)
                            {
                                fSel = (IFeatureSelection)fLayer;
                                if (fSel.SelectionSet.Count > 0)
                                    lineLayers.Add(fLayer);
                            }
                            else
                            {
                                lineLayers.Add(fLayer);
                            }
                        }
                    }
                    layer = enumLayer.Next();
                }

                //ProgressBar
                progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

                // Create a CancelTracker
                trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

                // Set the properties of the Step Progressor
                System.Int32 int32_hWnd = app.hWnd;
                stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
                stepProgressor.MinRange = 1;
                stepProgressor.MaxRange = 1;
                stepProgressor.StepValue = 1;
                stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_7");

                // Create the ProgressDialog. This automatically displays the dialog
                progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

                // Set the properties of the ProgressDialog
                progressDialog.CancelEnabled = true;
                progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_8");
                progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_7");
                progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;

                //Create an edit operation enabling undo/redo
                if (logEditOperation)
                    editor.StartOperation();

                try
                {

                    topoOp = SplitPoint as ITopologicalOperator;
                    if (ignoreTolerence)
                    {
                        poly = topoOp.Buffer(Globals.ConvertFeetToMapUnits(.1, app)) as IPolygon;
                    }
                    else
                    {
                        poly = topoOp.Buffer(Globals.ConvertFeetToMapUnits(SplitAtLocationSnap, app)) as IPolygon;
                    }
                    foreach (IFeatureLayer lineLayer in lineLayers)
                    {

                        if (onlySelectedFeatures)
                        {
                            lineSel = lineLayer as IFeatureSelection;
                            lineSel.SelectionSet.Search(null, false, out lineCursor);
                            lineFCursor = lineCursor as IFeatureCursor;

                        }
                        else
                        {
                            pSpatFilt = new SpatialFilter();
                            pSpatFilt.GeometryField = lineLayer.FeatureClass.ShapeFieldName;
                            pSpatFilt.Geometry = poly;
                            pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                            lineFCursor = lineLayer.Search(pSpatFilt, false);
                            //lineFCursor = lineCursor as IFeatureCursor;
                        }

                        IList<MergeSplitFlds> pFldsNames = new List<MergeSplitFlds>();
                        string strFormValu = "{0:0.##}";
                        if (m_Config.Count > 0)
                        {
                            foreach (A4LGSharedFunctions.Field FldNam in m_Config[0].Fields)
                            {
                                int idx = Globals.GetFieldIndex(lineLayer.FeatureClass.Fields, FldNam.Name);
                                if (idx > -1)
                                    pFldsNames.Add(new MergeSplitFlds(FldNam.Name, idx, "", FldNam.MergeRule, FldNam.SplitRule));

                            }
                            strFormValu = m_Config[0].SplitFormatString;
                        }

                        lineFeature = lineFCursor.NextFeature();
                        while (!(lineFeature == null))
                        {
                            Globals.splitLineWithPoint(lineFeature, SplitPoint, SplitAtLocationSnap, pFldsNames, strFormValu,app);
                            //featureEdit = lineFeature as IFeatureEdit2;
                            //hitTest = lineFeature.ShapeCopy as IHitTest;
                            //pHitPnt = new PointClass();
                            //double pHitDist = -1;
                            //int pHitPrt = -1;
                            //int pHitSeg = -1;
                            //bool pHitSide = false;
                            //bool hit = hitTest.HitTest(SplitPoint, SplitAtLocationSnap, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, pHitDist, pHitPrt, pHitSeg, pHitSide);

                            //if (hit)
                            //{
                            //    if (ignoreTolerence == true && (pHitDist == 0.0 || pHitDist == -1.0))
                            //    {

                            //        //Split feature
                            //        topoOpEndStart = pHitPnt as ITopologicalOperator;
                            //        polyEndStart = topoOpEndStart.Buffer(SkipDistance) as IPolygon;
                            //        relOp = polyEndStart as IRelationalOperator;
                            //        curve = lineFeature.Shape as ICurve;
                            //        if (!(relOp.Contains(curve.FromPoint)) &&
                            //            !(relOp.Contains(curve.ToPoint)))
                            //        {
                            //            Globals.FlashGeometry(pHitPnt, Globals.GetColor(255, 0, 0), mxdoc.ActiveView.ScreenDisplay, 150);

                            //            double dblHighVal = 0;
                            //            double dblLowVal = 0;
                            //            int intHighIdx = -1;
                            //            int intLowIdx = -1;
                            //            foreach (MergeSplitFlds FldNam in pFldsNames)
                            //            {
                            //                FldNam.Value = lineFeature.get_Value(FldNam.FieldIndex).ToString();
                            //                if (FldNam.SplitType.ToUpper() == "MAX")
                            //                {
                            //                    if (FldNam.Value != null)
                            //                    {
                            //                        if (FldNam.Value != "")
                            //                        {

                            //                            dblHighVal = Convert.ToDouble(FldNam.Value);
                            //                            intHighIdx = FldNam.FieldIndex;
                            //                        }
                            //                    }
                            //                }
                            //                else if (FldNam.SplitType.ToUpper() == "MIN")
                            //                {
                            //                    if (FldNam.Value != null)
                            //                    {
                            //                        if (FldNam.Value != "")
                            //                        {

                            //                            dblLowVal = Convert.ToDouble(FldNam.Value);
                            //                            intLowIdx = FldNam.FieldIndex;
                            //                        }
                            //                    }
                            //                }

                            //            }
                            //            if (intHighIdx > -1 && intLowIdx > -1)
                            //            {
                            //                double len = ((ICurve)(lineFeature.Shape as IPolyline)).Length;

                            //                double splitDist = Globals.PointDistanceOnLine(pHitPnt, lineFeature.Shape as IPolyline, 2, out pHitPnt);
                            //                double percentSplit = splitDist / len;
                            //                double dblMidVal;
                            //                if (m_Config[0].SplitFormatString == "")
                            //                {
                            //                    dblMidVal = dblLowVal + ((dblHighVal - dblLowVal) * percentSplit);
                            //                }
                            //                else
                            //                {
                            //                    dblMidVal = Convert.ToDouble(string.Format(m_Config[0].SplitFormatString, dblLowVal + ((dblHighVal - dblLowVal) * percentSplit)));

                            //                }

                            //                //Split feature
                            //                pSet = featureEdit.SplitWithUpdate(pHitPnt);

                            //                if (pSet.Count == 1)
                            //                {
                            //                    while ((pSplitResFeat = pSet.Next() as IFeature) != null)
                            //                    {
                            //                        if ((pSplitResFeat.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
                            //                        {
                            //                            pSplitResFeat.set_Value(intHighIdx, dblMidVal);
                            //                        }
                            //                        else if ((pSplitResFeat.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
                            //                        {
                            //                            pSplitResFeat.set_Value(intLowIdx, dblMidVal);

                            //                        }
                            //                    }

                            //                }
                            //                if ((lineFeature.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
                            //                {
                            //                    lineFeature.set_Value(intHighIdx, dblMidVal);
                            //                }
                            //                else if ((lineFeature.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
                            //                {
                            //                    lineFeature.set_Value(intLowIdx, dblMidVal);

                            //                }
                            //            }
                            //            else
                            //                featureEdit.SplitWithUpdate(pHitPnt);

                            //            //mxdoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, hitTest, mxdoc.ActiveView.Extent);
                            //            mxdoc.ActiveView.Refresh();

                            //            //mxdoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, curve, mxdoc.ActiveView.Extent);
                            //        }

                            //        topoOpEndStart = null;
                            //        polyEndStart = null;
                            //        relOp = null;
                            //        curve = null;

                            //    }
                            //    else if (ignoreTolerence == false)
                            //    {

                            //        //Split feature
                            //        topoOpEndStart = pHitPnt as ITopologicalOperator;
                            //        polyEndStart = topoOpEndStart.Buffer(SkipDistance) as IPolygon;
                            //        relOp = polyEndStart as IRelationalOperator;
                            //        curve = lineFeature.ShapeCopy as ICurve;
                            //        if (!(relOp.Contains(curve.FromPoint)) &&
                            //            !(relOp.Contains(curve.ToPoint)))
                            //        {
                            //            //Split feature
                            //            Globals.FlashGeometry(pHitPnt, Globals.GetColor(255, 0, 0), mxdoc.ActiveView.ScreenDisplay, 150);

                            //            double dblHighVal = 0;
                            //            double dblLowVal = 0;
                            //            int intHighIdx = -1;
                            //            int intLowIdx = -1;
                            //            foreach (MergeSplitFlds FldNam in pFldsNames)
                            //            {
                            //                FldNam.Value = lineFeature.get_Value(FldNam.FieldIndex).ToString();
                            //                if (FldNam.SplitType.ToUpper() == "MAX")
                            //                {
                            //                    if (FldNam.Value != null)
                            //                    {
                            //                        if (FldNam.Value != "")
                            //                        {

                            //                            dblHighVal = Convert.ToDouble(FldNam.Value);
                            //                            intHighIdx = FldNam.FieldIndex;
                            //                        }
                            //                    }
                            //                }
                            //                else if (FldNam.SplitType.ToUpper() == "MIN")
                            //                {
                            //                    if (FldNam.Value != null)
                            //                    {
                            //                        if (FldNam.Value != "")
                            //                        {

                            //                            dblLowVal = Convert.ToDouble(FldNam.Value);
                            //                            intLowIdx = FldNam.FieldIndex;
                            //                        }
                            //                    }
                            //                }

                            //            }
                            //            if (intHighIdx > -1 && intLowIdx > -1)
                            //            {
                            //                double len = ((ICurve)(lineFeature.Shape as IPolyline)).Length;

                            //                double splitDist = Globals.PointDistanceOnLine(pHitPnt, lineFeature.Shape as IPolyline, 2, out pHitPnt);
                            //                double percentSplit = splitDist / len;
                            //                double dblMidVal;
                            //                if (m_Config[0].SplitFormatString == "")
                            //                {
                            //                    dblMidVal = dblLowVal + ((dblHighVal - dblLowVal) * percentSplit);
                            //                }
                            //                else
                            //                {
                            //                    dblMidVal = Convert.ToDouble(string.Format(m_Config[0].SplitFormatString, dblLowVal + ((dblHighVal - dblLowVal) * percentSplit)));

                            //                }

                            //                //Split feature
                            //                pSet = featureEdit.SplitWithUpdate(pHitPnt);

                            //                if (pSet.Count == 1)
                            //                {
                            //                    while ((pSplitResFeat = pSet.Next() as IFeature) != null)
                            //                    {
                            //                        if ((pSplitResFeat.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
                            //                        {
                            //                            pSplitResFeat.set_Value(intHighIdx, dblMidVal);
                            //                        }
                            //                        else if ((pSplitResFeat.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (pSplitResFeat.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
                            //                        {
                            //                            pSplitResFeat.set_Value(intLowIdx, dblMidVal);

                            //                        }
                            //                    }

                            //                }
                            //                if ((lineFeature.ShapeCopy as IPolyline).FromPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).FromPoint.Y == pHitPnt.Y)
                            //                {
                            //                    lineFeature.set_Value(intHighIdx, dblMidVal);
                            //                }
                            //                else if ((lineFeature.ShapeCopy as IPolyline).ToPoint.X == pHitPnt.X && (lineFeature.ShapeCopy as IPolyline).ToPoint.Y == pHitPnt.Y)
                            //                {
                            //                    lineFeature.set_Value(intLowIdx, dblMidVal);

                            //                }
                            //            }
                            //            else
                            //                featureEdit.SplitWithUpdate(pHitPnt);
                            //        }

                            //        topoOpEndStart = null;
                            //        polyEndStart = null;
                            //        relOp = null;
                            //        curve = null;

                            //    }
                            //}
                            if (lineFeature != null)
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(lineFeature);
                            }
                            lineFeature = lineFCursor.NextFeature();
                        }
                        if (lineCursor != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(lineCursor);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(lineFCursor);

                    }

                    //Update progress bar
                    i += 1;
                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_8");
                    ESRI.ArcGIS.esriSystem.IStatusBar statusBar = app.StatusBar;
                    statusBar.set_Message(0, i.ToString());
                }
                catch (Exception ex)
                {

                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1"));
                    if (logEditOperation)
                        editor.AbortOperation();

                    return;
                }
                finally
                {
                    progressDialog.HideDialog();

                }

                //Stop the edit operation
                if (logEditOperation)
                    editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_9"));

            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsRealName_1"));
                return;
            }
            finally
            {

                if (progressDialog != null)
                    progressDialog.HideDialog();
                if (SplitSuspendAA.ToUpper() == "TRUE")
                {
                    pCmd = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app);
                    if (pCmd != null)
                    {
                        pCmd.Execute();
                    }
                }
                pCmd = null;
                progressDialog = null;
                progressDialogFactory = null;
                trackCancel = null;
                stepProgressor = null;
                mxdoc = null;
                editor = null;
                eLayers = null;
                map = null;
                fLayer = null;
                fSel = null;
                geoFeatureLayerID = null;
                enumLayer = null;
                layer = null;
                lineLayers = null;

                pSpatFilt = null;
                lineCursor = null;
                lineFCursor = null;
                topoOp = null;

                poly = null;
                lineSel = null;
                lineFeature = null;
                //featureEdit = null;
                //hitTest = null;
                //pHitPnt = null;
                //topoOpEndStart = null;
                //polyEndStart = null;
                //relOp = null;
                //curve = null;

            }
        }
 private static void calcStandMeans(IFeatureClass strataFtr, IFeatureClass standsFtr, int[] meanStrataFldIndex, int[] varStrataFldIndex, int[] countFldStrataIndex, IField[] fldsToSummarize, geoDatabaseUtility geoUtil)
 {
     int cnt = 0;
     int[] ptFldIndex = new int[fldsToSummarize.Length];
     int[] meanFldIndex = new int[fldsToSummarize.Length];
     int[] varFldIndex = new int[fldsToSummarize.Length];
     int[] cntFldIndex = new int[fldsToSummarize.Length];
     foreach (IField fld in fldsToSummarize)
     {
         string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
         varFldIndex[cnt] = standsFtr.FindField(sName);
         string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
         meanFldIndex[cnt] = standsFtr.FindField(mName);
         string cName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
         cntFldIndex[cnt] = standsFtr.FindField(cName);
         cnt++;
     }
     IFeatureCursor uCur = standsFtr.Update(null, true);
     IFeature uFtr = uCur.NextFeature();
     while (uFtr != null)
     {
         ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
         ISpatialFilter spFlt = new SpatialFilter();
         spFlt.Geometry = geo;
         spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
         double totalArea = 0;
         IFeatureCursor sCur = strataFtr.Search(spFlt, true);
         IFeature sFtr = sCur.NextFeature();
         double[][] vlArr = new double[meanFldIndex.Length][];
         for (int i = 0; i < meanFldIndex.Length; i++)
         {
             vlArr[i] = new double[3];
         }
         while (sFtr != null)
         {
             ESRI.ArcGIS.Geometry.IGeometry sgeo = sFtr.Shape;
             ESRI.ArcGIS.Geometry.ITopologicalOperator4 topo = (ESRI.ArcGIS.Geometry.ITopologicalOperator4)sgeo;
             ESRI.ArcGIS.Geometry.IGeometry sgeo2 = topo.Intersect(geo, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
             double subArea = (((ESRI.ArcGIS.Geometry.IArea)sgeo2).Area);
             totalArea += subArea;
             for (int i = 0; i < meanFldIndex.Length; i++)
             {
                 vlArr[i][0] += System.Convert.ToDouble(sFtr.get_Value(meanStrataFldIndex[i])) * subArea;
                 vlArr[i][1] += System.Convert.ToDouble(sFtr.get_Value(varStrataFldIndex[i])) * subArea;
                 vlArr[i][2] += System.Convert.ToDouble(sFtr.get_Value(countFldStrataIndex[i]));
             }
             sFtr = sCur.NextFeature();
         }
         System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
         if (totalArea != 0)
         {
             for (int i = 0; i < meanFldIndex.Length; i++)
             {
                 uFtr.set_Value(meanFldIndex[i], vlArr[i][0]/totalArea);
                 uFtr.set_Value(varFldIndex[i], vlArr[i][1]/totalArea);
                 uFtr.set_Value(cntFldIndex[i], vlArr[i][2]);
             }
             uCur.UpdateFeature(uFtr);
         }
         uFtr = uCur.NextFeature();
     }
     System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
 }
        public bool HasParallelCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
      double AngleToleranceTangentCompareInDegrees, double OrthogonalSearchDistance,
       out int outFoundLinesCount, out int outFoundParallelCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundLinesCount = 0;
              outFoundParallelCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pNormalLine = new Line(); //new
              for (int i = -1; i < 2; i = i + 2)
              {
            double dOffset = OrthogonalSearchDistance * i;

            inPolycurve.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, dOffset, pNormalLine);
            ILine pThisLine = new Line();

            pThisLine.PutCoords(pNormalLine.FromPoint, pNormalLine.ToPoint);
            pGeomColl.AddGeometry(pThisLine);

            //Although each line is connected to the other, create a new path for each line
            //this allows for future changes in case the input needs to be altered to separate paths.

            ISegmentCollection newPath = new PathClass();
            object obj = Type.Missing;
            newPath.AddSegment((ISegment)pThisLine, ref obj, ref obj);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref obj, ref obj);
              }

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = pGeomBag;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }

              IFeature pFeat = pFeatCursLines.NextFeature();
              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            if (dRadius == 0)
            {//null or zero radius so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            val = pFeat.get_Value(idxCenterPointID);
            if (val == DBNull.Value)
            {//null centrpointID so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            ITopologicalOperator6 pTopoOp6 = (ITopologicalOperator6)MultiPartPolyLine;
            IGeometry pResultGeom = pTopoOp6.IntersectEx(pFoundLineGeom, false, esriGeometryDimension.esriGeometry0Dimension);
            if (pResultGeom == null)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            if (pResultGeom.IsEmpty)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            bool bHasCurves = false;
            pFoundLineGeomSegs.HasNonLinearSegments(ref bHasCurves);
            if (!bHasCurves)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            IPointCollection5 PtColl = (IPointCollection5)pResultGeom;

            if (PtColl.PointCount > 1)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            IPolycurve pPolyCurve4Tangent = pFoundLineGeom as IPolycurve;

            for (int j = 0; j < PtColl.PointCount; j++)
            {
              IPoint p = PtColl.get_Point(j);
              IPoint outPoint = new Point();
              double dDistanceAlong = 0;
              double dDistanceFromCurve = 0;
              bool bOffsetRight = true;

              //work out if the point is to the left or right of the original
              inPolycurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOffsetRight);

              ILine pTangent = new Line();
              dDistanceAlong = 0;
              dDistanceFromCurve = 0;
              bool bOnRight = true;

              pPolyCurve4Tangent.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOnRight);
              pPolyCurve4Tangent.QueryTangent(esriSegmentExtension.esriNoExtension, dDistanceAlong, false, 100, pTangent);

              //compare the tangent bearing with the normal to check for orthogonality
              IVector3D vecTangent = new Vector3DClass();
              vecTangent.PolarSet(pTangent.Angle, 0, 1);

              IVector3D vecNormal = new Vector3DClass();
              vecNormal.PolarSet(pNormalLine.Angle, 0, 1);

              ILine pHitDistanceForRadiusDifference = new Line();
              pHitDistanceForRadiusDifference.PutCoords(pNormalLine.FromPoint, outPoint);
              double dRadiusDiff = pHitDistanceForRadiusDifference.Length;

              double dDotProd = vecTangent.DotProduct(vecNormal);
              double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
              dAngleCheck = Math.Abs(dAngleCheck - 90);

              if (dAngleCheck < AngleToleranceTangentCompareInDegrees)
              {
            //work out concavity orientation with respect to the original line using the radius sign and dot product
            dDotProd = vecOriginalSelected.DotProduct(vecTangent);
            double dTangentCheck = Math.Acos(dDotProd) * 180 / Math.PI; // in degrees
            //dTangentCheck at this point should be close to 0 or 180 degrees.
            outFoundLinesCount++;

            bool bIsConvex = ((dTangentCheck < 90 && dRadius < 0 && !bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius > 0 && !bOffsetRight) ||
                              (dTangentCheck < 90 && dRadius > 0 && bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius < 0 && bOffsetRight));

            double dUnitSignChange = 1;

            if (!bIsConvex)
              dUnitSignChange = -1;

            double dDerivedRadius = (Math.Abs(dRadius)) + dRadiusDiff * dUnitSignChange;

            dUnitSignChange = 1;
            //now compute inferred left/right for candidate
            if (bIsConvex && !bOffsetRight)
              dUnitSignChange = -1;

            if (!bIsConvex && bOffsetRight)
              dUnitSignChange = -1;

            dDerivedRadius = dDerivedRadius * dUnitSignChange;

            string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
              iCtrPoint.ToString() + "," + dRadiusDiff.ToString("#.000");
            CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);
              }
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              bool bHasParallelCurveFeaturesNearby = (outFoundLinesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
Esempio n. 54
0
 /// <summary>
 /// 空间属性查询
 /// </summary>
 /// <params name="geom">查询对象</params>
 /// <params name="sql">sql语句</params>
 /// <params name="featurelyr">图层</params>
 /// <returns>返回查询结果集合</returns>
 public IFeatureCursor SpatialSearch(IGeometry geom, string sql, IFeatureLayer featurelyr, esriSpatialRelEnum rel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects)
 {
     IFeatureClass featureclass = featurelyr.FeatureClass;
     IFeatureCursor feacursor = null;
     if (featureclass != null)
     {
         ISpatialFilter filter = new SpatialFilter();
         filter.Geometry = geom;
         filter.WhereClause = sql;
         filter.SpatialRel = rel;
         feacursor = featureclass.Search(filter, false);
     }
     return feacursor;
 }
        public static void summarizeBiomassPolygon(IFeatureClass pointFtr, IField[] fldsToSummarize, IFeatureClass strataFtr, IFeatureClass standsFtr = null, geoDatabaseUtility geoUtil=null )
        {
            if(geoUtil==null) geoUtil = new geoDatabaseUtility();
            int cnt = 0;
            int[] ptFldIndex = new int[fldsToSummarize.Length];
            int[] meanFldIndex = new int[fldsToSummarize.Length];
            int[] varFldIndex = new int[fldsToSummarize.Length];
            int[] cntFldIndex = new int[fldsToSummarize.Length];
            foreach (IField fld in fldsToSummarize)
            {

                ptFldIndex[cnt] = pointFtr.FindField(fld.Name);
                string sName = geoUtil.createField(strataFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                varFldIndex[cnt] = strataFtr.FindField(sName);
                string mName = geoUtil.createField(strataFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                meanFldIndex[cnt] = strataFtr.FindField(mName);
                string cntName = geoUtil.createField(strataFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeInteger, false);
                cntFldIndex[cnt] = strataFtr.FindField(cntName);
                cnt++;
            }
            IFeatureCursor uCur = strataFtr.Update(null, true);
            IFeature uFtr = uCur.NextFeature();
            while (uFtr != null)
            {
                ISpatialFilter sFilt = new SpatialFilter();
                sFilt.Geometry = uFtr.Shape;
                sFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                double[][] fldVlsArr = new double[fldsToSummarize.Length][];
                for (int i = 0; i < fldsToSummarize.Length; i++)
                {
                    fldVlsArr[i] = new double[3];
                }
                IFeatureCursor psCur = pointFtr.Search(sFilt, true);
                IFeature psFtr = psCur.NextFeature();

                while (psFtr != null)
                {
                    for (int i = 0; i < ptFldIndex.Length; i++)
                    {
                        int indexVl = ptFldIndex[i];
                        object objVl = psFtr.get_Value(indexVl);
                        if (objVl != null)
                        {
                            double vl = System.Convert.ToDouble(objVl);
                            double vl2 = vl*vl;
                            fldVlsArr[i][0] += vl;
                            fldVlsArr[i][1] += vl2;
                            fldVlsArr[i][2] += 1;
                        }
                    }
                    psFtr = psCur.NextFeature();
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(psCur);
                for (int i = 0; i < ptFldIndex.Length; i++)
                {
                    double s = fldVlsArr[i][0];
                    double s2 = fldVlsArr[i][1];
                    double n = fldVlsArr[i][2];
                    double mean = s / n;//mean
                    double var = (s2 - (Math.Pow(s, 2) / n)) / (n - 1);//variance
                    int mIndex = meanFldIndex[i];
                    int vIndex = varFldIndex[i];
                    int cntIndex = cntFldIndex[i];
                    uFtr.set_Value(mIndex, mean);
                    uFtr.set_Value(vIndex, var);
                    uFtr.set_Value(cntIndex, n);
                }
                uCur.UpdateFeature(uFtr);
                uFtr = uCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
            if (standsFtr != null)
            {
                calcStandMeans(strataFtr, standsFtr, meanFldIndex, varFldIndex, cntFldIndex, fldsToSummarize,geoUtil);
            }
        }
Esempio n. 56
0
        private bool SpatialSelect(string sClassName, string sMinX, string sMinY, string sMaxX, string sMaxY)
        {
            IObjectClass pOC;
            ITable pTable;
            IFeatureWorkspace pFWKS;
            ISpatialFilter pSQF;
            ISelectionSet2 pSelSet;
            IFeatureClass pFC;
            IEnvelope pEnv;

            this.Logger.WriteLine("Spatial Select by Attribute");
            try
            {
                try
                {
                    pFWKS = (IFeatureWorkspace)Workspace;
                    pOC = (IObjectClass)pFWKS.OpenTable(sClassName);
                    try
                    {
                        pFC = (IFeatureClass)pOC;
                        pSQF = new SpatialFilter();
                        pSQF.GeometryField = pFC.ShapeFieldName;
                        pEnv = new EnvelopeClass();
                        pEnv.PutCoords(System.Convert.ToDouble(sMinX), System.Convert.ToDouble(sMinY), System.Convert.ToDouble(sMaxX), System.Convert.ToDouble(sMaxY));
                        pTable = (ITable)pOC;
                        try
                        {
                            SW1.Reset();
                            SW1.Start();
                            pSelSet = (ISelectionSet2)pTable.Select(pSQF, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, Workspace);
                            SW1.Stop();
                            RecordActionTime("SpatialSelect Features (" + pSelSet.Count + ")" , SW1.ElapsedMilliseconds);
                            return true;
                        }
                        catch (Exception EX)
                        {
                            this.Logger.WriteLine("Failed to query class:" + EX.Message);
                            return false;
                        }
                    }
                    catch (Exception EX2)
                    {
                        this.Logger.WriteLine("Failed to obtain Field:" + EX2.Message);
                        return false;
                    }
                }
                catch (Exception EX)
                {
                    this.Logger.WriteLine("Failed to open Class:" + EX.Message);
                    return false;
                }
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("Failed:" + EX.Message);
                return false;
            }
        }
        public bool HasTangentCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
  double AngleToleranceTangentCompareInDegrees, double StraightLinesBreakLessThanInDegrees, double MaximumDeltaInDegrees, double ExcludeTangentsShorterThan, 
      out int outFoundTangentCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundTangentCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pTangentLineAtEnd = new Line(); //new
              ILine pTangentLineAtStart = new Line(); //new
              object objMissing = Type.Missing;

              for (int i = 0; i < 2; i++)
              {
            ILine pThisLine = null;
            if (i == 0)
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 0.2, pTangentLineAtEnd);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtEnd.FromPoint, pTangentLineAtEnd.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            else
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 0.2, pTangentLineAtStart);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtStart.FromPoint, pTangentLineAtStart.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            //Create a new path for each line.

            ISegmentCollection newPath = new PathClass();
            newPath.AddSegment((ISegment)pThisLine, ref objMissing, ref objMissing);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref objMissing, ref objMissing);
              }

              //now buffer the lines
              IGeometryCollection outBufferedGeometryCol = new GeometryBagClass();
              for (int jj = 0; jj < geometryCollection2.GeometryCount; jj++)
              {
            IPath pPath = geometryCollection2.get_Geometry(jj) as IPath;
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);

            ITopologicalOperator topologicalOperator = (ITopologicalOperator)pPolyL;
            IPolygon pBuffer = topologicalOperator.Buffer(0.1) as IPolygon;
            outBufferedGeometryCol.AddGeometry(pBuffer, ref objMissing, ref objMissing);
              }
              ITopologicalOperator pUnionedBuffers = null;
              pUnionedBuffers = new PolygonClass() as ITopologicalOperator;
              pUnionedBuffers.ConstructUnion((IEnumGeometry)outBufferedGeometryCol);

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = (IGeometry)pUnionedBuffers;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }
              IVector3D vecFoundGeom = new Vector3DClass();
              IFeature pFeat = pFeatCursLines.NextFeature();
              bool bHasTangentStraightLineAtJunction = false;
              List<int> lstLargeBreak = new List<int>();

              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;
            IPolycurve pFoundLineAsPolyCurve = pFoundLineGeom as IPolycurve;
            int iRelativeOrientation = GetRelativeOrientation(pFoundLineAsPolyCurve, inPolycurve);
            //iRelativeOrientation == 1 --> closest points are original TO and found TO
            //iRelativeOrientation == 2 --> closest points are original TO and found FROM
            //iRelativeOrientation == 3 --> closest points are original FROM and found TO
            //iRelativeOrientation == 4 --> closest points are original FROM and found FROM

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            val = pFeat.get_Value(idxCenterPointID);

            IPolycurve pPolyCurve = pFoundLineGeom as IPolycurve;

            ILine pFoundChordCandidate = new LineClass();
            pFoundChordCandidate.PutCoords(pPolyCurve.FromPoint, pPolyCurve.ToPoint);
            //first check for liklihood that subject line is supposed to stay straight, by
            //geometry chord bearing angle break test
            vecFoundGeom.PolarSet(pFoundChordCandidate.Angle, 0, 1);
            double dDotProd = vecFoundGeom.DotProduct(vecOriginalSelected);
            double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            double dLargeAngleBreakInDegrees = 3;
            if (dAngleCheck > dLargeAngleBreakInDegrees && dAngleCheck < (180 - dLargeAngleBreakInDegrees)) //large angle break non-tangent, greater than 3 degrees
            {
              if (!lstLargeBreak.Contains(iRelativeOrientation))
            lstLargeBreak.Add(iRelativeOrientation);
            }

            if ((dAngleCheck <= StraightLinesBreakLessThanInDegrees || (180 - dAngleCheck) < StraightLinesBreakLessThanInDegrees)
            && val == DBNull.Value && dRadius == 0 && !(pPolyCurve.Length< ExcludeTangentsShorterThan))
            {
              if (lstLargeBreak.Contains(iRelativeOrientation))
            bHasTangentStraightLineAtJunction = true;
            }

            if (val == DBNull.Value || dRadius == 0 || pPolyCurve.Length< ExcludeTangentsShorterThan)
            {//if the feature has a null centrpointID then skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            if (Math.Abs(inPolycurve.Length / dRadius * 180 / Math.PI) > MaximumDeltaInDegrees)
            {
              //if the resulting curve would have a central angle more than MaximumDeltaInDegrees degrees then skip
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            //if geometry of curve neighbour curves have been cracked then there can be more than one segment
            //however since all segments would be circular arcs, just need to test the first segment
            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            ISegment pSeg = pFoundLineGeomSegs.get_Segment(0);
            if (!(pSeg is ICircularArc))
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            dRadius = (double)pFeat.get_Value(idxRadius);

            IVector3D vect1 = new Vector3DClass();
            IVector3D vect2 = new Vector3DClass();
            ILine tang = new Line();
            double dUnitSignChange = 1;
            if (iRelativeOrientation == 1) //closest points are original TO and found TO
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 2)//closest points are original TO and found FROM
            {
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 3)//closest points are original FROM and found TO
            {
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 4)//closest points are original FROM and found FROM
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }

            dDotProd = vect1.DotProduct(vect2);
            dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            if (dAngleCheck < AngleToleranceTangentCompareInDegrees || (180 - dAngleCheck) < AngleToleranceTangentCompareInDegrees)
            {

              double dDerivedRadius = dRadius * dUnitSignChange;

              string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
            iCtrPoint.ToString() + "," + "t";
              CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);

              outFoundTangentCurvesCount++;
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              if (bHasTangentStraightLineAtJunction)
            return false; //open to logic change to be less conservative

              bool bHasParallelCurveFeaturesNearby = (outFoundTangentCurvesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
        public void weightFieldValuesByAreaLength(IFeatureClass strataFtr, string[] fldNames, IFeatureClass standsFtr, bool length = false)
        {
            int[] meanFldIndex = new int[fldNames.Length];
            int[] fldNamesIndex = new int[fldNames.Length];
            for (int i = 0; i < fldNames.Length; i++)
            {
                string mName = geoUtil.createField(standsFtr, "m_" + fldNames[i], ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble, false);
                meanFldIndex[i] = standsFtr.FindField(mName);
                fldNamesIndex[i] = strataFtr.FindField(fldNames[i]);
            }
            IFeatureCursor uCur = standsFtr.Update(null, true);
            IFeature uFtr = uCur.NextFeature();
            while (uFtr != null)
            {
                ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
                ISpatialFilter spFlt = new SpatialFilter();
                spFlt.Geometry = geo;
                spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                double totalVl = 0;
                IFeatureCursor sCur = strataFtr.Search(spFlt, true);
                IFeature sFtr = sCur.NextFeature();
                double[] vlArr = new double[meanFldIndex.Length];
                while (sFtr != null)
                {
                    ESRI.ArcGIS.Geometry.IGeometry sgeo = sFtr.Shape;
                    ESRI.ArcGIS.Geometry.ITopologicalOperator4 topo = (ESRI.ArcGIS.Geometry.ITopologicalOperator4)sgeo;
                    ESRI.ArcGIS.Geometry.IGeometry sgeo2 = topo.Intersect(geo, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
                    double subArea = 0;
                    if (length)
                    {
                        subArea = (((ESRI.ArcGIS.Geometry.IPolygon)sgeo2).Length);
                        totalVl += subArea;
                    }
                    else
                    {
                        subArea = ((ESRI.ArcGIS.Geometry.IArea)sgeo2).Area;
                        totalVl += subArea;
                    }

                    for (int i = 0; i < meanFldIndex.Length; i++)
                    {
                        vlArr[i] += System.Convert.ToDouble(sFtr.get_Value(fldNamesIndex[i])) * subArea;
                    }
                    sFtr = sCur.NextFeature();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
                if (totalVl != 0)
                {
                    for (int i = 0; i < meanFldIndex.Length; i++)
                    {
                        uFtr.set_Value(meanFldIndex[i], vlArr[i] / totalVl);
                    }
                    uCur.UpdateFeature(uFtr);
                }
                uFtr = uCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
        }
        public double RotatePoint(IMap pMap, IFeature pPointFeature, bool bArithmeticAngle, string strDiameterFld, string strLayerName)
        {
            IFeatureClass pPointFC = default(IFeatureClass);
            ISpatialFilter pSFilter = default(ISpatialFilter);
            IFeatureCursor pLineCursor = default(IFeatureCursor);
            IFeature pLineFeature = default(IFeature);
            IPoint pPoint = default(IPoint);
            IEnumLayer pEnumLayer = default(IEnumLayer);
            ILayer pLayer = default(ILayer);
            IFeatureLayer pFLayer = default(IFeatureLayer);
            UID pId = new UID();
            UID pUID = new UID();
            ITopologicalOperator pTopo = null;

            List<Double> cAngles = new List<Double>();
            List<string> pLstInt = new List<string>();
            List<double> cDiameters = new List<double>();

            double dblAngle = 0;
            double dblDiameter = 0;
            double ltest = 0;
            int iLineDiameterFieldPos = 0;
            try
            {
            //This routine is used by both RotateDuringCreateFeature and RotateSelectedFeature.
            //It contains all of logic for determining the rotation angle.

            const int iAngleTol = 5;
            //Used for Tees> a straight line is 180 + or - iAngleTol

                pPointFC = (IFeatureClass)pPointFeature.Class;
            pPoint = (IPoint)pPointFeature.Shape;

            //Create spatial filter to find intersecting features at this given point
            pTopo = (ITopologicalOperator)pPoint;

            pSFilter = new SpatialFilter();
            pSFilter.Geometry = pTopo.Buffer(0.5);
            //pPoint
            pSFilter.GeometryField = pPointFC.ShapeFieldName;
            pSFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            //Step through each feature layer
            pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            //GeoFeatureLayer
            pEnumLayer = (IEnumLayer)pMap.get_Layers(pUID, true);
            pEnumLayer.Reset();
            pLayer = (ILayer)pEnumLayer.Next();

            while ((pLayer != null))
            {
                //Verify that this is a line layer
                pFLayer = (IFeatureLayer)pLayer;

                if (pFLayer.FeatureClass != null)
                {

                    if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFLayer.Visible && (strLayerName == "" || strLayerName == Globals.getClassName((IDataset)pFLayer.FeatureClass)))
                    {
                        //Apply the filter this line layer
                        pLineCursor = pFLayer.FeatureClass.Search(pSFilter, true);

                        //Loop through the found lines for this layer
                        pLineFeature = pLineCursor.NextFeature();
                        while ((pLineFeature != null))
                        {
                            if (pLstInt.Count > 0)
                            {
                                if (pLstInt.Contains(pLineFeature.Class.ObjectClassID + " " + pLineFeature.OID))
                                {
                                    pLineFeature = pLineCursor.NextFeature();
                                    continue;
                                }
                            }
                            pLstInt.Add(pLineFeature.Class.ObjectClassID.ToString() + " " + pLineFeature.OID.ToString());

                            dblAngle = Globals.GetAngleOfLineAtPoint((IPolyline)pLineFeature.ShapeCopy, (IPoint)pPointFeature.ShapeCopy, Globals.GetXYTolerance(pPointFeature));
                            dblAngle = Globals.ConvertRadsToDegrees(dblAngle);

                            //Convert to geographic degrees(zero north clockwise)
                            if (!(bArithmeticAngle))
                            {
                                dblAngle = Globals.ConvertArithmeticToGeographic(dblAngle);
                            }
                            //Round angle
                            dblAngle = Math.Round(dblAngle, 4);

                            //Find diameter field, if it exists
                            iLineDiameterFieldPos = pFLayer.FeatureClass.FindField(strDiameterFld);

                            //Get diameter of line
                            if (iLineDiameterFieldPos < 0)
                            {
                                dblDiameter = -9999;
                            }
                            else if (pLineFeature.get_Value(iLineDiameterFieldPos) == null)
                            {
                                dblDiameter = -9999;
                            }
                            else if (object.ReferenceEquals(pLineFeature.get_Value(iLineDiameterFieldPos), DBNull.Value))
                            {
                                dblDiameter = -9999;
                            }
                            else
                            {
                                Double.TryParse(pLineFeature.get_Value(iLineDiameterFieldPos).ToString(), out dblDiameter);

                            }

                            //add this line (angle and diameter) to a collection of line info for this point
                            cAngles.Add(dblAngle);

                            if (dblDiameter != -9999)
                            {
                                cDiameters.Add(dblDiameter);
                            }

                            //Get next line
                            pLineFeature = pLineCursor.NextFeature();
                        }
                    }
                }
                //Get next line layer
                pLayer = pEnumLayer.Next();
            }

            //Read the collection of line segment angles and diameters
            //and use them to derive a symbol rotation angle for the point
            switch (cAngles.Count)
            {
                case 0:
                    //One line such as at valves

                    return 0.0;

                case 1:
                    //One line such as at valves
                    return cAngles[0];
                case 2:
                    //Two lines such as at reducers Or at tee fittings where line is not broken

                    if (cDiameters.Count == 2)
                    {
                        //If cDiameters(0) Is Nothing Or cDiameters(1) Is Nothing Then
                        //    Return cAngles.Item(0)
                        //Else
                        if (cDiameters[0] > cDiameters[1])
                        {
                            return cAngles[1];
                            //If cAngles.Item(0) = cAngles.Item(1) Then
                            //    Return cAngles.Item(1)
                            //Else
                            //    Return cAngles.Item(1) - 180
                            //End If

                        }
                        else
                        {
                            return cAngles[0];
                            //If cAngles.Item(0) = cAngles.Item(1) Then
                            //    Return cAngles.Item(0) - 180
                            //Else
                            //    Return cAngles.Item(1)
                            //End If
                        }
                    }
                    else
                    {
                        return cAngles[0];
                    }

                    break;
                case 3:
                    //Three lines such as at tee fittings where line is broken
                    ltest = Math.Abs(cAngles[0] - cAngles[1]);
                    if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                    {
                        return cAngles[2];
                    }
                    else
                    {
                        ltest = Math.Abs(cAngles[0] - cAngles[2]);
                        if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                        {
                            return cAngles[1];
                        }
                        else
                        {
                            ltest = Math.Abs(cAngles[1] - cAngles[2]);
                            if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                            {
                                return cAngles[0];
                            }
                            else
                            {
                                return -360;
                            }
                        }
                    }
                    break;
                case 4:
                    //Four lines such as at crosses
                    //the angle of any of the four lines should work since the symbol should be symetrically
                    return cAngles[0];
                default:
                    return 0;
            }

            //Clear collections
            }
            catch
            {
                return 0;
            }
            finally
            {

                 pPointFC = null;
                 pSFilter = null;
                 pLineCursor = null;
                 pLineFeature = null;
                 pPoint = null;
                 pEnumLayer = null;
                 pLayer = null;
                 pFLayer = null;
                 pId = null;
                 pUID = null;
                 pTopo = null;

                 cAngles.Clear();
                 pLstInt.Clear();
                cDiameters.Clear();

            }
        }
Esempio n. 60
0
        private ReadOnlyCollection<AGraphElement> Searching(IRTreeDataContainer element, SpatialFilter spatialPredicate, SpatialFilter dataContainerPredicate)
        {
            var stack = new Stack<ARTreeContainer>();
            var currentResult = new List<AGraphElement>();
            if (spatialPredicate(_root, element))
                stack.Push(_root);
            while (stack.Count > 0)
            {
                var currentContainer = stack.Pop();

                if (!currentContainer.IsLeaf)
                {
                    foreach (var value in ((RTreeNode)currentContainer).Children)
                    {
                        if (spatialPredicate(value, element))
                            stack.Push(value);
                    }
                }
                else
                {
                    foreach (var value in ((RTreeLeaf)currentContainer).Data)
                    {
                        if (dataContainerPredicate(value, element))
                        {

                            currentResult.Add(value.GraphElement);
                        }

                    }
                }
            }

            return currentResult.AsReadOnly();
        }