Beispiel #1
0
        /// <summary>
        /// Pans to geometry.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="pGeometry">The p geometry.</param>
        /// <param name="isFlash">if set to <c>true</c> [is flash].</param>
        /// <param name="mMap"></param>
        public static void PanToGeometry(IActiveView view, IGeometry pGeometry, bool isFlash, IMap m_map)
        {
            if (pGeometry.IsEmpty == true)
            {
                return;
            }
            IEnvelope pEnv    = pGeometry.Envelope;
            IEnvelope pExtent = view.Extent;

            if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                pExtent.CenterAt((IPoint)pGeometry);
            }
            else
            {
                IPoint pPnt = new PointClass();
                pPnt.X = (pEnv.XMin + pEnv.XMax) / 2;
                pPnt.Y = (pEnv.YMin + pEnv.YMax) / 2;
                pExtent.CenterAt(pPnt);
                pPnt = null;
            }
            view.Extent = pExtent;
            view.Refresh();
            MapHelper.FlashGeometry(pGeometry, m_map);
        }
Beispiel #2
0
        private void EyeMap_MouseUp(object sender, MouseEventArgs e)
        {
            if (m_MapControl == null)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            IEnvelope pEnvelope = m_MapControl.Extent;
            Size      size      = new Size();

            size.Width  = (int)(e.X - m_pStratPt.X);
            size.Height = (int)(e.Y - m_pStratPt.Y);
            if (Math.Abs(size.Width) < 2 && Math.Abs(size.Height) < 2)//如果鼠标移动范围过小,当做点击定位
            {
                POINT pt = new POINT();
                pt.X = (int)e.X; pt.Y = (int)e.Y;
                IPoint point = EyeMap2Ctrl(pt);
                pEnvelope.CenterAt(point);
            }
            else//相应拖动鼠标事件
            {
                POINT pt = new POINT();
                pt.X = (int)e.X; pt.Y = (int)e.Y;
                IPoint point = EyeMap2Ctrl(pt);
                pEnvelope.CenterAt(point);
                //SIZE dMapSize = MapExtent2Rect(size);
                // pEnvelope.Offset(dMapSize.cX, dMapSize.cY);
            }

            m_MapControl.Extent = pEnvelope;
        }
Beispiel #3
0
        public override void OnMouseUp(int int_0, int int_1, int int_2, int int_3)
        {
            IActiveView focusMap;
            double      mapUnits;

            if (this.bool_0)
            {
                IEnvelope envelope = null;
                if (this.idisplayFeedback_0 != null)
                {
                    envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                    if ((envelope.IsEmpty || envelope.Width == 0 ? true : envelope.Height == 0))
                    {
                        focusMap        = this._context.FocusMap as IActiveView;
                        envelope        = this.ipoint_0.Envelope;
                        mapUnits        = Common.ConvertPixelsToMapUnits(focusMap, 8);
                        envelope.Height = mapUnits;
                        envelope.Width  = mapUnits;
                        envelope.CenterAt(this.ipoint_0);
                    }
                }
                else
                {
                    focusMap        = this._context.FocusMap as IActiveView;
                    envelope        = this.ipoint_0.Envelope;
                    mapUnits        = Common.ConvertPixelsToMapUnits(focusMap, 8);
                    envelope.Height = mapUnits;
                    envelope.Width  = mapUnits;
                    envelope.CenterAt(this.ipoint_0);
                }
                envelope.SpatialReference = this._context.FocusMap.SpatialReference;


                IActiveView               activeView              = this._context.FocusMap as IActiveView;
                IErrorFeatureContainer    topology                = CmdSelectTopology.m_TopologyLayer.Topology as IErrorFeatureContainer;
                IGeoDataset               geoDataset              = CmdSelectTopology.m_TopologyLayer.Topology as IGeoDataset;
                ITopologyErrorSelection   mTopologyLayer          = CmdSelectTopology.m_TopologyLayer as ITopologyErrorSelection;
                IEnumTopologyErrorFeature errorFeaturesByRuleType = topology.ErrorFeaturesByRuleType[geoDataset.SpatialReference, esriTopologyRuleType.esriTRTAny, envelope, mTopologyLayer.SelectErrors, mTopologyLayer.SelectExceptions];
                FixTopologyErrorTool.m_pTopoErroeSelection.Clear();
                for (ITopologyErrorFeature i = errorFeaturesByRuleType.Next(); i != null; i = errorFeaturesByRuleType.Next())
                {
                    FixTopologyErrorTool.m_pTopoErroeSelection.Add(new TopologyError(CmdSelectTopology.m_TopologyLayer, i));
                }
                this.method_0();
                activeView.Refresh();
                this.idisplayFeedback_0 = null;
                this.bool_0             = false;
            }
        }
        public void RefreshDisplay(double latitude, double longitude, double percent)
        {
            if (MxDocument == null)
            {
                throw new InvalidOperationException("MxDocument not set");
            }

            GetObjectFactoryOrFail();

            //IPoint center = new PointClass();
            var center = (IPoint)_objectFactory.Create("esriGeometry.Point");

            center.PutCoords(longitude, latitude);
            center.SpatialReference = Wgs84;
            center.Project(MxDocument.FocusMap.SpatialReference);

            var       map     = ((IActiveView)MxDocument.FocusMap);
            IEnvelope extents = map.Extent;

            extents.Expand(percent, percent, true); //If percent is less than one it will shrink
            if (((IRelationalOperator)center).Within(extents))
            {
                map.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
            else
            {
                extents = map.Extent;
                extents.CenterAt(center);
                map.Extent = extents;
                map.Refresh();
            }
        }
Beispiel #5
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IEnvelope envelope = null;

            if (axMapControl1.Map.LayerCount != 0 && m_mapControl != null)
            {
                // 按下鼠标左键移动矩形框
                if (e.button == 1)
                {
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);
                    envelope = m_mapControl.Extent;
                    envelope.CenterAt(pPoint);
                }
                // 按下鼠标右键绘制矩形框
                else if (e.button == 2)
                {
                    envelope = this.axMapControl1.TrackRectangle();
                }
                m_mapControl.Extent = envelope;
                m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
 public void OnClick()
 {
     if (_view.SelectedItemType == esriTOCControlItem.esriTOCControlItemLayer && _view.SelectedLayer != null)
     {
         IActiveView pActiveView = _view.SelectedMap as IActiveView;
         if (pActiveView != null)
         {
             if (_view.SelectedLayer is IFeatureLayer)
             {
                 ICursor           pCursor;
                 IFeatureSelection featureSelection = _view.SelectedLayer as IFeatureSelection;
                 if (featureSelection != null)
                 {
                     featureSelection.SelectionSet.Search(null, false, out pCursor);
                     IRow      i      = pCursor.NextRow();
                     IEnvelope extent = (i as IFeature).Extent;
                     while ((i = pCursor.NextRow()) != null)
                     {
                         extent.Union((i as IFeature).Extent);
                     }
                     IPoint point = new PointClass();
                     point.PutCoords((extent.XMin + extent.XMax) / 2, (extent.YMin + extent.YMax) / 2);
                     IEnvelope envelope = pActiveView.Extent;
                     envelope.CenterAt(point);
                     pActiveView.Extent = envelope;
                     pActiveView.Refresh();
                 }
             }
         }
     }
 }
Beispiel #7
0
 public static IEnvelope GetSearchEnvelope(IActiveView pActiveView, IPoint pPoint)
 {
     try
     {
         double    num           = 6.0;
         IEnvelope visibleBounds = null;
         if (pActiveView != null)
         {
             IDisplayTransformation displayTransformation = pActiveView.ScreenDisplay.DisplayTransformation;
             visibleBounds = displayTransformation.VisibleBounds;
             tagRECT deviceFrame = displayTransformation.get_DeviceFrame();
             double  height      = 0.0;
             long    num3        = 0L;
             height = visibleBounds.Height;
             num3   = deviceFrame.bottom - deviceFrame.top;
             double num4 = 0.0;
             num4 = height / ((double)num3);
             num *= num4;
         }
         if (pPoint == null)
         {
             return(null);
         }
         visibleBounds        = pPoint.Envelope;
         visibleBounds.Width  = num;
         visibleBounds.Height = num;
         visibleBounds.CenterAt(pPoint);
         return(visibleBounds);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #8
0
        private void PanToFlash()
        {
            try
            {
                IFeature  selectedFeature = GetCurrentFeature();
                IGeometry geometry        = selectedFeature.Shape;
                IPoint    pCenterPoint    = new PointClass();
                double    x = (geometry.Envelope.LowerLeft.X + geometry.Envelope.UpperRight.X) / 2;
                double    y = (geometry.Envelope.LowerLeft.Y + geometry.Envelope.UpperRight.Y) / 2;
                pCenterPoint.PutCoords(x, y);

                IDisplayTransformation pDisplayTransform = m_activeView.ScreenDisplay.DisplayTransformation;
                IEnvelope pEnvelope = pDisplayTransform.VisibleBounds;
                pEnvelope.CenterAt(pCenterPoint);
                pDisplayTransform.VisibleBounds = pEnvelope;

                //m_map.SelectFeature(currentLayer, selectedFeature);

                m_activeView.PartialRefresh((esriViewDrawPhase)6, null, m_activeView.Extent);
                m_activeView.ScreenDisplay.UpdateWindow();

                ISymbol symbol = CreateSimpleSsymbol(geometry.GeometryType);
                if (symbol == null)
                {
                    return;
                }
                DrawSymbol(symbol, geometry);
            }
            catch (Exception)
            {
                return;
            }
        }
Beispiel #9
0
        private void LoadPage(PageInfoWrap infoWrap)
        {
            if (isRunning)
            {
                return;
            }
            propertyPage.SelectedObject = infoWrap.PrintPageInfo;

            IActiveView pActiveView = _context.FocusMap as IActiveView;

            pActiveView.ScreenDisplay.DisplayTransformation.Rotation = btnRotatePage.Checked ? infoWrap.PrintPageInfo.Angle : 0;
            IPoint    centerPoint = new ESRI.ArcGIS.Geometry.Point();
            IEnvelope pEnv        = infoWrap.PrintPageInfo.Boundary.Envelope;

            centerPoint.PutCoords(pEnv.XMin + pEnv.Width / 2.0, pEnv.YMin + pEnv.Height / 2.0);
            IEnvelope pExtentEnv = pActiveView.Extent;

            pExtentEnv.CenterAt(centerPoint);
            pActiveView.Extent = pExtentEnv;
            pActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio = infoWrap.PrintPageInfo.Scale;
            pActiveView.Refresh();
            if (_context.MainView.ControlType != GISControlType.PageLayout)
            {
                return;
            }
            LoadPrintPage(infoWrap.PrintPageInfo);
            MessageService.Current.Info("Refresh");
            pActiveView.Extent = pExtentEnv;
            pActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio = infoWrap.PrintPageInfo.Scale;
            pActiveView.Refresh();
        }
Beispiel #10
0
        /// <summary>
        /// 实现几个图形聚焦
        /// </summary>
        /// <param name="pActiveView">操作的活动视图</param>
        /// <param name="pGeometry">几何图形</param>
        public void ZoomToGeo(IActiveView pActiveView, IGeometry pGeometry)
        {
            switch (pGeometry.GeometryType)//根据不同图形作不同设置
            {
            case esriGeometryType.esriGeometryPoint:
            {
                IEnvelope pEnv = default(IEnvelope);
                pEnv = pActiveView.Extent;
                pEnv.CenterAt((IPoint)pGeometry);        //改变外界矩形封套的中心锚点位置(点的特殊操作)
                pActiveView.Extent = pEnv;
                break;
            }

            case esriGeometryType.esriGeometryPolyline:
            case esriGeometryType.esriGeometryPolygon:
            {
                pActiveView.Extent = pGeometry.Envelope;
                break;
            }

            default:
            {
                pActiveView.Extent = pGeometry.Envelope;
                break;
            }
            }

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, pActiveView.Extent);
        }
Beispiel #11
0
        private static void m_RealTimeFeedEvents_Event_PositionUpdated(ref esriGpsPositionInfo position, bool estimate)
        {
            CurrentGpsPositionInfoIsValid = true;
            CurrentGpsPositionInfo        = position;
            IPoint p = new PointClass();

            if (m_CurrentPosition == null)
            {
                m_CurrentPosition = new PointClass();
                m_CurrentPosition.SpatialReference = m_RealTimeFeedManager.RealTimeFeed.SpatialReference;
            }
            m_CurrentPosition.PutCoords(position.longitude, position.latitude);
            p.PutCoords(position.longitude, position.latitude);
            p.SpatialReference = m_RealTimeFeedManager.RealTimeFeed.SpatialReference;
            if ((m_RealTimeFeedManager.Map != null) && (m_RealTimeFeedManager as IGpsDisplayProperties).AutoPan)
            {
                IActiveView map = m_RealTimeFeedManager.Map as IActiveView;
                if (
                    !((p.SpatialReference is IUnknownCoordinateSystem) ||
                      (m_RealTimeFeedManager.Map.SpatialReference is IUnknownCoordinateSystem)))
                {
                    p.Project(m_RealTimeFeedManager.Map.SpatialReference);
                }
                IEnvelope extent = map.Extent;
                extent.CenterAt(p);
                map.Extent = extent;
                map.Refresh();
            }
            OnGpsPositionUpdated(position);
        }
Beispiel #12
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);
        }
        public void OnClick()
        {
            if (m_pHookHelper == null)
            {
                return;
            }

            //Get the active view
            IActiveView pActiveView = (IActiveView)m_pHookHelper.FocusMap;

            //Get the extent
            IEnvelope pEnvelope = (IEnvelope)pActiveView.Extent;

            //Create a point to pan to
            IPoint pPoint;

            pPoint   = new PointClass();
            pPoint.X = ((pEnvelope.XMin + pEnvelope.XMax) / 2) - (pEnvelope.Height / (100 / GetPanFactor()));
            pPoint.Y = ((pEnvelope.YMin + pEnvelope.YMax) / 2);

            //Center the envelope on the point
            pEnvelope.CenterAt(pPoint);

            //Set the new extent
            pActiveView.Extent = pEnvelope;

            //Refresh the active view
            pActiveView.Refresh();
        }
Beispiel #14
0
        public static IFeature GetHitLineFeature(IPoint inPoint, IMap pMap, double torelance)
        {
            IFeature  feature  = null;
            double    mapUnits = CommonHelper.ConvertPixelsToMapUnits(pMap as IActiveView, torelance);
            IEnvelope envelope = inPoint.Envelope;

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

            for (int i = 0; i < pMap.LayerCount; i++)
            {
                IFeatureLayer layer = pMap.Layer[i] as IFeatureLayer;
                if (layer != null && layer.Visible &&
                    layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    spatialFilterClass.GeometryField = layer.FeatureClass.ShapeFieldName;
                    IFeatureCursor featureCursor = layer.Search(spatialFilterClass, false);
                    QueryHelper.GetClosestSelectedFeature(inPoint, featureCursor, out feature);
                    ComReleaser.ReleaseCOMObject(featureCursor);
                }
            }
            return(feature);
        }
        private void lvResults_DoubleClick(object sender, EventArgs e)
        {
            foreach (ListViewItem selectedItem in lvResults.SelectedItems)
            {
                var tag = selectedItem.Tag as object[];

                if ((tag != null) && (tag.Length >= 2) && (selectedItem.SubItems.Count >= 1))
                {
                    var         feature               = tag[0] as IFeature;
                    var         cycloMediaLayer       = tag[1] as CycloMediaLayer;
                    IActiveView activeView            = ArcUtils.ActiveView;
                    ListViewItem.ListViewSubItem item = selectedItem.SubItems[0];

                    if ((feature != null) && (cycloMediaLayer != null) && (activeView != null) && (item != null))
                    {
                        var point = feature.Shape as IPoint;

                        if (point != null)
                        {
                            string imageId = item.Text;
                            FrmGlobespotter.ShowLocation(imageId, cycloMediaLayer);
                            IEnvelope envelope = activeView.Extent;
                            envelope.CenterAt(point);
                            activeView.Extent = envelope;
                            activeView.Refresh();
                        }
                    }
                }
            }
        }
        //回退操作
        private void  Undo()
        {
            if (m_pUndoArray.Count > 1)
            {
                m_pEnvelope = CommonFunction.GetMinEnvelopeOfTheArray(m_pUndoArray);
            }
            else if (m_pUndoArray.Count == 1)
            {
                IPoint pTempPoint = new PointClass();
                pTempPoint.X = (m_pUndoArray.get_Element(0) as Point).X;
                pTempPoint.Y = (m_pUndoArray.get_Element(0) as Point).Y;

                m_pEnvelope.Width  = Math.Abs(m_pPoint.X - pTempPoint.X);
                m_pEnvelope.Height = Math.Abs(m_pPoint.Y - pTempPoint.Y);

                pTempPoint.X = (pTempPoint.X + m_pPoint.X) / 2;
                pTempPoint.Y = (pTempPoint.Y + m_pPoint.Y) / 2;

                m_pEnvelope.CenterAt(pTempPoint);
            }
            if (m_pEnvelope != null && !m_pEnvelope.IsEmpty)
            {
                m_pEnvelope.Expand(10, 10, false);
            }
            ;

            m_pUndoArray.Remove(m_pUndoArray.Count - 1);//删除数组中最后一个点
            m_mouseDownCount--;

            //屏幕刷新
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, m_pEnvelope);
            m_pActiveView.ScreenDisplay.UpdateWindow();

            //开始作复位工作
            if (m_pUndoArray.Count != 0)
            {
                CommonFunction.DisplaypSegmentColToScreen(m_MapControl, ref m_pUndoArray);

                m_pLastPoint = (IPoint)m_pUndoArray.get_Element(m_pUndoArray.Count - 1);

                m_pFeedback         = new NewLineFeedbackClass();
                m_pLineFeed         = (NewLineFeedback)m_pFeedback;
                m_pLineFeed.Display = m_pActiveView.ScreenDisplay;
                if (m_pLineFeed != null)
                {
                    m_pLineFeed.Stop();
                }
                m_pLineFeed.Start(m_pLastPoint);

                m_MapControl.ActiveView.GraphicsContainer.DeleteAllElements();
                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, m_pLastPoint);
                m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_pEnvelope);                //视图刷新
            }
            else
            {  //复位
                m_pFeedback.MoveTo(m_pAnchorPoint);
                Reset();
            }
        }
Beispiel #17
0
        public event EventHandler <FeatureClickEventArgs> FeatureClick;//声明小区点击事件

        /// <summary>
        /// 将地图定位到指定点
        /// </summary>
        /// <param name="p">指定点</param>
        public void LocateToPoint(IPoint p)
        {
            ILayer    referLayer = GISMapApplication.Instance.GetLayer(LayerNames.Projecton);//定位居中参照图层。
            IEnvelope pEnvelope  = referLayer.AreaOfInterest;

            pEnvelope.CenterAt(p);
            pEnvelope.Expand(0.15, 0.15, true);
            GISMapApplication.Instance.FullExtent(pEnvelope);
        }
Beispiel #18
0
        public static void setElementPosition(AxPageLayoutControl axPageLayoutControl, IElement pElement, IPoint pPoint)
        {
            IPageLayout pageLayout = axPageLayoutControl.PageLayout;
            IActiveView activeView = pageLayout as IActiveView;
            IEnvelope   pEnvelope  = pElement.Geometry.Envelope;

            pEnvelope.CenterAt(pPoint);
            pElement.Geometry = pEnvelope;
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Beispiel #19
0
        public static void AddAndVisualizeTreelistBackground(TreeList parentTree, IMapControl2 mapControl1)
        {
            try
            {
                if (mapControl1 == null)
                {
                    return;
                }
                IMapDocument pMapDoc   = new MapDocument();
                string       pFileName = Config.GetConfigValue("2DMxdBackground");//获得背景图文件路径
                if (string.IsNullOrEmpty(pFileName) || !File.Exists(pFileName))
                {
                    return;
                }
                SplashScreenManager.Default.SendCommand(null, "正在加载二维基础数据......");
                pMapDoc.Open(pFileName, null);                        //打开地图
                IMap          pMap      = pMapDoc.get_Map(0);         //获得地图
                List <ILayer> loadLayer = new List <ILayer>();        //初始化待加载地理信息图层list
                int           layerNum  = mapControl1.Map.LayerCount; //获得当前主地图控件的图层数
                for (int i = 0; i < pMap.LayerCount; i++)             //对地图的图层进行遍历
                {
                    ILayer layer = pMap.get_Layer(i);
                    AddComLayerNode(parentTree, rootNode, layer, loadLayer);//为图层树控件加载新图层,并将待加载图层写入loadLayer
                    rootNode.CollapseAll();
                }
                if (loadLayer.Count > 0)
                {
                    foreach (ILayer layer in loadLayer)
                    {
                        mapControl1.AddLayer(layer, layerNum);
                        layerNum++;
                        //if (layer is IRasterLayer)
                        //{
                        //    mapControl2.AddLayer(layer);
                        //}
                    }
                    IEnvelope pEnv  = mapControl1.ActiveView.Extent;
                    IPoint    point = new ESRI.ArcGIS.Geometry.Point();
                    point.PutCoords((pEnv.XMax + pEnv.XMin) / 2, (pEnv.YMax + pEnv.YMin) / 2);

                    pEnv.CenterAt(point);
                    mapControl1.ActiveView.Extent = pEnv;
                    mapControl1.MapUnits          = pMap.MapUnits;
                    mapControl1.ReferenceScale    = pMap.ReferenceScale;
                    mapControl1.ActiveView.Refresh();
                }
            }
            catch (System.Exception ex)
            {
                return;
            }
        }
Beispiel #20
0
        void OnDynamicMapStarted(IDisplay Display, IDynamicDisplay dynamicDisplay)
        {
            lock (m_bikePositionInfo)
            {
                // update the bike position
                if (m_bikePositionInfo.positionCount != m_bikePositionCount)
                {
                    // update the geometry
                    m_gpsPosition.PutCoords(m_bikePositionInfo.position.X, m_bikePositionInfo.position.Y);

                    // check if needed to update the map extent
                    if (m_bTrackMode)
                    {
                        IEnvelope mapExtent = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FittedBounds;
                        mapExtent.CenterAt(m_gpsPosition);
                        m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds = mapExtent;
                    }

                    // update the bike trail
                    m_wksPoints[0] = m_bikePositionInfo.position;
                    m_geometryBridge.AddWKSPoints(m_bikeRouteGeometry, ref m_wksPoints);

                    // get the GPS altitude reading
                    m_altitudeString = string.Format("Altitude: {0} m", m_bikePositionInfo.altitudeMeters.ToString("####.#"));

                    if (m_playbackFormat == GPSPlaybackFormat.HST)
                    {
                        // calculate the heading
                        m_heading  = Math.Atan2(m_bikePositionInfo.position.X - m_wksPrevPosition.X, m_bikePositionInfo.position.Y - m_wksPrevPosition.Y);
                        m_heading *= (180 / Math.PI);
                        if (m_heading < 0)
                        {
                            m_heading += 360;
                        }

                        m_heartRateString = string.Format("{0} BPM", m_bikePositionInfo.heartRate);
                    }
                    else
                    {
                        m_heading = m_bikePositionInfo.course;
                        m_speed   = string.Format("Speed: {0} MPH", m_bikePositionInfo.speed.ToString("###.#"));
                    }

                    m_wksPrevPosition.X = m_bikePositionInfo.position.X;
                    m_wksPrevPosition.Y = m_bikePositionInfo.position.Y;
                    m_bikePositionCount = m_bikePositionInfo.positionCount;
                }
            }

            // explicitly call refresh in order to make the dynamic display fire AfterDynamicDraw event
            m_hookHelper.ActiveView.Refresh();
        }
Beispiel #21
0
        //鹰眼地图:左键拖动矩形框、右键绘制矩形框
        private void axMapControlEagleMap_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (axMapControlEagleMap.Map.LayerCount == 0)
            {
                return;
            }
            //按下鼠标左键拖动矩形框
            if (e.button == 1)
            {
                IPoint point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(e.mapX, e.mapY);
                IEnvelope envelope = axMapControlMainMap.Extent;
                envelope.CenterAt(point);
                axMapControlMainMap.Extent = envelope;
                axMapControlMainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            //按下鼠标右键绘制矩形框
            else if (e.button == 2)
            {
                IEnvelope envelope = axMapControlEagleMap.TrackRectangle();

                //计算新显示框范围
                double newWidth  = 0;
                double newHeight = 0;
                if (envelope.IsEmpty)
                {
                    return;
                }
                if (envelope.Width / envelope.Height > axMapControlMainMap.ActiveView.Extent.Width / axMapControlMainMap.ActiveView.Extent.Height)
                {//宽相同
                    newWidth  = envelope.Width;
                    newHeight = envelope.Width * axMapControlMainMap.ActiveView.Extent.Height / axMapControlMainMap.ActiveView.Extent.Width;
                }
                else//高相同
                {
                    newHeight = envelope.Height;
                    newWidth  = envelope.Height * axMapControlMainMap.ActiveView.Extent.Width / axMapControlMainMap.ActiveView.Extent.Height;
                }

                double midX = (envelope.XMin + envelope.XMax) / 2;
                double midY = (envelope.YMin + envelope.YMax) / 2;
                double xmi  = midX - newWidth / 2;
                double xma  = midX + newWidth / 2;
                double ymi  = midY - newHeight / 2;
                double yma  = midY + newHeight / 2;
                envelope.PutCoords(xmi, ymi, xma, yma);

                axMapControlMainMap.Extent = envelope;
                axMapControlMainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
Beispiel #22
0
        /// <summary>
        /// 鸟瞰地图的红框体移动后,宿主程序地图视图发生改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IPoint cenpt = new PointClass();

            cenpt.PutCoords(e.mapX, e.mapY);
            IEnvelope pEleEnv = pEle.Geometry.Envelope;

            pEleEnv.CenterAt(cenpt);
            pEle.Geometry = (IGeometry)pEleEnv;

            hook.MapControl.Extent = pEleEnv;
            hook.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Beispiel #23
0
        private void EagleMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)//鹰眼图:左键拖动矩形框、右键绘制矩形框
        {
            if (EagleMapControl.Map.LayerCount == 0)
            {
                return;
            }
            if (e.button == 1) //按下鼠标左键拖动矩形框
            {
                IPoint point = new Point();
                point.PutCoords(e.mapX, e.mapY);
                IEnvelope envelope = MapControl.Extent;
                envelope.CenterAt(point);
                MapControl.Extent = envelope;
                MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            else if (e.button == 2)//按下鼠标右键绘制矩形框
            {
                IEnvelope envelope = EagleMapControl.TrackRectangle();
                IEnvelope extent   = MapControl.ActiveView.Extent;

                //计算新显示框范围
                double newWidth;
                double newHeight;
                if (envelope.IsEmpty)
                {
                    return;
                }
                if (envelope.Width / envelope.Height > extent.Width / extent.Height)
                {//宽相同
                    newWidth  = envelope.Width;
                    newHeight = envelope.Width * extent.Height / extent.Width;
                }
                else//高相同
                {
                    newHeight = envelope.Height;
                    newWidth  = envelope.Height * extent.Width / extent.Height;
                }

                double midX = (envelope.XMin + envelope.XMax) / 2;
                double midY = (envelope.YMin + envelope.YMax) / 2;
                double xmi  = midX - newWidth / 2;
                double xma  = midX + newWidth / 2;
                double ymi  = midY - newHeight / 2;
                double yma  = midY + newHeight / 2;
                envelope.PutCoords(xmi, ymi, xma, yma);

                MapControl.Extent = envelope;
                MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
Beispiel #24
0
 /// <summary>
 /// 平移到几何形状
 /// </summary>
 /// <param name="activeView">ESRI活动视图接口</param>
 /// <param name="geometry">平移到的ESRI几何形状接口</param>
 public static void PanToGeometry(IActiveView activeView, IGeometry geometry)
 {
     if (activeView != null && GeometryUtility.IsValidGeometry(geometry))
     {
         IPoint cp = GeometryUtility.GeometryCentroid(geometry);
         if (cp == null)
         {
             IEnvelope envelope = activeView.Extent;
             envelope.CenterAt(cp);
             activeView.Extent = envelope;
             activeView.Refresh();
         }
     }
 }
Beispiel #25
0
        public static bool IdentifyFeatureLayers(IBasicMap ibasicMap_0, IPoint ipoint_0, double double_0,
                                                 List <IFeatureLayer> list_0, out IList <object> ilist_0)
        {
            ilist_0 = new List <object>();
            IEnvelope envelope = ipoint_0.Envelope;

            envelope.Width  = double_0;
            envelope.Height = double_0;
            envelope.CenterAt(ipoint_0);
            foreach (IFeatureLayer list0 in list_0)
            {
                IdentifyHelper.FeatureLayerIdentify(ibasicMap_0, list0, envelope, ilist_0);
            }
            return(true);
        }
Beispiel #26
0
 public void LocateCheckError(IGeometry location)
 {
     if (location.GeometryType == esriGeometryType.esriGeometryPoint)
     {
         //ITopologicalOperator topo = location as ITopologicalOperator;
         //IGeometry buffer = topo.Buffer(10);
         IPoint    ptn = location as IPoint;
         IEnvelope env = this.axMapControl1.Extent;
         env.CenterAt(ptn);
         this.axMapControl1.Extent = env;
     }
     else
     {
         this.axMapControl1.Extent = location.Envelope;
     }
 }
Beispiel #27
0
        private void ZoomToCenter()
        {
            IEnvelope extent = (_context.FocusMap as IActiveView).Extent;
            IPoint    point  = this.ipointCollection_0.Point[this.int_2];

            if ((point.X > extent.XMax || point.Y > extent.YMax || point.X < extent.XMin
                ? false
                : point.Y >= extent.YMin))
            {
                (_context.FocusMap as IActiveView).Refresh();
            }
            else
            {
                extent.CenterAt(point);
                (_context.FocusMap as IActiveView).Extent = extent;
                (_context.FocusMap as IActiveView).Refresh();
            }
        }
Beispiel #28
0
        // 点选要素
        public static void SelectByPoint(AxMapControl axMapControl, int x, int y)
        {
            IActiveView pActiveView = axMapControl.ActiveView;
            IPoint      pPoint      = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            IEnvelope   pEnvelope   = pPoint.Envelope;

            double tolDistance = ConvertPixelsToMapUnits(pActiveView, SEARCHTOLPIXELS);

            pEnvelope.Width  = tolDistance;
            pEnvelope.Height = tolDistance;
            pEnvelope.CenterAt(pPoint);

            IGeometry pGeometry = pEnvelope as IGeometry;

            pGeometry.SpatialReference = axMapControl.Map.SpatialReference;
            axMapControl.Map.SelectByShape(pGeometry, null, false);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
        }
Beispiel #29
0
        private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //if (axMapControl2.Map.LayerCount > 0)
            //{

            //    if (e.button == 1)
            //    {

            //        IPoint pPoint = new PointClass();
            //        pPoint.PutCoords(e.mapX, e.mapY);
            //        axMapControl1.CenterAt(pPoint);
            //        axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            //    }
            //    else if (e.button == 2)
            //    {
            //        IEnvelope pEnv = axMapControl2.TrackRectangle();
            //        axMapControl1.Extent = pEnv;
            //        axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            //    }

            //}



            if (e.button == 1)
            {
                IPoint pPoint = new PointClass();
                pPoint.X = e.mapX;
                pPoint.Y = e.mapY;
                IEnvelope pEnvelop = axMapControl1.Extent as IEnvelope;
                pEnvelop.CenterAt(pPoint);
                //pPoint.PutCoords(e.mapX, e.mapY);
                //axMapControl1.CenterAt(pPoint);
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            else if (e.button == 2)
            {
                IEnvelope pEnv = axMapControl2.TrackRectangle();
                axMapControl1.Extent = pEnv;
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
Beispiel #30
0
        public static void PanToGeometry(IActiveView view, IGeometry geometry, bool setCenterAt = false)
        {
            IEnvelope env = view.Extent;

            IRelationalOperator operation = env as IRelationalOperator;

            logger.InfoEx($"Projeting to {view.FocusMap.SpatialReference.Name}");
            geometry.Project(view.FocusMap.SpatialReference);

            if (setCenterAt || !operation.Contains(geometry))
            {
                ISegmentCollection poly = new PolygonClass();
                IArea area = geometry.Envelope as IArea;
                env.CenterAt(area.Centroid);
                view.Extent = env;
                view.Refresh();
                view.ScreenDisplay.UpdateWindow();
            }
        }
        public void SetDynamicValues(IObject inObject, string mode)
        {
            IFeature inFeature = null;
            // IRow inRow = null;

            IMSegmentation mseg = null;
            INetworkFeature netFeat = null;
            IEdgeFeature edgeFeat = null;
            IFeature juncFeat;
            IJunctionFeature iJuncFeat;
            //ProgressBar
            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null;
            // Create a CancelTracker
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

            try
            {
                if (AAState._PerformUpdates && AAState._dv == null)
                {

                    AAState.WriteLine("Dynamic Value Table is missing - Name in Config:" + AAState._defaultsTableName);

                    //    MessageBox.Show("The Attribute Assistant is turned on, but the Dynamic Value table is missing, please add the table and toggle the extension on");
                    AAState._PerformUpdates = false;
                    return;
                }
                if (AAState._PerformUpdates && AAState._dv != null)
                {
                    if (inObject == null)
                        return;
                    //Convert row to feature (test for feature is null before using - this could be a table update)
                    inFeature = inObject as IFeature;
                    // inRow = inObject as IRow;
                    string modeVal;

                    if (AAState._dv.Table.Columns[mode].DataType == System.Type.GetType("System.String"))
                    {
                        modeVal = "(" + mode + " = '1' or " + mode + " = 'Yes' or " + mode + " = 'YES' or " + mode + " = 'True' or " + mode + " = 'TRUE')";

                    }
                    else
                    {
                        modeVal = mode + " = 1";
                    }
                    System.Int32 int32_hWnd = ArcMap.Application.hWnd;

                    progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
                    stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);

                    stepProgressor.MinRange = 0;
                    stepProgressor.MaxRange = inObject.Fields.FieldCount;
                    stepProgressor.StepValue = 1;
                    stepProgressor.Message = "Attribute Assistant Progress";
                    // 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 = "Checking rules for " + inObject.Class.AliasName;
                    progressDialog.Title = "Attribute Assistant Progress";
                    progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe;
                    progressDialog.ShowDialog();
                    //for each field in this row/feature
                    // Skip orphan junctions (saves time)

                    if (Globals.isOrpanJunction(inFeature))
                        return;
                    //Get table name for this feature
                    _currentDataset = inObject.Class as IDataset;
                    _currentDatasetNameItems = _currentDataset.Name.Split('.');
                    tableName = _currentDatasetNameItems[_currentDatasetNameItems.GetLength(0) - 1];

                    for (int fieldNum = 0; fieldNum <= inObject.Fields.FieldCount; fieldNum++)
                    {

                        stepProgressor.Step();
                        bool editable = true;
                        if (fieldNum == inObject.Fields.FieldCount)
                        {
                            fieldObj = null;

                            fieldName = "";
                            stepProgressor.Message = "Checking rules for field null fields in" + inObject.Class.AliasName;
                            progressDialog.Description = "Checking rules for field null fields in" + inObject.Class.AliasName;
                            AAState.WriteLine("***********************************************************");
                            AAState.WriteLine("");

                            AAState.WriteLine("############ " + DateTime.Now + " ################");
                            editable = true;
                            //  fieldNum++;

                        }
                        else
                        {
                            fieldObj = inObject.Fields.get_Field(fieldNum);

                            fieldName = fieldObj.Name;
                            stepProgressor.Message = "Checking rules for field " + fieldName + " in " + inObject.Class.AliasName;
                            progressDialog.Description = "Checking rules for field " + fieldName + " in " + inObject.Class.AliasName;
                            AAState.WriteLine("***********************************************************");
                            AAState.WriteLine("");
                            AAState.WriteLine("############ " + fieldName + " ################");
                            AAState.WriteLine("############ " + DateTime.Now + " ################");
                            AAState.WriteLine("Is field -  " + fieldName + " Editable = " + fieldObj.Editable);
                            editable = fieldObj.Editable;
                        }
                        bool proc = false;
                        if (editable == true && fieldObj != null)
                        {
                            AAState.WriteLine("Checking rules for field " + fieldName + " in " + inObject.Class.AliasName);

                            AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal;
                            //AAState._dv.rw
                            AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal);
                            if (AAState._dv.Count == 0)
                            {
                                AAState._dv.RowFilter = "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal;

                                AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                                AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal);
                            }
                            if (AAState._dv.Count == 0)
                            {
                                AAState.WriteLine("    No entries found");
                                proc = false;
                            }
                            else
                            {
                                proc = true;
                            }

                        }
                        //   else if (editable == false )
                        //{
                        //    AAState.WriteLine("Checking rules for field " + fieldName + " in " + inObject.Class.AliasName);

                        //    AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal;
                        //    //AAState._dv.rw
                        //    AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal);
                        //    if (AAState._dv.Count == 0)
                        //    {
                        //        AAState._dv.RowFilter = "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal;

                        //        AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                        //        AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal);
                        //    }
                        //    if (AAState._dv.Count == 0)
                        //    {
                        //        AAState.WriteLine("    No entries found");
                        //        proc = false;
                        //    }
                        //    else
                        //    {
                        //        proc = true;
                        //    }

                        //}
                        else if (editable && fieldObj == null)
                        {
                            fieldName = "";
                            AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal;
                            //AAState._dv.rw
                            AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal);
                            if (AAState._dv.Count == 0)
                            {
                                AAState._dv.RowFilter = "TABLENAME = '*' And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal;

                                AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                                AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal);
                            }
                            if (AAState._dv.Count == 0)
                            {
                                AAState.WriteLine("    No entries found");
                                proc = false;
                            }
                            else
                            {
                                proc = true;
                            }
                        }
                        if (proc)
                        {

                            AAState.WriteLine("          Value Entry Rows found: " + AAState._dv.Count);
                            AAState.WriteLine("          ----------------------------------------------");
                            // Get requested method and any data parameters
                            AAState.WriteLine("          Looping through Value Methods");
                            AAState.WriteLine("                  ------------------------");
                            foreach (DataRowView drv in AAState._dv)
                            {

                                AAState.WriteLine("                  Checking for Subtype Restriction");
                                valFC = drv["TABLENAME"].ToString().Trim();
                                if (valFC.Contains("|"))
                                {
                                    AAState.WriteLine("                  Subtype restriction Found");
                                    string[] spliVal = valFC.Split('|');

                                    if (Globals.IsInteger(spliVal[1]))
                                    {
                                        int SubVal = Convert.ToInt32(spliVal[1]);
                                        ISubtypes pSub = inObject.Class as ISubtypes;
                                        if (pSub != null)
                                        {
                                            if (pSub.HasSubtype)
                                            {
                                                int obSubVal = (int)inObject.get_Value(pSub.SubtypeFieldIndex);
                                                if (obSubVal == SubVal)
                                                {
                                                    AAState.WriteLine("                  Subtypes match");
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  Skipping, not the subtype defined");
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                AAState.WriteLine("                  ERROR: Layer does not have subtypes");
                                            }
                                        }
                                        else
                                        {
                                            AAState.WriteLine("                  ERROR: Layer does not have subtypes");
                                        }
                                    }
                                    else
                                    {
                                        AAState.WriteLine("                  ERROR: Subtype not an integar");
                                    }
                                }
                                valMethod = drv["VALUEMETHOD"].ToString().ToUpper().Trim();
                                valData = drv["VALUEINFO"].ToString().Trim();

                                AAState.WriteLine("                  VALUEMETHOD: " + valMethod);
                                AAState.WriteLine("                  VALUEINFO: " + valData);
                                AAState.WriteLine("                  ------------------------");
                                //set field value based on specified method
                                try
                                {
                                    switch (valMethod)
                                    {
                                        case "SPLIT_INTERSECTING_FEATURE":
                                            {
                                                AAState.WriteLine("                  Trying: SPLIT_INTERSECTING_FEATURE");

                                                try
                                                {
                                                    if ((valData != null) && (inFeature != null))
                                                    {
                                                        intersectLayerName = "";
                                                        intersectLayer = null;
                                                        args = valData.Split('|');
                                                        if (args.Length > 0)
                                                        {
                                                            AAState.WriteLine("                  " + args.Length + " Layers listed ");

                                                            for (int i = 0; i < args.Length; i++)
                                                            {

                                                                intersectLayerName = args[i].Trim();
                                                                AAState.WriteLine("                  Searching for " + intersectLayerName);

                                                                intersectLayer = Globals.FindLayer(AAState._editor.Map, intersectLayerName) as IFeatureLayer;

                                                                if (intersectLayer != null)
                                                                {
                                                                    AAState.WriteLine("                  Layer Found " + intersectLayerName);
                                                                    if (intersectLayer.FeatureClass != null)
                                                                    {
                                                                        AAState.WriteLine("                  Datasource is valid for " + intersectLayerName);

                                                                        sFilter = new SpatialFilterClass();
                                                                        AAState.WriteLine("                  Checking source Geometry Type");

                                                                        if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                        {
                                                                            // esriSpatialRelIntersects does not work properly for point intersecting line.
                                                                            // hence expand point envelope (code cribbed from below)
                                                                            try
                                                                            {
                                                                                ISpatialReferenceResolution pSRResolution;

                                                                                pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;

                                                                                //  sFilter = new SpatialFilterClass();
                                                                                double intTol = pSRResolution.get_XYResolution(false);
                                                                                bool hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();

                                                                                searchEnvelope = new EnvelopeClass();
                                                                                searchEnvelope.XMin = 0 - intTol;
                                                                                searchEnvelope.YMin = 0 - intTol;
                                                                                searchEnvelope.XMax = 0 + intTol;
                                                                                searchEnvelope.YMax = 0 + intTol;
                                                                                searchEnvelope.CenterAt(inFeature.ShapeCopy as IPoint);

                                                                                //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                searchEnvelope.SnapToSpatialReference();
                                                                                searchEnvelope.Project(AAState._editor.Map.SpatialReference);

                                                                                sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                            }
                                                                            catch
                                                                            {
                                                                                sFilter.Geometry = inFeature.ShapeCopy;
                                                                            }

                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Geoemetry is not a point, using shape envelope");

                                                                            sFilter.Geometry = inFeature.ShapeCopy;
                                                                        }
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                        sFilter.GeometryField = intersectLayer.FeatureClass.ShapeFieldName;
                                                                        AAState.WriteLine("                  Searching " + intersectLayerName + "for intersected feature");

                                                                        fCursor = intersectLayer.FeatureClass.Search(sFilter, true);
                                                                        IFeature intsersectFeature;
                                                                        int idx = 1;
                                                                        while ((intsersectFeature = fCursor.NextFeature()) != null)
                                                                        {
                                                                            AAState.WriteLine("                  Splitting Intersected Feature number: " + idx);
                                                                            idx++;

                                                                            IFeatureEdit featureEdit = intsersectFeature as IFeatureEdit;
                                                                            ISet featset = featureEdit.Split(inFeature.Shape);
                                                                            AAState.WriteLine("                  Adding split features to array to call the AA ext");

                                                                            if (featset.Count > 0)
                                                                            {
                                                                                if (newFeatureList == null)
                                                                                {
                                                                                    newFeatureList = new List<IObject>();
                                                                                }
                                                                                object featobj;
                                                                                while ((featobj = featset.Next()) != null)
                                                                                {
                                                                                    IFeature feature = featobj as IFeature;
                                                                                    if (feature != null)
                                                                                    {
                                                                                        newFeatureList.Add(feature as IObject);
                                                                                    }
                                                                                }
                                                                            }
                                                                            AAState.WriteLine("                  Split feature " + intersectLayerName + " into " + featset.Count);
                                                                            if (intsersectFeature != null)
                                                                            {
                                                                                Marshal.ReleaseComObject(intsersectFeature);
                                                                            }

                                                                        }
                                                                    }
                                                                }

                                                                else
                                                                {
                                                                    AAState.WriteLine("                  Warning: Can't find intersecting layer: " + intersectLayerName);
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Unsupported Value Info: " + valData);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: not a feature or no Value Info");
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: SPLIT_INTERSECTING_FEATURE" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: SPLIT_INTERSECTING_FEATURE");
                                                }
                                                break;
                                            }

                                        case "NEAREST_FEATURE_ATTRIBUTES":
                                            {
                                                AAState.WriteLine("                  Trying NEAREST_FEATURE_ATTRIBUTES");
                                                try
                                                {
                                                    if ((valData != null) && (inFeature != null))
                                                    {
                                                        sourceLayerName = "";
                                                        string[] sourceFieldNames = null;
                                                        string[] destFieldNames = null;
                                                        searchDistance = 0;

                                                        // Parse arguments
                                                        args = valData.Split('|');
                                                        if (args.Length == 3)
                                                        {
                                                            sourceLayerName = args[0].ToString().Trim();
                                                            sourceFieldNames = args[1].ToString().Split(',');
                                                            destFieldNames = args[2].ToString().Split(',');
                                                            AAState.WriteLine("                  WARNING:  search distance as not specified, defaulting to 0");

                                                        }
                                                        else if (args.Length == 4)
                                                        {
                                                            sourceLayerName = args[0].ToString().Trim();
                                                            sourceFieldNames = args[1].ToString().Split(',');
                                                            destFieldNames = args[2].ToString().Split(',');
                                                            Double.TryParse(args[3], out searchDistance);
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR:  the valuemethod is not defined properly for this rule");
                                                            continue;

                                                        }

                                                        if ((sourceFieldNames != null) && (destFieldNames != null) &&
                                                            (sourceFieldNames.Length > 0) && (destFieldNames.Length > 0) &&
                                                            (sourceFieldNames.Length == destFieldNames.Length))
                                                        {
                                                            AAState.WriteLine("                  Looking for layer: " + sourceLayerName);

                                                            sourceLayer = Globals.FindLayer(AAState._editor.Map, sourceLayerName) as IFeatureLayer;
                                                            if (sourceLayer != null)
                                                            {
                                                                if (sourceLayer.FeatureClass != null)
                                                                {
                                                                    AAState.WriteLine("                  layer Found: " + sourceLayerName);

                                                                    string missingFieldMess = null;
                                                                    int[] sourceFieldNums = new int[sourceFieldNames.Length];
                                                                    int[] destFieldNums = new int[destFieldNames.Length];
                                                                    AAState.WriteLine("                  Checking Field Mapping");

                                                                    for (int i = 0; i < sourceFieldNums.Length; i++)
                                                                    {
                                                                        int fnum = sourceLayer.FeatureClass.FindField(sourceFieldNames[i].Trim());
                                                                        if (fnum < 0)
                                                                        {
                                                                            missingFieldMess = sourceFieldNames[i].Trim() + " in table " + sourceLayerName;
                                                                            break;
                                                                        }
                                                                        sourceFieldNums[i] = fnum;
                                                                    }
                                                                    if (missingFieldMess == null)
                                                                    {
                                                                        for (int i = 0; i < destFieldNums.Length; i++)
                                                                        {
                                                                            int fnum = inFeature.Fields.FindField(destFieldNames[i].Trim());
                                                                            if (fnum < 0)
                                                                            {
                                                                                missingFieldMess = destFieldNames[i].Trim() + " in table " + tableName;
                                                                                break;
                                                                            }
                                                                            destFieldNums[i] = fnum;
                                                                        }
                                                                    }
                                                                    if (missingFieldMess == null)
                                                                    {
                                                                        AAState.WriteLine("                  Field Mapping verified");

                                                                        // found source and destination fields.
                                                                        sFilter = new SpatialFilterClass();

                                                                        if (searchDistance > 0)
                                                                        {
                                                                            searchEnvelope = inFeature.ShapeCopy.Envelope;
                                                                            searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                            sFilter.Geometry = searchEnvelope;
                                                                        }
                                                                        else
                                                                            sFilter.Geometry = inFeature.ShapeCopy;

                                                                        sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                        AAState.WriteLine("                  Searching for Nearest Feature");

                                                                        fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                        sourceFeature = fCursor.NextFeature();
                                                                        nearestFeature = null;

                                                                        proxOp = (IProximityOperator)inFeature.Shape;
                                                                        lastDistance = searchDistance;
                                                                        if (sourceFeature != null)
                                                                        {
                                                                            AAState.WriteLine("                  Features Found, looping for closest");

                                                                            while (sourceFeature != null)
                                                                            {

                                                                                distance = proxOp.ReturnDistance(sourceFeature.Shape);
                                                                                if (distance <= lastDistance)
                                                                                {
                                                                                    nearestFeature = sourceFeature;
                                                                                    lastDistance = distance;
                                                                                }
                                                                                sourceFeature = fCursor.NextFeature();
                                                                            }
                                                                        }
                                                                        if (nearestFeature != null)
                                                                        {
                                                                            AAState.WriteLine("                  Closest Feature is " + lastDistance + " Away with OID of " + nearestFeature.OID);

                                                                            for (int i = 0; i < sourceFieldNums.Length; i++)
                                                                            {
                                                                                try
                                                                                {
                                                                                    AAState.WriteLine("                  Trying to copy " + sourceFieldNums[i] + " to " + destFieldNums[i]);

                                                                                    inObject.set_Value(destFieldNums[i], nearestFeature.get_Value(sourceFieldNums[i]));
                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: copying " + sourceFieldNums[i] + " to " + destFieldNums[i]);

                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  No Feature was found, default fields");

                                                                            for (int i = 0; i < destFieldNums.Length; i++)
                                                                            {
                                                                                IField field = inObject.Fields.get_Field(destFieldNums[i]);
                                                                                object newval = field.DefaultValue;
                                                                                if (newval == null)
                                                                                {
                                                                                    if (field.IsNullable)
                                                                                    {
                                                                                        inObject.set_Value(destFieldNums[i], null);
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(destFieldNums[i], newval);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: Cant find field " + missingFieldMess);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayerName + " data source is not set");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: " + sourceLayerName + " was not found");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Invalid Value Info: " + valData);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Not a feature or missing Value Info");
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: EUK_NEAREST_FEATURE_ATTRIBUTES" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: EUK_NEAREST_FEATURE_ATTRIBUTES");
                                                }
                                                break;
                                            }
                                        case "MINIMUM_LENGTH":
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying MINIMUM_LENGTH");

                                                    double minlength;
                                                    AAState.WriteLine("                  Evaluating Minimum length value");

                                                    if (Double.TryParse(valData, out minlength))
                                                    {
                                                        if (inFeature != null)
                                                        {
                                                            ICurve curve = inFeature.Shape as ICurve;
                                                            if (curve != null)
                                                            {
                                                                if (curve.Length < minlength)
                                                                {
                                                                    String mess = "Line is shorter than " +
                                                                        String.Format("{0:0.00}", minlength) + " " + Globals.GetSpatRefUnitName(inFeature.Shape.SpatialReference, true) +
                                                                        ", aborting edit.";
                                                                    AAState.WriteLine("                  " + mess);

                                                                    MessageBox.Show(mess, "Line too short");
                                                                    AAState._editor.AbortOperation();
                                                                    return;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR:  Feature is not a Line");

                                                            }
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  Error MINIMUM_LENGTH \n" + ex.Message);
                                                }
                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished MINIMUM_LENGTH");

                                                }

                                                break;
                                            }
                                        case "LINK_TABLE_ASSET":
                                            try
                                            {
                                                intersectLayerName = "";
                                                intersectTable = null;
                                                intersectLayer = null;
                                                intersectLayerFieldName = "";
                                                AAState.WriteLine("                  Trying LINK_TABLE_ASSET");
                                                args = valData.Split('|');
                                                switch (args.GetLength(0))
                                                {
                                                    case 1:  // Feature Layer only
                                                        intersectLayerName = args[0].ToString();
                                                        break;
                                                    case 2:  // Feature Layer| Field to copy
                                                        intersectLayerName = args[0].ToString();
                                                        intersectLayerFieldName = args[1].ToString();

                                                        break;
                                                    case 3:  // Feature Layer| Field to copy | for future
                                                        intersectLayerName = args[0].ToString();
                                                        intersectLayerFieldName = args[1].ToString();
                                                        //sequenceColumnName = args[2].ToString();
                                                        break;
                                                    default:
                                                        AAState.WriteLine("                  ERROR: Unsupported Value Method: " + valData);
                                                        break;
                                                }
                                                intersectLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, intersectLayerName);
                                                intersectTable = Globals.FindStandAloneTable(AAState._editor.Map, intersectLayerName);
                                                ICursor cCurs = null;
                                                if (intersectLayer != null)
                                                {
                                                    //Find Area Field
                                                    intersectFieldPos = intersectLayer.FeatureClass.Fields.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset feature Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }
                                                    intersectLayerSelection = (IFeatureSelection)intersectLayer;
                                                    if (intersectLayerSelection.SelectionSet.Count == 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: No assests selected in " + intersectLayerName);

                                                        break;
                                                    }
                                                    if (intersectLayerSelection.SelectionSet.Count > 1)
                                                    {
                                                        AAState.WriteLine("                  ERROR: To many assests are selected in " + intersectLayerName);

                                                        break;
                                                    }

                                                    intersectLayerSelection.SelectionSet.Search(null, true, out cCurs);
                                                }
                                                else if (intersectTable != null)
                                                {
                                                    if (intersectTable.Table == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset  Layer(" + intersectLayerName + ") not found");
                                                        break;
                                                    }
                                                    //Find Area Field
                                                    intersectFieldPos = intersectTable.Table.Fields.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }
                                                    intersectTableSelection = (ITableSelection)intersectTable;
                                                    if (intersectTableSelection.SelectionSet.Count == 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: No assests selected in " + intersectLayerName);

                                                        break;
                                                    }
                                                    if (intersectTableSelection.SelectionSet.Count > 1)
                                                    {
                                                        AAState.WriteLine("                  ERROR: To many assests are selected in " + intersectLayerName);

                                                        break;
                                                    }

                                                    intersectTableSelection.SelectionSet.Search(null, true, out cCurs);
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: Asset  Layer(" + intersectLayerName + ") not found");
                                                    break;
                                                }

                                                IRow row;

                                                while ((row = cCurs.NextRow()) != null)
                                                {
                                                    string val = row.get_Value(intersectFieldPos).ToString();

                                                    if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                        inObject.set_Value(fieldNum, val);
                                                    else
                                                    {
                                                        if (Globals.IsNumeric(val))
                                                        {

                                                            inObject.set_Value(fieldNum, row.get_Value(intersectFieldPos));
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field is a number and ID from Asset is not - ID:" + val);

                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LINK_TABLE_ASSET" + Environment.NewLine + ex.Message);
                                            }

                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LINK_TABLE_ASSET");
                                            }
                                            break;

                                        case "GET_ADDRESS_USING_GEOCODER":
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying GET_ADDRESS_USING_GEOCODER");

                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 2)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    AAState.WriteLine("                  Trying to get address locator");
                                                    IReverseGeocoding reverseGeocoding = Globals.OpenLocator(args[0], args[1]);

                                                    if (reverseGeocoding == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Reverse Address not locator found");
                                                        break;
                                                    }
                                                    AAState.WriteLine("                  Reverse Address locator found");
                                                    AAState.WriteLine("                  Retrieving Location to reverse geocode");
                                                    IPoint revGCLoc = Globals.GetGeomCenter(inFeature);
                                                    AAState.WriteLine("                  Location retrieved");
                                                    // Create a Point at which to find the address.
                                                    IAddressGeocoding addressGeocoding = (IAddressGeocoding)reverseGeocoding;

                                                    IFields matchFields = addressGeocoding.MatchFields;
                                                    int shpFld = matchFields.FindField("Shape");

                                                    IField shapeField = matchFields.get_Field(shpFld);
                                                    AAState.WriteLine("                  Setting distance");
                                                    // Set the search tolerance for reverse geocoding.
                                                    IReverseGeocodingProperties reverseGeocodingProperties =
                                                        (IReverseGeocodingProperties)reverseGeocoding;
                                                    reverseGeocodingProperties.SearchDistance = 100;
                                                    reverseGeocodingProperties.SearchDistanceUnits = esriUnits.esriFeet;

                                                    // Find the address nearest the Point.
                                                    IPropertySet addressProperties = reverseGeocoding.ReverseGeocode(revGCLoc, false);

                                                    // Print the address properties.
                                                    IAddressInputs addressInputs = (IAddressInputs)reverseGeocoding;
                                                    IFields addressFields = addressInputs.AddressFields;
                                                    object key, value;
                                                    addressProperties.GetAllProperties(out key, out value);

                                                    //object[] keyArray = key as object[];
                                                    //object[] valueArray = value as object[];

                                                    //for (int i = 0; i < keyArray.Length; i++)
                                                    //{
                                                    //    if (keyArray[i].ToString() == "Shape")
                                                    //    {
                                                    //        IPoint addressPoint = valueArray[i] as IPoint;
                                                    //        Console.WriteLine(keyArray[i] + " = " + addressPoint.X + ", " +
                                                    //            addressPoint.Y);
                                                    //    }
                                                    //    else
                                                    //        Console.WriteLine(keyArray[i] + " = " + valueArray[i]);
                                                    //}
                                                    for (int i = 0; i < addressFields.FieldCount; i++)
                                                    {
                                                        IField addressField = addressFields.get_Field(i);
                                                        string tempVal = addressProperties.GetProperty(addressField.Name).ToString();

                                                        inFeature.set_Value(fieldNum, tempVal);

                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: GET_ADDRESS_USING_GEOCODER" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: GET_ADDRESS_USING_GEOCODER");
                                                }
                                                break;

                                            }
                                            break;

                                        case "GET_ADDRESS_USING_ARCGIS_SERVICE":  //ARGS: url
                                            try
                                            {
                                                AAState.WriteLine("                  Trying GET_ADDRESS_USING_ARCGIS_SERVICE");
                                                if (fieldObj.Type == esriFieldType.esriFieldTypeString)
                                                {
                                                    if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                    {

                                                        IPoint revGCLoc = Globals.GetGeomCenter(inFeature);

                                                        if (revGCLoc != null)
                                                        {
                                                            //Test for user specified URL
                                                            if (Globals.IsUrl(valData))
                                                            {
                                                                locatorURL = valData;
                                                                /////locatorURL.TrimEnd(char[] );
                                                                if (!(locatorURL.EndsWith(reverseGeocode)))
                                                                    locatorURL += reverseGeocode;
                                                            }

                                                            //If no valid user speficied URL, test for keywords for North America or European Union locators
                                                            else if (valData == "ESRI_Geocode_NA" || valData == "ESRI_Geocode_EU")
                                                                locatorURL = _agsOnlineLocators + valData + reverseGeocode;
                                                            else if (valData == "TA_Streets_US " || valData == "TA_Address_NA" || valData == "TA_Address_EU")
                                                                locatorURL = _agsOnlineLocators + valData + reverseGeocode;
                                                            //Default to AGS Online USA geocode service

                                                            else if (_agsOnlineLocators.Substring(_agsOnlineLocators.LastIndexOf('/', _agsOnlineLocators.Length - 2)).Contains("Locator"))
                                                                locatorURL = _agsOnlineLocators + "TA_Address_NA" + reverseGeocode;
                                                            else
                                                                locatorURL = _agsOnlineLocators + reverseGeocode;

                                                            //Copy point from this current feature
                                                            _copyPoint = revGCLoc;//inFeature.ShapeCopy as IPoint;

                                                            //Project point to WGS84
                                                            _copyPoint.Project(AAState.srWGS84);

                                                            //Include location parameters in URL
                                                            string results = Globals.FormatLocationRequest(locatorURL, _copyPoint.X, _copyPoint.Y, 100);

                                                            //Send and receieve the request
                                                            WebRequest req = WebRequest.Create(results);
                                                            WebResponse res = req.GetResponse();

                                                            //Convert response from JSON to XML
                                                            XmlDocument doc = new XmlDocument();
                                                            using (Stream s = res.GetResponseStream())
                                                            {
                                                                XmlDictionaryReader xr = JsonReaderWriterFactory.CreateJsonReader(s, XmlDictionaryReaderQuotas.Max);
                                                                doc.Load(xr);
                                                                xr.Close();
                                                                s.Close();

                                                                //Store Address element from Address Results in the specified field
                                                                //if (mode == "ON_CREATE")
                                                                //{
                                                                //    inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));
                                                                //}
                                                                //else//on change
                                                                //{
                                                                //    if (inFeature.Fields.get_Field(fieldNum).DefaultValue == inFeature.get_Value(fieldNum))
                                                                //    //if (inFeature.get_Value(fieldNum).ToString() != "")
                                                                //    {
                                                                //        inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));
                                                                //    }
                                                                //}
                                                                inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));

                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  Could not get location to Reverse Geocode");
                                                        }
                                                    }

                                                }

                                            }
                                            catch
                                            {
                                                AAState.WriteLine("                  ERROR: GET_ADDRESS_USING_ARCGIS_SERVICE");
                                            }

                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GET_ADDRESS_USING_ARCGIS_SERVICE");
                                            }
                                            break;
                                        case "TIMESTAMP":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TIMESTAMP");
                                                if (fieldObj.Type == esriFieldType.esriFieldTypeDate)
                                                    inObject.set_Value(fieldNum, DateTime.Now);
                                                else if (fieldObj.Type == esriFieldType.esriFieldTypeString)
                                                    inObject.set_Value(fieldNum, DateTime.Now.ToString());

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TIMESTAMP " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TIMESTAMP");
                                            }
                                            break;

                                        case "LAST_VALUE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LAST_VALUE");
                                                if (mode == "ON_CREATE")
                                                {

                                                    lastValue = AAState.lastValueProperties.GetProperty(fieldName);
                                                    if (lastValue != null)
                                                    {
                                                        inObject.set_Value(fieldNum, lastValue);
                                                        AAState.WriteLine("                  " + fieldName + ": " + lastValue);
                                                    }
                                                }
                                                else if (mode == "ON_CHANGE" && inObject.get_Value(fieldNum) == null)
                                                {
                                                    lastValue = AAState.lastValueProperties.GetProperty(fieldName);
                                                    if (lastValue != null)
                                                    {
                                                        inObject.set_Value(fieldNum, lastValue);
                                                        AAState.WriteLine("                  " + fieldName + ": " + lastValue);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LAST_VALUE " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LAST_VALUE");
                                            }
                                            break;

                                        case "X_COORDINATE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: X_COORDINATE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {
                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.Shape as IPoint;
                                                        inFeature.set_Value(fieldNum, _copyPoint.X);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.X);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.X);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).X);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: X_COORDINATE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: X_COORDINATE");
                                            }
                                            break;

                                        case "Y_COORDINATE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: Y_COORDINATE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {
                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.Shape as IPoint;
                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.Y);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.Y);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).Y);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: Y_COORDINATE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: Y_COORDINATE");
                                            }
                                            break;

                                        case "LATITUDE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LATITUDE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {

                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.ShapeCopy as IPoint;
                                                        _copyPoint.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.ShapeCopy as IPolyline;
                                                        _copyPolyline.Project(AAState._sr1);

                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.X);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.X);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;
                                                        _copyPolygon.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).X);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  Error: LATITUDE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LATITUDE");
                                            }
                                            break;

                                        case "LONGITUDE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LONGITUDE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {

                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.ShapeCopy as IPoint;
                                                        _copyPoint.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        _copyPolyline.Project(AAState._sr1);

                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.Y);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.Y);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;
                                                        _copyPolygon.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).Y);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LONGITUDE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LONGITUDE");
                                            }
                                            break;

                                        case "FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: Field");
                                                // verify that field to copy exists
                                                fieldCopy = inObject.Fields.FindField(valData as string);
                                                if (fieldCopy > -1)
                                                {
                                                    if (mode == "ON_CREATE")
                                                    {
                                                        inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                                    }
                                                    if (mode == "ON_CHANGE")
                                                    {
                                                        //copy value only if current field is empty
                                                        if (inObject.get_Value(fieldNum).ToString() == "")
                                                            inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  " + valData + " is not found");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: Field: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: Field");
                                            }
                                            break;

                                        //CURRENT_USER
                                        //Value Data options:
                                        //U - windows username only
                                        //W or (blank) - full username including domain i.e. domain\username
                                        //D - database user if available and not dbo
                                        case "CURRENT_USER":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: CURRENT_USER");
                                                lastEditorName = AAState._currentUserInfo.GetCurrentUser(valData, fieldObj.Length);

                                                if (!String.IsNullOrEmpty(lastEditorName))
                                                {
                                                    inObject.set_Value(fieldNum, lastEditorName);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: CURRENT_USER: "******"                  Finished: CURRENT_USER");
                                            }
                                            break;

                                        case "JUNCTION_ROTATION":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: JUNCTION_ROTATION");
                                                if ((inFeature != null))
                                                {
                                                    AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;
                                                    args = null;

                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args[0].Length == 0)
                                                        {
                                                            if (args[0].Substring(0, 1).ToLower() == "a")
                                                                AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;
                                                        }
                                                        if (args[0].Length == 1)
                                                        {
                                                            if (args[0].Substring(0, 1).ToLower() == "a")
                                                                AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;
                                                            if (Globals.IsNumeric(args[1].ToString()))
                                                                AAState.rCalc.SpinAngle = Convert.ToDouble(args[1]);

                                                        }
                                                    }
                                                    AAState.WriteLine("                  " + AAState.rCalc.RotationType.ToString() + " is being used");
                                                    rotationAngle = AAState.rCalc.GetRotationUsingConnectedEdges(inFeature);
                                                    if (rotationAngle == null)
                                                    {
                                                        AAState.WriteLine("                  Rotation Angle not found or errored out");
                                                        continue;
                                                    }

                                                    //Accept optional second argument to provide extra rotation
                                                    //if ((args != null) && (args.Length > 1) && (Globals.IsInteger(args[1])))
                                                    //    rotationAngle += System.Convert.ToInt32(args[1]);
                                                    if (rotationAngle != -1)
                                                        inObject.set_Value(fieldNum, rotationAngle);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: JUNCTION_ROTATION \r\n" + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: JUNCTION_ROTATION");
                                            }
                                            break;

                                        //For Release: 1.2
                                        //New Dynamic Value Method: Length - stores calculated length of line feature
                                        case "LENGTH":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LENGTH");
                                                if (inFeature != null)
                                                {
                                                    curve = (ICurve)inFeature.Shape;
                                                    if (curve != null)
                                                    {
                                                        inObject.set_Value(fieldNum, curve.Length);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LENGTH: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LENGTH");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: SET_MEASURES - stores calculated M values (from 0 to length of line) for line feature
                                        //Value Data options:
                                        //P = Percent - Ms will be zero to 100
                                        //default - Ms will be zero to length of line
                                        case "SET_MEASURES":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: SET_MEASURES");
                                                if (inFeature != null)
                                                {
                                                    curve = inFeature.Shape as ICurve;
                                                    mseg = inFeature.Shape as IMSegmentation;
                                                    if (curve != null && mseg != null)
                                                        if (valData != null && valData != "" && valData.Substring(0, 1).ToUpper() == "P")
                                                            mseg.SetAndInterpolateMsBetween(0, 100);
                                                        else
                                                            mseg.SetAndInterpolateMsBetween(0, curve.Length);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: SET_MEASURES: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: SET_MEASURES");
                                            }
                                            break;
                                        //case "EDGE_INTERSECT_SECOND":
                                        //    try
                                        //    {
                                        //        if (inFeature != null)
                                        //        {
                                        //            netFeat = inFeature as INetworkFeature;
                                        //            if (netFeat != null)
                                        //            {
                                        //                if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                        //                {

                                        //                    iJuncFeat = (IJunctionFeature)netFeat;
                                        //                    // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                        //                    ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                        //                    if (iSJunc == null)
                                        //                        break;
                                        //                    if (iSJunc.EdgeFeatureCount <= 1)
                                        //                        break;
                                        //                    edgeFeat = iSJunc.get_EdgeFeature(1);

                                        //                    // verify that field (in junction) to copy exists

                                        //                    IRow pRow = edgeFeat as IRow;

                                        //                    juncField = pRow.Fields.FindField(valData as string);
                                        //                    if (juncField > -1)
                                        //                    {
                                        //                        inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                        //                    }
                                        //                }
                                        //            }
                                        //        }
                                        //    }
                                        //    catch
                                        //    {
                                        //    }
                                        //    break;
                                        //case "EDGE_INTERSECT_FIRST":
                                        //    try
                                        //    {
                                        //        if (inFeature != null)
                                        //        {
                                        //            netFeat = inFeature as INetworkFeature;
                                        //            if (netFeat != null)
                                        //            {
                                        //                if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                        //                {

                                        //                    iJuncFeat = (IJunctionFeature)netFeat;
                                        //                    // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                        //                    ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                        //                    if (iSJunc == null)
                                        //                        break;
                                        //                    if (iSJunc.EdgeFeatureCount <= 0)
                                        //                        break;
                                        //                    edgeFeat = iSJunc.get_EdgeFeature(0);

                                        //                    IRow pRow = edgeFeat as IRow;

                                        //                    juncField = pRow.Fields.FindField(valData as string);
                                        //                    if (juncField > -1)
                                        //                    {
                                        //                        inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                        //                    }
                                        //                }
                                        //            }
                                        //        }
                                        //    }
                                        //    catch
                                        //    {
                                        //    }
                                        //    break;

                                        //Release: 2.0
                                        //New Dynamic Value Method: TO_EDGE_FIELD transfers a field value from a connected egde feature to a junction feature
                                        //Takes value from the frist edge whose "TO" point connects with this junction
                                        case "TO_EDGE_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TO_EDGE_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                                        {

                                                            iJuncFeat = (IJunctionFeature)netFeat;
                                                            // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                                            ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                                            if (iSJunc == null)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount <= 0)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount > 0)
                                                            {
                                                                for (int i = 0; i < iSJunc.EdgeFeatureCount; i++)
                                                                {
                                                                    edgeFeat = iSJunc.get_EdgeFeature(i);
                                                                    try
                                                                    {
                                                                        juncFeat = (IFeature)edgeFeat.FromJunctionFeature;
                                                                        if (juncFeat.Shape.Equals(inFeature.Shape))
                                                                        {
                                                                            IRow pRow = edgeFeat as IRow;

                                                                            // verify that field (in junction) to copy exists
                                                                            juncField = pRow.Fields.FindField(valData as string);
                                                                            if (juncField > -1)
                                                                            {
                                                                                inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  " + valData + " field not found in edge");
                                                                            }
                                                                            break;

                                                                        }
                                                                    }
                                                                    catch
                                                                    {
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  No Connected Edges Found");
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  not an junction feature");
                                                        }

                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Not a Geometric Network Feature");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TO_EDGE_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TO_EDGE_FIELD");
                                            }
                                            break;

                                        //Release: 2.0
                                        //New Dynamic Value Method: FROM_EDGE_FIELD transfers a field value from a connected egde feature to a junction feature
                                        //Takes value from the frist edge whose "FROM" point connects with this junction
                                        case "FROM_EDGE_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: FROM_EDGE_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                                        {

                                                            iJuncFeat = (IJunctionFeature)netFeat;
                                                            // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                                            ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                                            if (iSJunc == null)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount <= 0)
                                                                break;
                                                            for (int i = 0; i < iSJunc.EdgeFeatureCount; i++)
                                                            {
                                                                edgeFeat = iSJunc.get_EdgeFeature(i);
                                                                try
                                                                {
                                                                    juncFeat = (IFeature)edgeFeat.ToJunctionFeature;
                                                                    if (juncFeat.Shape.Equals(inFeature.Shape))
                                                                    {
                                                                        IRow pRow = edgeFeat as IRow;

                                                                        // verify that field (in junction) to copy exists
                                                                        juncField = pRow.Fields.FindField(valData as string);
                                                                        if (juncField > -1)
                                                                        {
                                                                            inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  " + valData + " field not found");
                                                                        }
                                                                        break;

                                                                    }

                                                                }

                                                                catch
                                                                {
                                                                    AAState.WriteLine("                  error ");
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  not an junction feature");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Not a Geometric Network Feature");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: FROM_EDGE_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: FROM_EDGE_FIELD");
                                            }
                                            break;

                                        case "FROM_JUNCTION_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: FROM_JUNCTION_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexEdge || inFeature.FeatureType == esriFeatureType.esriFTSimpleEdge)
                                                        {
                                                            edgeFeat = (IEdgeFeature)netFeat;
                                                            juncFeat = (IFeature)edgeFeat.FromJunctionFeature;

                                                            // verify that field (in junction) to copy exists
                                                            juncField = juncFeat.Fields.FindField(valData as string);
                                                            if (juncField > -1)
                                                            {
                                                                inObject.set_Value(fieldNum, juncFeat.get_Value(juncField));
                                                            }
                                                            else
                                                                AAState.WriteLine("                  " + valData + " field not found");
                                                        }
                                                        else
                                                            AAState.WriteLine("                  not an edge feature");
                                                    }
                                                    else
                                                        AAState.WriteLine("                  Not a network feature");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: FROM_JUNCTION_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: FROM_JUNCTION_FIELD");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: TO_JUNCTION_FIELD transfers a field value from a junction connected at terminal end of a line feature
                                        case "TO_JUNCTION_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TO_JUNCTION_FIELD");
                                                if (inFeature != null)
                                                {

                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexEdge || inFeature.FeatureType == esriFeatureType.esriFTSimpleEdge)
                                                        {
                                                            edgeFeat = (IEdgeFeature)netFeat;
                                                            juncFeat = (IFeature)edgeFeat.ToJunctionFeature;

                                                            // verify that field (in junction) to copy exists
                                                            juncField = juncFeat.Fields.FindField(valData as string);
                                                            if (juncField > -1)
                                                            {
                                                                inObject.set_Value(fieldNum, juncFeat.get_Value(juncField));
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  Trying: TO_JUNCTION_FIELD");
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  not an edge feature");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  not an geometric network feature");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TO_JUNCTION_FIELD:" + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TO_JUNCTION_FIELD");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: GENERATE_ID - uses value in specificed table and increments it as specified
                                        case "GENERATE_ID":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID");
                                                if (AAState._gentab != null)
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    formatString = "";

                                                    // Parse arguments
                                                    if (valData == null) break;
                                                    args = valData.Split('|');
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 1:  // sequenceColumnName only
                                                            sequenceColumnName = args[0].ToString(); break;
                                                        case 2:  // sequenceColumnName|sequenceFixedWidth
                                                            sequenceColumnName = args[0].ToString();
                                                            sequenceFixedWidth = args[1].ToString();
                                                            break;
                                                        case 3:  // sequenceColumnName|sequenceFixedWidth|formatString
                                                            sequenceColumnName = args[0].ToString();
                                                            sequenceFixedWidth = args[1].ToString();
                                                            formatString = args[2].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);
                                                    if (sequencePadding > 25)
                                                    {

                                                        AAState.WriteLine("                  WARNING: you are trying to pad your id with a more than 25 - 0's");
                                                        AAState.WriteLine("                  WARNING: " + sequencePadding + " 0's is what you have");

                                                    }
                                                    else if (sequencePadding > 50)
                                                    {
                                                        MessageBox.Show("You are trying to add 50 places to your ID, this is not supported, please fix your dynamic value table");
                                                    }

                                                    //Check for sequence column in generate id table
                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (AAState._gentab.FindField(sequenceColumnName) >= 0)
                                                    {
                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(null, false).NextRow();
                                                            if (row == null)
                                                            {
                                                                break;
                                                            }
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));

                                                            sequenceValue += 1;
                                                            // _editEvents.OnChangeFeature -= OnChangeFeature;
                                                            // _editEvents.OnCreateFeature -= OnCreateFeature;

                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            AAState.WriteLine("                  " + row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue);

                                                            row.Store();
                                                            //  _editEvents.OnChangeFeature += OnChangeFeature;
                                                            //  _editEvents.OnCreateFeature += OnCreateFeature;
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            AAState.WriteLine("                  ERROR: GENERATE_ID: Sequence Not Found");
                                                        }

                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || formatString.ToLower().IndexOf("[seq]") == -1)
                                                                {
                                                                    string setVal = (sequenceValue.ToString("D" + sequencePadding) + sequencePostfix).ToString();

                                                                    if (inObject.Fields.get_Field(fieldNum).Length < setVal.Length && inObject.Fields.get_Field(fieldNum).Length != 0)
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + sequenceValue + " is to long for field " + row.Fields.get_Field(sequenceColumnNum).AliasName);
                                                                    }
                                                                    else
                                                                    {
                                                                        inObject.set_Value(fieldNum, sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                        AAState.WriteLine("                  " + inObject.Fields.get_Field(fieldNum).AliasName + " set to " + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);

                                                                    }

                                                                }
                                                                else
                                                                {

                                                                    int locIdx = formatString.ToUpper().IndexOf("[SEQ]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 5);
                                                                        formatString = formatString.Insert(locIdx, sequenceValue.ToString("D" + sequencePadding));
                                                                    }
                                                                    //formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));

                                                                    if (inObject.Fields.get_Field(fieldNum).Length < formatString.Length && inObject.Fields.get_Field(fieldNum).Length != 0)
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + formatString + " is to long for field " + row.Fields.get_Field(sequenceColumnNum).AliasName);
                                                                    }
                                                                    else
                                                                    {
                                                                        inObject.set_Value(fieldNum, formatString);
                                                                        AAState.WriteLine("                  " + inObject.Fields.get_Field(fieldNum).AliasName + " set to " + formatString);
                                                                    }

                                                                }
                                                            else
                                                            {

                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                                AAState.WriteLine("                  " + sequenceColumnNum + " changed to " + sequenceValue);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Sequence Field not found");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }

                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID");
                                            }
                                            break;

                                        case "GENERATE_ID_BY_INTERSECT":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID_BY_INTERSECT");
                                                if (AAState._gentab != null && inFeature != null && !(inFeature.Shape.IsEmpty))
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    //genIdAreaFieldName = "";
                                                    intersectLayerName = "";
                                                    intersectLayerFieldName = "";
                                                    formatString = "";
                                                    intersectFieldPos = -1;

                                                    // Parse arguments
                                                    if (valData == null) break;

                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) < 3)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Improper value method");
                                                        break;
                                                    }
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 3:  //columnName
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            // genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            break;
                                                        case 4:  // columnName|sequenceFixedWidth
                                                            //sequenceFixedWidth formats the sequence with leading zeros to create specified width
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            //genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            sequenceFixedWidth = Convert.ToString(0);
                                                            formatString = args[3].ToString();

                                                            break;
                                                        case 5:  // columnName|sequenceFixedWidth|formatString
                                                            //formatString must contain [seq] and [id]  and may contain [area] plus any desired text
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            //genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            sequenceFixedWidth = args[3].ToString();
                                                            formatString = args[4].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Find Area Layer
                                                    // FindLayerByName(areaLayerName, out areaLayer);
                                                    intersectLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, intersectLayerName);
                                                    if (intersectLayer == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature Layer(" + intersectLayerName + ") not found");
                                                        break;
                                                    }
                                                    //Find Area Field
                                                    intersectFieldPos = intersectLayer.FeatureClass.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }

                                                    //Find GenID Area Field
                                                    //genIdAreaFieldPos = areaLayer.FeatureClass.FindField(genIdAreaFieldName);
                                                    //if (genIdAreaFieldPos < 0) break;

                                                    //Perform spatial search
                                                    IGeometry pSearchGeo = (IGeometry)inFeature.ShapeCopy;
                                                    pSearchGeo.SpatialReference = (inFeature.Class as IGeoDataset).SpatialReference;
                                                    pSearchGeo.Project((intersectLayer as IGeoDataset).SpatialReference);
                                                    sFilter = new SpatialFilterClass();
                                                    sFilter.Geometry = pSearchGeo;
                                                    sFilter.GeometryField = intersectLayer.FeatureClass.ShapeFieldName;
                                                    sFilter.SubFields = intersectLayerFieldName;
                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                    fCursor = intersectLayer.FeatureClass.Search(sFilter, true);
                                                    sourceFeature = fCursor.NextFeature();
                                                    if (sourceFeature != null)
                                                        intersectValue = sourceFeature.get_Value(intersectFieldPos).ToString();
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature not found");
                                                        break;
                                                    }
                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);

                                                    if (sequencePadding > 25)
                                                    {
                                                        AAState.WriteLine("                  WARNING: you are trying to pad your id with a more than 25 - 0's");
                                                        AAState.WriteLine("                  WARNING: " + sequencePadding + " 0's is what you have");

                                                    }

                                                    sequenceColumnName = sequenceColumnName + intersectValue;
                                                    AAState.WriteLine("                  Looking for a field called " + sequenceColumnName + " in the generate ID table");
                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (sequenceColumnNum > -1)
                                                    {
                                                        AAState.WriteLine("                  Field Found");

                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(qFilter, false).NextRow();
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));
                                                            sequenceValue += 1;
                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            row.Store();
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Sequence number not found");
                                                        }
                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || (formatString.ToUpper().IndexOf("[SEQ]") == -1 && formatString.ToUpper().IndexOf("[ID]") == -1))
                                                                    inObject.set_Value(fieldNum, intersectValue + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                else
                                                                {

                                                                    int locIdx = formatString.ToUpper().IndexOf("[ID]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 4);
                                                                        formatString = formatString.Insert(locIdx, intersectValue);
                                                                    }
                                                                    //  formatString = formatString.Replace("[id]", intersectValue);
                                                                    // formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));
                                                                    locIdx = formatString.ToUpper().IndexOf("[SEQ]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 5);
                                                                        formatString = formatString.Insert(locIdx, sequenceValue.ToString());
                                                                    }
                                                                    //
                                                                    inObject.set_Value(fieldNum, formatString);
                                                                }
                                                            else
                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Field NOT Found");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID_BY_INTERSECT: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID_BY_INTERSECT");
                                            }
                                            break;
                                        //Modified for Release 1.2  (No longer uses ICalculator)
                                        //Requires valid VBScript expression
                                        //Can include string, numeric, and date fields by name in square brackets []
                                        //Example: DateDiff("yyyy",[INSTALLDATE],Now())
                                        case "GENERATE_ID_BY_AREA":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID_BY_AREA");
                                                if (AAState._gentab != null && inFeature != null && !(inFeature.Shape.IsEmpty))
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    genIdAreaFieldName = "";
                                                    areaLayerName = "";
                                                    areaLayerFieldName = "";
                                                    formatString = "";

                                                    // Parse arguments
                                                    if (valData == null) break;

                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) < 3)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Improper Value Method");
                                                        break;
                                                    }
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 4:  //columnName
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            break;
                                                        case 5:  // columnName|sequenceFixedWidth
                                                            //sequenceFixedWidth formats the sequence with leading zeros to create specified width
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            sequenceFixedWidth = args[4].ToString();
                                                            break;
                                                        case 6:  // columnName|sequenceFixedWidth|formatString
                                                            //formatString must contain [seq] and may contain [area] plus any desired text
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            sequenceFixedWidth = args[4].ToString();
                                                            formatString = args[5].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Find Area Layer
                                                    // FindLayerByName(areaLayerName, out areaLayer);
                                                    areaLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, areaLayerName);
                                                    if (areaLayer == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Area Layer not found: " + areaLayerName);
                                                        break;
                                                    }

                                                    //Find Area Field
                                                    areaFieldPos = areaLayer.FeatureClass.FindField(areaLayerFieldName);
                                                    if (areaFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Area Layer field not found: " + areaLayerFieldName);
                                                        break;
                                                    }

                                                    //Find GenID Area Field
                                                    //genIdAreaFieldPos = areaLayer.FeatureClass.FindField(genIdAreaFieldName);
                                                    //if (genIdAreaFieldPos < 0) break;

                                                    //Perform spatial search
                                                    sFilter = new SpatialFilterClass();
                                                    sFilter.Geometry = (IGeometry)inFeature.ShapeCopy;
                                                    sFilter.GeometryField = areaLayer.FeatureClass.ShapeFieldName;
                                                    sFilter.SubFields = areaLayerFieldName;
                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                    fCursor = areaLayer.FeatureClass.Search(sFilter, true);
                                                    sourceFeature = fCursor.NextFeature();
                                                    if (sourceFeature != null)
                                                        areaValue = sourceFeature.get_Value(areaFieldPos).ToString();
                                                    else
                                                        break;

                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);

                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (sequenceColumnNum > -1)
                                                    {
                                                        qFilter = new QueryFilterClass();
                                                        qFilter.SubFields = areaLayerFieldName + "," + sequenceColumnName;

                                                        ISQLSyntax sqlSyntax = (ISQLSyntax)AAState._editor.EditWorkspace;
                                                        char[] charBuf = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix).ToCharArray();
                                                        string strSC = new string(charBuf);
                                                        switch (strSC)
                                                        {
                                                            case "":
                                                                qFilter.WhereClause = genIdAreaFieldName + " = '" + areaValue + "'";
                                                                break;
                                                            case "[":
                                                                qFilter.WhereClause = "[" + genIdAreaFieldName + "]" + " = '" + areaValue + "'";
                                                                break;
                                                            default:
                                                                qFilter.WhereClause = "\"" + genIdAreaFieldName + "\" = '" + areaValue + "'";
                                                                break;
                                                        }

                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(qFilter, false).NextRow();
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));
                                                            sequenceValue += 1;
                                                            sequenceValue += 1;
                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            row.Store();
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            //TODO raise error
                                                        }
                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || formatString.IndexOf("[seq]") == -1)
                                                                    inObject.set_Value(fieldNum, areaValue + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                else
                                                                {
                                                                    formatString = formatString.Replace("[area]", areaValue);
                                                                    formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));
                                                                    inObject.set_Value(fieldNum, formatString);
                                                                }
                                                            else
                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID_BY_AREA: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID_BY_AREA");
                                            }

                                            break;
                                        //Modified for Release 1.2  (No longer uses ICalculator)
                                        //Requires valid VBScript expression
                                        //Can include string, numeric, and date fields by name in square brackets []
                                        //Example: DateDiff("yyyy",[INSTALLDATE],Now())
                                        case "EXPRESSION":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: EXPRESSION");
                                                if (inObject != null & valData != null)
                                                {
                                                    newValue = valData;
                                                    for (int i = 0; i < inObject.Fields.FieldCount; i++)
                                                    {
                                                        testField = inObject.Fields.get_Field(i);

                                                        int indFld = newValue.ToUpper().IndexOf("[" + testField.Name.ToUpper() + "]");
                                                        while (indFld >= 0)
                                                        {
                                                            AAState.WriteLine("                  replace field: " + testField.Name + " with a value");
                                                            int fldLen = testField.Name.Length;
                                                            string tmpStr1 = newValue.Substring(0, indFld + 1);
                                                            string tmpStr2 = newValue.Substring(indFld + fldLen + 1);
                                                            newValue = tmpStr1 + "_REPLACE_VAL_" + tmpStr2;

                                                            switch (testField.Type)
                                                            {
                                                                case esriFieldType.esriFieldTypeString:

                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                    }

                                                                    // newValue = newValue.Replace("[" + testField.Name + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                    break;
                                                                case esriFieldType.esriFieldTypeDate:

                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(" + null + ")");
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                        }
                                                                    }

                                                                    // newValue = newValue.Replace("[" + testField.Name + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                    break;

                                                                default:
                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);// "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "" + inObject.get_Value(i).ToString() + "");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", inObject.get_Value(i).ToString());
                                                                        }
                                                                    }
                                                                    //  newValue = newValue.Replace("[" + testField.Name + "]", inObject.get_Value(i).ToString());
                                                                    break;
                                                            }
                                                            indFld = newValue.ToUpper().IndexOf("[" + testField.Name.ToUpper() + "]");
                                                        }
                                                    }
                                                    //MessageBox.Show(newValue);

                                                    try
                                                    {
                                                        newValue = script.Eval(newValue).ToString();
                                                        if (inObject.get_Value(fieldNum).ToString() != newValue)
                                                            inObject.set_Value(fieldNum, newValue);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        AAState.WriteLine("                  ERROR: evaluating the expression for feature in " + inObject.Class.AliasName + " with OID of " + inObject.OID);
                                                        AAState.WriteLine("                         " + ex.Message);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: EXPRESSION: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: EXPRESSION");
                                            }
                                            break;

                                        // GUID values are calculated into text fields or into native GUID field types
                                        // When using text field you have an optional argument (valdata) to specify the format
                                        // N-none 32 chars, D-dash 36, B-braces 38, P-Parenthesis 38
                                        case "GUID":
                                            try
                                            {
                                                if (inObject != null)
                                                {
                                                    if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeGUID)
                                                        inObject.set_Value(fieldNum, System.Guid.NewGuid().ToString("B"));
                                                    else if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString &&
                                                             inObject.Fields.get_Field(fieldNum).Length >= 32)
                                                    {

                                                        valData = valData.Trim();
                                                        if (valData != "N" && valData != "D" && valData != "B" && valData != "P")
                                                            if (inObject.Fields.get_Field(fieldNum).Length >= 38)
                                                                valData = "B";  //Default to braces
                                                            else if (inObject.Fields.get_Field(fieldNum).Length < 36)
                                                                valData = "N";
                                                            else
                                                                valData = "D";
                                                        inObject.set_Value(fieldNum, System.Guid.NewGuid().ToString(valData));
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: EXPRESSION: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: EXPRESSION");
                                            }
                                            break;

                                        case "CREATE_LINKED_RECORD"://Feature Layer|Field To Copy|Field To Populate|Primary Key Field|Foreign Key Field
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying: CREATE_LINKED_RECORD");
                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 5)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    if (inFeature == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: The input features is null");
                                                        break;
                                                    }
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    AAState.WriteLine("                  Getting Value Info");
                                                    sourceLayerNames = args[0].ToString().Split(',');
                                                    sourceFieldName = args[1].ToString();
                                                    string targetFieldName = args[2].ToString();
                                                    string sourceIDFieldName = args[3].ToString();
                                                    string targetIDFieldName = args[4].ToString();
                                                    AAState.WriteLine("                  Checking values");
                                                    if (sourceFieldName != null)
                                                    {
                                                        AAState.WriteLine("                  Checking Fields in Source Layer");
                                                        int fldValToCopyIdx = inObject.Fields.FindField(sourceFieldName);
                                                        int fldIDToCopyIdx = inObject.Fields.FindField(sourceIDFieldName);
                                                        if (fldValToCopyIdx > -1 && fldIDToCopyIdx > -1)
                                                        {

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                sourceLayerName = sourceLayerNames[i].ToString();

                                                                if (sourceLayerName != "")
                                                                {

                                                                    // Get layer
                                                                    AAState.WriteLine("                  Checking for table to populate");
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);

                                                                    if (sourceLayer != null)
                                                                    {

                                                                    }
                                                                    else
                                                                    {
                                                                        ITable pTable = Globals.FindTable(AAState._editor.Map, sourceLayerName);
                                                                        if (pTable != null)
                                                                        {
                                                                            int fldValToPopIdx = pTable.Fields.FindField(targetFieldName);
                                                                            int fldIDToPopIdx = pTable.Fields.FindField(targetIDFieldName);
                                                                            if (fldValToPopIdx > -1 && fldIDToPopIdx > -1)
                                                                            {
                                                                                AAState.WriteLine("                  Trying to create a row in the target table");
                                                                                IRow pNewRow = pTable.CreateRow();
                                                                                AAState.WriteLine("                  Row Created");
                                                                                AAState.WriteLine("                  Trying to Copy ID");
                                                                                try
                                                                                {
                                                                                    pNewRow.set_Value(fldIDToPopIdx, inObject.get_Value(fldIDToCopyIdx));

                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: Could not Copy: " + inObject.get_Value(fldIDToCopyIdx) + " to field: " + targetIDFieldName);
                                                                                }
                                                                                AAState.WriteLine("                  ID successfully copied");
                                                                                AAState.WriteLine("                  Trying to Copy Value");
                                                                                try
                                                                                {
                                                                                    pNewRow.set_Value(fldValToPopIdx, inObject.get_Value(fldValToCopyIdx));

                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: Could not Copy: " + inObject.get_Value(fldValToCopyIdx) + " to field: " + targetFieldName);
                                                                                }
                                                                                AAState.WriteLine("                  Value successfully copied");
                                                                                pNewRow.Store();
                                                                                if (newFeatureList == null)
                                                                                {
                                                                                    newFeatureList = new List<IObject>();
                                                                                }
                                                                                IObject featobj = pNewRow as IObject;

                                                                                if (featobj != null)
                                                                                {
                                                                                    newFeatureList.Add(featobj);
                                                                                }

                                                                                AAState.WriteLine("                  Row successfully stored");
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: ID or Field to populate was not found");
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR: Table to populate not found: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: ID or Field to Copy was not found");
                                                        }

                                                        //if ((!found) && (inObject.Fields.get_Field(fieldNum).IsNullable))
                                                        //{
                                                        //    inObject.set_Value(fieldNum, null);
                                                        //}
                                                    }

                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: CREATE_LINKED_RECORD" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: CREATE_LINKED_RECORD");
                                                    // fieldNum = -1;

                                                }
                                                break;

                                            }

                                        case "UPDATE_INTERSECTING_FEATURE"://Intersected Feature|FieldIntersectingFeatureToChange|FromFieldinModifiedFeature
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying: UPDATE_INTERSECTING_FEATURE");
                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 3)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    if (inFeature == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: The input features is null");
                                                        break;
                                                    }
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    AAState.WriteLine("                  Getting Value Info");
                                                    sourceLayerNames = args[0].ToString().Split(',');
                                                    sourceFieldName = args[1].ToString();
                                                    string targetFieldName = args[2].ToString();
                                                    AAState.WriteLine("                  Checking values");
                                                    if (sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")
                                                            {
                                                                // Get layer
                                                                sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);

                                                                if (sourceLayer != null)
                                                                {
                                                                    if (inObject.Class != sourceLayer.FeatureClass)
                                                                    {
                                                                        if (Globals.IsEditable(sourceLayer, AAState._editor))
                                                                        {

                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    try
                                                                                    {
                                                                                        ISpatialReferenceResolution pSRResolution;

                                                                                        pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;

                                                                                        //  sFilter = new SpatialFilterClass();
                                                                                        double intTol = pSRResolution.get_XYResolution(false);
                                                                                        bool hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();

                                                                                        searchEnvelope = new EnvelopeClass();
                                                                                        searchEnvelope.XMin = 0 - intTol;
                                                                                        searchEnvelope.YMin = 0 - intTol;
                                                                                        searchEnvelope.XMax = 0 + intTol;
                                                                                        searchEnvelope.YMax = 0 + intTol;
                                                                                        searchEnvelope.CenterAt(inFeature.ShapeCopy as IPoint);

                                                                                        //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                        searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                        searchEnvelope.SnapToSpatialReference();
                                                                                        searchEnvelope.Project(AAState._editor.Map.SpatialReference);

                                                                                        sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                                    }
                                                                                    catch
                                                                                    {
                                                                                        sFilter.Geometry = inFeature.ShapeCopy;
                                                                                    }

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                if (sourceFeature != null)
                                                                                {
                                                                                    int fldIdx = inFeature.Fields.FindField(targetFieldName);
                                                                                    AAState.WriteLine("                  " + targetFieldName + " at index " + fldIdx);
                                                                                    string test = targetFieldName;
                                                                                    if (fldIdx > -1)
                                                                                    {
                                                                                        test = inFeature.get_Value(fldIdx).ToString();
                                                                                        AAState.WriteLine("                  Value Found " + test);
                                                                                    }
                                                                                    AAState.WriteLine("                  Value used " + test);
                                                                                    try
                                                                                    {

                                                                                        if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeString)
                                                                                        {
                                                                                            sourceFeature.set_Value(sourceField, test);
                                                                                            sourceFeature.Store();
                                                                                            found = true;
                                                                                            break;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (Globals.IsNumeric(test))
                                                                                            {
                                                                                                if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeSmallInteger ||
                                                                                                    sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeInteger)
                                                                                                {

                                                                                                    sourceFeature.set_Value(sourceField, Convert.ToInt32(test));
                                                                                                    sourceFeature.Store();
                                                                                                    found = true;
                                                                                                    break;
                                                                                                }
                                                                                                else if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeDouble ||
                                                                                                    sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeSingle)
                                                                                                {
                                                                                                    sourceFeature.set_Value(sourceField, Convert.ToDouble(test));

                                                                                                    sourceFeature.Store(); found = true;
                                                                                                    break;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    sourceFeature.set_Value(sourceField, test as object);
                                                                                                    sourceFeature.Store();
                                                                                                    found = true;
                                                                                                    break;
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                sourceFeature.set_Value(sourceField, test as object);
                                                                                                sourceFeature.Store();
                                                                                                found = true;
                                                                                                break;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    catch
                                                                                    {
                                                                                        AAState.WriteLine("                  ERROR setting value");
                                                                                    }
                                                                                    finally
                                                                                    {
                                                                                        if (found)
                                                                                        {
                                                                                            //   break;
                                                                                        }
                                                                                    }

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Source Layer is not editable: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                }
                                                            }
                                                        }
                                                        //if ((!found) && (inObject.Fields.get_Field(fieldNum).IsNullable))
                                                        //{
                                                        //    inObject.set_Value(fieldNum, null);
                                                        //}
                                                    }

                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: UPDATE_INTERSECTING_FEATURE" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: UPDATE_INTERSECTING_FEATURE");
                                                    // fieldNum = -1;

                                                }
                                                break;

                                            }
                                        case "MULTI_FIELD_INTERSECT":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: MULTI_FIELD_INTERSECT");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    //LayerToIntersect|Field To Elevate
                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    int popFldIdx = 0;
                                                    if (args.GetLength(0) > 2)
                                                    {
                                                        AAState.WriteLine("                  Parsing Valueinfo");

                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                        string[] fieldsToPop = args[2].ToString().Split(',');
                                                        if (args.GetLength(0) == 4)
                                                        {
                                                            AAState.WriteLine("                  Search distance specified");

                                                            if (Globals.IsDouble(args[3]))
                                                            {
                                                                searchDistance = Convert.ToDouble(args[3]);
                                                            }
                                                            else
                                                            {
                                                                searchDistance = 0.0;
                                                            }
                                                        }
                                                        else
                                                        {

                                                            searchDistance = 0.0;
                                                        }

                                                        if (sourceFieldName != null)
                                                        {
                                                            AAState.WriteLine("                  Looping Through Layers");

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                if (fieldsToPop.Length == popFldIdx)
                                                                    break;

                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        if (sourceLayer.FeatureClass != null)
                                                                        {
                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    searchEnvelope = Globals.CalcSearchExtent(sourceLayer, inFeature, searchDistance);

                                                                                    sFilter.Geometry = searchEnvelope;

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    if (fieldsToPop.Length == popFldIdx)
                                                                                        break;

                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();

                                                                                    int tempFieldNum = inObject.Fields.FindField(fieldsToPop[popFldIdx]);
                                                                                    popFldIdx++;
                                                                                    if (tempFieldNum > -1)
                                                                                    {
                                                                                        inObject.set_Value(tempFieldNum, sourceFeature.get_Value(sourceField));
                                                                                    }
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Datasource is invalid: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer string is empty");

                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field name is invalid");

                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Invalid Value method definition");

                                                    }

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: MULTI_FIELD_INTERSECT: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: MULTI_FIELD_INTERSECT");
                                            }
                                            break;
                                        case "INTERSECT_STATS":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECT_STATS");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    //LayerToIntersect|Field To Elevate
                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    int AverageCount = 0;
                                                    if (args.GetLength(0) > 2)
                                                    {
                                                        AAState.WriteLine("                  Parsing Valueinfo");

                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                        string statType = args[2].ToString();
                                                        if (args.GetLength(0) == 4)
                                                        {
                                                            AAState.WriteLine("                  Search distance specified");

                                                            if (Globals.IsDouble(args[3]))
                                                                searchDistance = Convert.ToDouble(args[3]);
                                                            else
                                                                searchDistance = 0.0;
                                                        }
                                                        else
                                                        {

                                                            searchDistance = 0.0;
                                                        }
                                                        double result = -999999.1;

                                                        if (sourceFieldName != null)
                                                        {
                                                            AAState.WriteLine("                  Looping Through Layers");

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {

                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        if (sourceLayer.FeatureClass != null)
                                                                        {
                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    searchEnvelope = Globals.CalcSearchExtent(sourceLayer, inFeature, searchDistance);

                                                                                    sFilter.Geometry = searchEnvelope;

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                    if (Globals.IsNumeric(test))
                                                                                    {
                                                                                        double valToTest = Convert.ToDouble(test);
                                                                                        if (result == -999999.1)
                                                                                        {
                                                                                            result = valToTest;

                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            switch (statType.ToUpper())
                                                                                            {
                                                                                                case "MAX":
                                                                                                    if (result < valToTest)
                                                                                                    {
                                                                                                        result = valToTest;

                                                                                                    }
                                                                                                    break;
                                                                                                case "MIN":
                                                                                                    if (result > valToTest)
                                                                                                    {
                                                                                                        result = valToTest;

                                                                                                    }
                                                                                                    break;
                                                                                                case "SUM":
                                                                                                    result += valToTest;

                                                                                                    break;
                                                                                                case "AVERAGE":
                                                                                                    result += valToTest;
                                                                                                    AverageCount++;
                                                                                                    break;
                                                                                                case "MEAN":
                                                                                                    result += valToTest;
                                                                                                    AverageCount++;

                                                                                                    break;
                                                                                                default:
                                                                                                    AAState.WriteLine("                  ERROR: Unsupported stat type: " + test);
                                                                                                    break;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        AAState.WriteLine("                  ERROR/WARNING: Non numeric value returned: " + test);
                                                                                    }
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Datasource is invalid: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer string is empty");

                                                                }
                                                            }

                                                            if (result != -999999.1)
                                                            {
                                                                if (AverageCount != 0)
                                                                {
                                                                    result = result / AverageCount;
                                                                }
                                                                inObject.set_Value(fieldNum, result);

                                                            }
                                                            else
                                                            {
                                                                IField field = inObject.Fields.get_Field(fieldNum);
                                                                object newval = field.DefaultValue;
                                                                if (newval == null)
                                                                {
                                                                    if (field.IsNullable)
                                                                    {
                                                                        inObject.set_Value(fieldNum, null);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    inObject.set_Value(fieldNum, newval);
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field name is invalid");

                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Invalid Value method definition");

                                                    }

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECT_STATS: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECT_STATS");
                                            }
                                            break;
                                        case "INTERSECTING_FEATURE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_FEATURE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) >= 2)
                                                    {
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();

                                                        if (sourceFieldName != null)
                                                        {
                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                        if (sourceField > -1)
                                                                        {
                                                                            sFilter = new SpatialFilterClass();

                                                                            sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                            sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                            sFilter.set_OutputSpatialReference(sourceLayer.FeatureClass.ShapeFieldName, (sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                            //sFilter.set_OutputSpatialReference(sourceLayer.FeatureClass.ShapeFieldName, AAState._editor.Map.SpatialReference);
                                                                            if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                            {

                                                                                try
                                                                                {
                                                                                    IGeometry pSourceGeo = inFeature.ShapeCopy as IPoint;
                                                                                    pSourceGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    pSourceGeo.Project((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                                    //pSourceGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                    bool hasXY;
                                                                                    hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();
                                                                                    //hasXY = (AAState._editor.Map.SpatialReference).HasXYPrecision();

                                                                                    double intTol = .001;
                                                                                    if (hasXY)
                                                                                    {
                                                                                        ISpatialReferenceResolution pSRResolution;

                                                                                        pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;
                                                                                        //pSRResolution = (AAState._editor.Map.SpatialReference) as ISpatialReferenceResolution;
                                                                                        intTol = pSRResolution.get_XYResolution(false) * 2;
                                                                                    }

                                                                                    searchEnvelope = new EnvelopeClass();
                                                                                    searchEnvelope.XMin = 0 - intTol;
                                                                                    searchEnvelope.YMin = 0 - intTol;
                                                                                    searchEnvelope.XMax = 0 + intTol;
                                                                                    searchEnvelope.YMax = 0 + intTol;
                                                                                    searchEnvelope.CenterAt(pSourceGeo as IPoint);

                                                                                    searchEnvelope.SpatialReference = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                                    //searchEnvelope.SpatialReference = (AAState._editor.Map.SpatialReference);

                                                                                    //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    //searchEnvelope.SnapToSpatialReference();
                                                                                    //if (AAState._editor.Map.SpatialReference != ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference)
                                                                                    //{

                                                                                    //  searchEnvelope.Project((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);

                                                                                    //searchEnvelope.Project(AAState._editor.Map.SpatialReference);
                                                                                    //}

                                                                                    sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                                    //searchEnvelope.Expand(.1, .1, true);
                                                                                    //searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                                }
                                                                                catch
                                                                                {
                                                                                    IGeometry pGeo = inFeature.ShapeCopy;
                                                                                    pGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    pGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                    sFilter.Geometry = pGeo;

                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                IGeometry pGeo = inFeature.ShapeCopy;
                                                                                pGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                pGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                sFilter.Geometry = pGeo;

                                                                            }
                                                                            fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                            sourceFeature = fCursor.NextFeature();
                                                                            while (sourceFeature != null)
                                                                            {
                                                                                string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                inObject.set_Value(fieldNum, sourceFeature.get_Value(sourceField));
                                                                                found = true;
                                                                                sourceFeature = fCursor.NextFeature();

                                                                            }

                                                                            if (found == false  && AAState._CheckEnvelope)

                                                                            {
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
                                                                              //  sFilter.SpatialRelDescription = "T*T***T*T";
                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                    inObject.set_Value(fieldNum, sourceFeature.get_Value(sourceField));
                                                                                    found = true;
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            if (found)
                                                                            {
                                                                                break;
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                            }
                                                            if (!found)
                                                            {
                                                                IField field = inObject.Fields.get_Field(fieldNum);
                                                                object newval = field.DefaultValue;
                                                                if (newval == null)
                                                                {
                                                                    if (field.IsNullable)
                                                                    {
                                                                        inObject.set_Value(fieldNum, null);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    inObject.set_Value(fieldNum, newval);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_FEATURE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_FEATURE");
                                            }
                                            break;
                                        case "INTERSECTING_RASTER":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_RASTER");
                                                if (inFeature != null & valData != null)
                                                {

                                                    sourceLayerName = "";
                                                    formatString = "";
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.Length < 1) break;
                                                    switch (args.Length)
                                                    {
                                                        case 1:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            break;
                                                        case 2:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = args[1].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    // Get layer
                                                    for (int i = 0; i < sourceLayerNames.Length; i++)
                                                    {
                                                        sourceLayerName = sourceLayerNames[i].ToString();
                                                        IPoint pLoc = Globals.GetGeomCenter(inFeature);

                                                        if (pLoc != null)
                                                        {
                                                            string cellVal = GetCellValue(sourceLayerName, pLoc, AAState._editor.Map);// Globals.GetCellValue(sourceLayerName, pLoc, _editor.Map);
                                                            AAState.WriteLine("                  ERROR/WARING: No cell value or raster was found: " + sourceLayerName);
                                                            if (cellVal != null && cellVal != "" && cellVal != "No Raster")
                                                            {

                                                                if (formatString == null || formatString == "" || (inObject.Fields.get_Field(fieldNum).Type != esriFieldType.esriFieldTypeString))
                                                                {
                                                                    inObject.set_Value(fieldNum, cellVal);
                                                                    found = true;
                                                                    break;
                                                                }
                                                                else
                                                                {
                                                                    // formatString = formatString.Replace("[value]",cellVal);
                                                                    formatString = formatString + cellVal;
                                                                    inObject.set_Value(fieldNum, formatString);

                                                                    found = true;
                                                                    break;
                                                                }

                                                            }

                                                        }
                                                    }
                                                    if (!(found) && inObject.Fields.get_Field(fieldNum).IsNullable)
                                                        inObject.set_Value(fieldNum, null);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_RASTER: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_RASTER");
                                            }
                                            break;
                                        case "INTERSECTING_LAYER_DETAILS":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_LAYER_DETAILS");
                                                if (inFeature != null & valData != null)
                                                {

                                                    sourceLayerName = "";
                                                    formatString = "";
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.Length < 1) break;
                                                    switch (args.Length)
                                                    {
                                                        case 1:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = "P";
                                                            break;
                                                        case 2:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = args[1].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    // Get layer
                                                    for (int i = 0; i < sourceLayerNames.Length; i++)
                                                    {
                                                        sourceLayerName = sourceLayerNames[i].ToString();
                                                        //AAState.WriteLine("                  Getting Features Centeroid");

                                                        //IPoint pLoc = Globals.GetGeomCenter(inFeature);
                                                        IGeometry pGeo = inFeature.ShapeCopy;

                                                        if (pGeo != null)
                                                        {
                                                            // AAState.WriteLine("                  Centroid Found");
                                                            AAState.WriteLine("                  Getting list of " + sourceLayerName + " Layers");
                                                            IEnumLayer pEnum = Globals.GetLayers(AAState._editor.Map, sourceLayerName);

                                                            if (pEnum != null)
                                                            {
                                                                AAState.WriteLine("                  List retrieved of " + sourceLayerName + " Layers");
                                                                AAState.WriteLine("                  Starting Loop");
                                                                ILayer pLay = pEnum.Next();
                                                                ISpatialFilter pSpatFilt;
                                                                while (pLay != null)
                                                                {

                                                                    if (found)
                                                                    {
                                                                        AAState.WriteLine("                  Exiting Layer Loop");
                                                                        break;
                                                                    }
                                                                    AAState.WriteLine("                  Checking " + pLay.Name);

                                                                    if (pLay is IRasterLayer)
                                                                    {

                                                                        IRasterLayer pRasLay = pLay as IRasterLayer;
                                                                        AAState.WriteLine("                  Trying " + pRasLay.Name);
                                                                        IEnvelope pEnv = pRasLay.AreaOfInterest;
                                                                        // ITopologicalOperator pTopo = pEnv as ITopologicalOperator;
                                                                        IRelationalOperator pRel = pEnv as IRelationalOperator;
                                                                        IRelationalOperator2 pRel2 = pEnv as IRelationalOperator2;

                                                                        if (pRel.Crosses(pGeo) || pRel.Touches(pGeo) || pRel.Overlaps(pGeo) || pRel2.ContainsEx(pGeo, esriSpatialRelationExEnum.esriSpatialRelationExClementini))
                                                                        {
                                                                            AAState.WriteLine("                  Geometry does intersect " + pRasLay.Name);
                                                                            switch (formatString)
                                                                            {
                                                                                case "P":
                                                                                    // IDataset pDS = pFLay.FeatureClass as IDataset;

                                                                                    inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                                case "N":
                                                                                    inObject.set_Value(fieldNum, pLay.Name);
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                                default:
                                                                                    inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                            }
                                                                        }
                                                                    }
                                                                    else if (pLay is IFeatureLayer)
                                                                    {
                                                                        IFeatureLayer pFLay = pLay as IFeatureLayer;
                                                                        if (pFLay.FeatureClass == inObject.Class)
                                                                        {
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Trying " + pFLay.Name);
                                                                            pSpatFilt = new SpatialFilterClass();
                                                                            pSpatFilt.GeometryField = pFLay.FeatureClass.ShapeFieldName;
                                                                            pSpatFilt.Geometry = pGeo as IGeometry;
                                                                            pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                            if (pFLay.FeatureClass.FeatureCount(pSpatFilt) > 0)
                                                                            {
                                                                                AAState.WriteLine("                  Geometry does intersect " + pFLay.Name);
                                                                                switch (formatString)
                                                                                {
                                                                                    case "P":
                                                                                        // IDataset pDS = pFLay.FeatureClass as IDataset;
                                                                                        // AAState.WriteLine("                  Exiting Layer Loop");
                                                                                        inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        break;
                                                                                    case "N":
                                                                                        inObject.set_Value(fieldNum, pLay.Name);
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        break;
                                                                                    default:
                                                                                        inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        //inObject.set_Value(fieldNum, null);
                                                                                        break;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  Does not intersect " + pFLay.Name);
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  Warning: Unsupported type");
                                                                    }
                                                                    pLay = pEnum.Next();
                                                                }
                                                                pEnum = null;

                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: not matching layer types found");
                                                            }

                                                        }
                                                        else
                                                            AAState.WriteLine("                  ERROR: Geo not Found");
                                                    }
                                                    //if (!(found) && inObject.Fields.get_Field(fieldNum).IsNullable)
                                                    //    inObject.set_Value(fieldNum, null);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_LAYER_DETAILS: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_LAYER_DETAILS");
                                            }
                                            break;
                                        case "INTERSECTING_FEATURE_DISTANCE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_FEATURE_DISTANCE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) >= 2)
                                                    {
                                                        //    sourceLayerName = args[0].ToString();
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                    }
                                                    // Get layer

                                                    if (sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")

                                                                sourceLayerName = args[i].ToString();
                                                            if (i == 0)
                                                                i++;

                                                            sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                            if (sourceLayer == null)
                                                            {
                                                                AAState.WriteLine("                  ERROR/WARNING: " + sourceLayer + " was not found");
                                                                continue;
                                                            }

                                                            IFeatureClass iFC = inFeature.Class as IFeatureClass;
                                                            if (sourceLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                                            {
                                                                AAState.WriteLine("                  ERROR: " + sourceLayer + " is a polygon layer");

                                                                break;
                                                            }
                                                            //if (sourceLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline || iFC.ShapeType != esriGeometryType.esriGeometryPoint)
                                                            //    break;
                                                            //FindLayerByName(sourceLayerName, out sourceLayer);
                                                            if (sourceLayer != null)
                                                            {
                                                                sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                if (sourceField > -1)
                                                                {
                                                                    sFilter = new SpatialFilterClass();
                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                    sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                    fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                    sourceFeature = fCursor.NextFeature();
                                                                    if (sourceFeature != null)
                                                                    {

                                                                        IPoint pIntPnt;
                                                                        if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                                        {
                                                                            pIntPnt = Globals.GetIntersection(inFeature.ShapeCopy, sourceFeature.ShapeCopy as IPolyline) as IPoint;

                                                                        }
                                                                        else
                                                                            pIntPnt = inFeature.ShapeCopy as IPoint;

                                                                        double dAlong = Globals.PointDistanceOnLine(pIntPnt, sourceFeature.Shape as IPolyline, 2);
                                                                        string strUnit = Globals.GetSpatRefUnitName(Globals.GetLayersCoordinateSystem(sourceLayer.FeatureClass), true);
                                                                        if (strUnit == "Foot" && dAlong != 1)
                                                                        {
                                                                            strUnit = "Feet";
                                                                        }
                                                                        else if (strUnit == "Meter" && dAlong != 1)
                                                                        {
                                                                            strUnit = "Meters";
                                                                        }
                                                                        string strDis = dAlong + " " + strUnit + " along " + sourceLayer.Name + " with " + sourceLayer.FeatureClass.Fields.get_Field(sourceField).AliasName + " of " + sourceFeature.get_Value(sourceField);

                                                                        if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                        {

                                                                            strDis = dAlong + " " + strUnit + ": " + sourceFeature.get_Value(sourceField);
                                                                            AAState.WriteLine("                  Text is to long, defaulting to length along: " + strDis);

                                                                            if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                            {

                                                                                if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                                {
                                                                                    strDis = dAlong.ToString();
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                strDis = dAlong.ToString();
                                                                                AAState.WriteLine("                  Text is to long, defaulting to length along: " + strDis);
                                                                                if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                                {
                                                                                    strDis = dAlong.ToString();
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                            }

                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Value set to: " + strDis);
                                                                            inObject.set_Value(fieldNum, strDis);
                                                                            break;
                                                                        }
                                                                    }

                                                                    else if (inObject.Fields.get_Field(fieldNum).IsNullable)
                                                                        inObject.set_Value(fieldNum, null);
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayer + ": field: " + sourceFieldName + " was not found");
                                                                }
                                                            }
                                                            else { }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_FEATURE_DISTANCE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_FEATURE_DISTANCE");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: NEARSET_FEATURE - similiar to INTERSECTING_FEATURE but requires a search distance.

                                        case "NEAREST_FEATURE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: NEAREST_FEATURE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    searchDistance = 0;
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) > 1)
                                                    {
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                    }

                                                    if (args.GetLength(0) > 2)
                                                        Double.TryParse(args[2], out searchDistance);

                                                    if (sourceLayerNames.Length > 0 & sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")
                                                            {
                                                                sourceLayer = Globals.FindLayer(AAState._editor.Map, sourceLayerName) as IFeatureLayer;
                                                                if (sourceLayer != null)
                                                                {
                                                                    sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                    if (sourceField > -1)
                                                                    {
                                                                        sFilter = new SpatialFilterClass();
                                                                        if (searchDistance > 0)
                                                                        {
                                                                            searchEnvelope = inFeature.ShapeCopy.Envelope;
                                                                            searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                            sFilter.Geometry = searchEnvelope;
                                                                        }
                                                                        else
                                                                            sFilter.Geometry = inFeature.ShapeCopy;

                                                                        sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                        fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                        sourceFeature = fCursor.NextFeature();
                                                                        nearestFeature = null;

                                                                        proxOp = (IProximityOperator)inFeature.Shape;
                                                                        lastDistance = searchDistance;
                                                                        while (!(sourceFeature == null))
                                                                        {
                                                                            distance = proxOp.ReturnDistance(sourceFeature.Shape);
                                                                            if (distance <= lastDistance)
                                                                            {
                                                                                nearestFeature = sourceFeature;
                                                                                lastDistance = distance;
                                                                            }
                                                                            sourceFeature = fCursor.NextFeature();
                                                                        }

                                                                        if (nearestFeature != null)
                                                                        {
                                                                            inObject.set_Value(fieldNum, nearestFeature.get_Value(sourceField));
                                                                            found = true;
                                                                            break;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + sourceLayer + ": field: " + sourceFieldName + " was not found");
                                                                    }

                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayer + " was not found");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: Empty source layer name");
                                                            }

                                                        }
                                                        if (!found)
                                                        {
                                                            IField field = inObject.Fields.get_Field(fieldNum);
                                                            object newval = field.DefaultValue;
                                                            if (newval == null)
                                                            {
                                                                if (field.IsNullable)
                                                                {
                                                                    inObject.set_Value(fieldNum, null);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                inObject.set_Value(fieldNum, newval);
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: NEAREST_FEATURE: " + ex.Message);

                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: NEAREST_FEATURE");
                                            }
                                            break;

                                        default:
                                            //    MessageBox.Show(valMethod + " for layer " + tableName + " is not a valid method, check the dynamic value table", "Attribute Assistant");
                                            AAState.WriteLine("ERROR: " + valMethod + " for layer " + tableName + " is not a valid method, check the dynamic value table");

                                            break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("TableName:" + tableName + "  FieldName:" + fieldName + System.Environment.NewLine + "ValueMethod:" + valMethod + "  ValueData:" + valData + System.Environment.NewLine + "Message: " + ex.Message, "Attribute Assistant Message");
                                    AAState.WriteLine("ERROR: TableName:" + tableName + "  FieldName:" + fieldName + System.Environment.NewLine + "ValueMethod:" + valMethod + "  ValueData:" + valData + System.Environment.NewLine + "Message: " + ex.Message);
                                }

                            }

                            // if (mode == "ON_CREATE")
                            //{
                            if (inObject != null)
                            {

                                inChanges = inObject as IRowChanges;
                                if (fieldNum < inObject.Fields.FieldCount)
                                {
                                    changed = inChanges.get_ValueChanged(fieldNum);
                                    if (changed)
                                        //  if (fieldName.ToUpper() != "SHAPE")
                                        try
                                        {
                                            // AAState.WriteLine("                      Setting Last Value");
                                            if (AAState.lastValueProperties.GetProperty(fieldName) != null)
                                            {
                                                AAState.WriteLine("                      Setting Last Value");
                                                AAState.WriteLine("                           " + fieldName + ": " + inObject.get_Value(fieldNum).ToString());
                                                AAState.lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                                            }

                                            else
                                            {
                                                AAState.WriteLine("                      Setting Last Value");
                                                AAState.WriteLine("                           " + fieldName + ": " + inObject.get_Value(fieldNum).ToString());

                                                AAState.lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                                            }

                                        }
                                        catch
                                        {
                                            //AAState.WriteLine("        Error Setting Last Value " + inObject.Fields.get_Field(fieldNum).Name);

                                        }
                                    //}
                                }
                            }

                        }

                     }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem in setup." + System.Environment.NewLine + "Message:" + ex.Message, "Attribute Assistant Message");
                AAState.WriteLine("Error in setup");
            }
            finally
            {
                if (AAState._tab == inObject.Class)
                {
                    AAState.reInitExt();

                }
                if (progressDialog != null)
                {
                    progressDialog.HideDialog();
                }
                AAState.WriteLine("DONE");
                AAState.WriteLine("---------------------------------------");
                if (fCursor != null)
                {
                    Marshal.ReleaseComObject(fCursor);
                    GC.Collect(300);
                    GC.WaitForFullGCComplete();
                }
            }
        }