private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (DoQueryIndex == 1)//点击查询
            {
                ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(layerComboBox.SelectedIndex) as ESRI.ArcGIS.Carto.IFeatureLayer;
                ESRI.ArcGIS.Geometry.IPoint     point         = new ESRI.ArcGIS.Geometry.PointClass();
                point.PutCoords(e.mapX, e.mapY);

                ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                spatialFilter.Geometry   = point;
                spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = pFeatureLayer.Search(spatialFilter, false);

                ESRI.ArcGIS.Geodatabase.IFeature pFeature;
                while ((pFeature = featureCursor.NextFeature()) != null)
                {
                    axMapControl1.FlashShape(pFeature.Shape);
                }
            }
            else if (DoQueryIndex == 2)//面范围查询
            {
                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.PutCoords(e.mapX, e.mapY);

                pointCollection.AddPoints(1, ref point);

                if (pointCollection.PointCount > 1)
                {
                    DrawPolygon(pointCollection, axMapControl1);
                }
            }
        }
Example #2
0
        private void axMapControlMain_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //实现不同的选择

            this.axMapControlMain.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            IGeometry geometry = null;
            switch (iFlagSelection)
            {
                case 0:
                    ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.PointClass();
                    point.X = e.mapX;
                    point.Y = e.mapY;
                    geometry = point as IGeometry;
                    break;
                case 1:
                    geometry = this.axMapControlMain.TrackRectangle();
                    break;
                case 2:
                    geometry = this.axMapControlMain.TrackPolygon();
                    break;
                case 3:
                    geometry = this.axMapControlMain.TrackCircle();
                    break;
                case 4:
                    geometry = this.axMapControlMain.TrackLine();
                    break;
            }
            this.axMapControlMain.Map.SelectByShape(geometry, null, false);
            this.axMapControlMain.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            this.axMapControlMain.CurrentTool = null;
        }
Example #3
0
 public override void OnMouseDown(int Button, int Shift, int X, int Y)
 {
     try
     {
         ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
         ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();
         m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference;
         pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
         if (pMapPoint == null)
         {
             return;
         }
         pMapPoint.Project(m_psurface.Domain.SpatialReference);
         pMapPoint.Z = m_psurface.GetElevation(pMapPoint);
         IGroupElement pGroup = null;
         ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
         m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
         m_Geometry = pMapPoint;
         EndDtrawd(true);
     }
     catch
     {
         return;
     }
 }
Example #4
0
        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            IGeometry geometry = null;

            switch (flag)
            {
            case 1:
                ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.PointClass();
                point.X  = e.mapX;
                point.Y  = e.mapY;
                geometry = point as IGeometry;
                break;

            case 2:
                geometry = axMapControl1.TrackCircle();
                break;

            case 3:
                geometry = axMapControl1.TrackRectangle();
                break;

            case 4:
                geometry = axMapControl1.TrackPolygon();
                break;
            }
            axMapControl1.Map.SelectByShape(geometry, null, false);
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
        }
Example #5
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //IMapDocument mxd;
            string x;
            x = e.mapX.ToString("#########.########");
            string y;
            y = e.mapY.ToString("#########.########");

            string data;
            data = "";
            data += string.Format("The map has x coordinate {0} \n y coordinate {1}", x, y);

            Form1 msgForm = new Form1();
            msgForm.label1.Text = data;
            //msgForm.ShowDialog();
            IPropertySet location = new PropertySet();
            location.SetProperty("ps","C:\\Users\\AlexanderN\\Documents\\ArcGIS\\Points.gdb");
            string featureBuffer = "C:\\Users\\AlexanderN\\Documents\\ArcGIS\\Points.gdb\\Buffer";
            string featurePoint = "C:\\Users\\AlexanderN\\Documents\\ArcGIS\\Points.gdb\\AdditionalPoint";
            IFeatureWorkspace ws;
            IFeature newPoint = ws.OpenFeatureClass(featurePoint) as IFeature;
            IFeature newBuffer = ws.OpenFeatureClass(featureBuffer) as IFeature;

                Geom.IPoint point = new Geom.PointClass();
                point.PutCoords(e.mapX, e.mapY);
                newPoint.Shape = point;
                IFeatureClass pointFC = newPoint as IFeatureClass;
                newPoint.Store();
        }
Example #6
0
        /**
         * 官网示例
         * */
        public void IFeatureClass_CreateFeature_Example(IFeatureClass featureClass)
        {
            //Function is designed to work with polyline data
            if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
            {
                return;
            }
            //create a geometry for the features shape
            ESRI.ArcGIS.Geometry.IPolyline polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
            ESRI.ArcGIS.Geometry.IPoint    point    = new ESRI.ArcGIS.Geometry.PointClass();
            point.X            = 0; point.Y = 0;
            polyline.FromPoint = point;
            point   = new ESRI.ArcGIS.Geometry.PointClass();
            point.X = 10; point.Y = 10; polyline.ToPoint = point;
            IFeature feature = featureClass.CreateFeature();

            //Apply the constructed shape to the new features shape
            feature.Shape = polyline;
            ISubtypes    subtypes    = (ISubtypes)featureClass;
            IRowSubtypes rowSubtypes = (IRowSubtypes)feature;

            if (subtypes.HasSubtype)         // does the feature class have subtypes?
            {
                rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype
            }
            // initalize any default values that the feature has
            rowSubtypes.InitDefaultValues();
            //Commit the default values in the feature to the database
            feature.Store();
            //update the value on a string field that indicates who installed the feature.
            feature.set_Value(feature.Fields.FindField("InstalledBy"), "K Johnston");
            //Commit the updated values in the feature to the database
            feature.Store();
        }
        private void add2MapBtn_Click(object sender, EventArgs e)
        {
            if (lam72 == null || adres == null)
            {
                return;
            }

            IPoint fromXY = new ESRI.ArcGIS.Geometry.PointClass()
            {
                X = xAdres, Y = yAdres, SpatialReference = lam72
            };
            IPoint toXY = geopuntHelper.Transform(fromXY as IGeometry, view.FocusMap.SpatialReference) as IPoint;

            IRgbColor innerClr = new RgbColor()
            {
                Red = 255, Blue = 0, Green = 255
            };
            IRgbColor outlineClr = new RgbColor()
            {
                Red = 0, Blue = 0, Green = 0
            };

            geopuntHelper.AddGraphicToMap(map, toXY, innerClr, outlineClr, 12, false);
            geopuntHelper.AddTextElement(map, toXY, adres);

            view.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #8
0
        /// <summary>
        /// 添加点
        /// </summary>
        /// <param name="lngLat"></param>
        public void AddPoint(MapLngLat lngLat)
        {
            Dosomething((Action)(delegate
            {
                ESRI.ArcGIS.Geometry.IPoint newPoint = new ESRI.ArcGIS.Geometry.PointClass()
                {
                    X = lngLat.Lng, Y = lngLat.Lat
                };
                pointCollection.AddPoint(newPoint);
                base.Geometry = (IGeometry)pointCollection;
            }), true);

            Update();
            pointList.Add(lngLat);//坐标集合
        }
Example #9
0
        /// <summary>
        /// 创建balloon型提示框
        /// </summary>
        /// <param name="x">提示框所在位置X坐标</param>
        /// <param name="y">提示框所在位置Y坐标</param>
        /// <returns></returns>
        public IBalloonCallout CreateBalloonCallout(double x, double y)
        {
            IRgbColor pRgbClr = new RgbColorClass();

            pRgbClr.Red   = 255;
            pRgbClr.Blue  = 255;
            pRgbClr.Green = 255;
            ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass();

            pSmplFill.Color = pRgbClr;
            pSmplFill.Style = esriSimpleFillStyle.esriSFSSolid;
            IBalloonCallout pBllnCallout = new BalloonCalloutClass();

            pBllnCallout.Style           = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
            pBllnCallout.Symbol          = pSmplFill;
            pBllnCallout.LeaderTolerance = 1;
            IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();

            pPoint.X = x;
            pPoint.Y = y;
            pBllnCallout.AnchorPoint = pPoint;
            return(pBllnCallout);
        }
Example #10
0
        /// <summary>
        /// 移除点
        /// </summary>
        /// <param name="lngLat"></param>
        /// <returns></returns>
        public void RemovePoint(MapLngLat lngLat)
        {
            Dosomething((Action)(delegate
            {
                ESRI.ArcGIS.Geometry.IPoint newPoint = new ESRI.ArcGIS.Geometry.PointClass()
                {
                    X = lngLat.Lng, Y = lngLat.Lat
                };
                for (int i = 0; i < pointCollection.PointCount; i++)
                {
                    if (pointCollection.get_Point(i).Compare(newPoint) == 0)
                    {
                        pointCollection.RemovePoints(i, 1);

                        pointList.Remove(lngLat);
                        break;
                    }
                }
                base.Geometry = (IGeometry)pointCollection;

                Update();
            }), true);
        }
Example #11
0
        /// <summary>
        /// 将错误点展现在图面上
        /// </summary>
        /// <param name="pGra">符号展现容器</param>
        /// <param name="x">点x坐标</param>
        /// <param name="y">点y坐标</param>
        /// <param name="conScale">底图比例尺</param>
        private void MakePointSymbol(IGraphicsContainer pGra, double x, double y, long conScale)
        {
            //IActiveView pAcitveView = pGra as IActiveView;
            IElement pEle;

            //画点
            ESRI.ArcGIS.Geometry.IPoint pPint = new ESRI.ArcGIS.Geometry.PointClass();
            pPint.PutCoords(x, y);
            //设置点的衍射
            IRgbColor pColor = new RgbColorClass();

            pColor.Blue  = 0;
            pColor.Green = 0;
            pColor.Red   = 255;

            //设置显示比例尺和参考比例尺
            double vMapFrameScale    = double.Parse(conScale.ToString());
            double vMapRefrenceScale = double.Parse(conScale.ToString());

            // m_Hook.MapControl.Map.ReferenceScale = double.Parse(conScale.ToString());
            _MapControl.Map.ReferenceScale = double.Parse(conScale.ToString());

            //设置符号显示大小,颜色、几何等
            IMarkerElement pMakEle = new MarkerElementClass();

            pEle = pMakEle as IElement;
            ISimpleMarkerSymbol pMakSym = new SimpleMarkerSymbolClass();

            if (vMapRefrenceScale != 0 && vMapFrameScale != 0)
            {
                double size = (vMapFrameScale / 40) * vMapFrameScale / vMapRefrenceScale;; // (vMapFrameScale / 30) * vMapFrameScale / vMapRefrenceScale;
                pMakSym.Size = size;                                                       // *10;
            }
            //IDisplayName pDisName = pMakSym as IDisplayName;
            //pDisName.NameString = pointName;
            pMakSym.Color  = pColor;
            pMakEle.Symbol = pMakSym;
            pMakSym.Style  = esriSimpleMarkerStyle.esriSMSCircle;
            pEle.Geometry  = pPint as ESRI.ArcGIS.Geometry.IGeometry;

            //添加元素
            pGra.AddElement(pEle, 0);
            //pAcitveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            //ESRI.ArcGIS.Geometry.IPoint pPint2 = new ESRI.ArcGIS.Geometry.PointClass();
            //pPint2.PutCoords(y - 50, x + 50);

            //ITextElement pTextElement = new TextElementClass();
            //ITextSymbol pTextSymbol = new TextSymbolClass();

            //stdole.StdFont pStdFont = new stdole.StdFontClass();
            //stdole.IFontDisp pFont = (stdole.IFontDisp)pStdFont;
            //pFont.Name = "宋体";
            //if (vMapRefrenceScale != 0 && vMapFrameScale != 0)
            //{
            //    //double size = (vMapFrameScale / 30) * vMapFrameScale / vMapRefrenceScale;
            //    double size = (vMapFrameScale / vMapRefrenceScale) * 16;
            //    pFont.Size = (decimal)size;
            //}
            //pTextSymbol.Font = pFont;
            //pTextSymbol.Color = pColor;

            //pTextElement.Symbol = pTextSymbol;
            //pTextElement.ScaleText = true;
            //pTextElement.Text = "";//pointName;
            //pEle = pTextElement as IElement;
            //pEle.Geometry = pPint2 as ESRI.ArcGIS.Geometry.IGeometry;

            //pGra.AddElement(pEle, 0);
            //pAcitveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
        public static SpatialFieldValues Execute(IFeature utransFeature, IFeatureClass zipsFeatClass, IFeatureClass muniFeatClass, IFeatureClass countyFeatClass, IFeatureClass addrSysFeatClass, IFeatureClass metroTwnShp)
        {
            try
            {
                // Instantiate a new fields value object.
                var spatialFieldValues = new SpatialFieldValues();
                //spatialFieldValues.Muni_L = "Lefty";
                //spatialFieldValues.Muni_R = "Righty";


                // Get the right and left offset points for the utrans feature for sgid spatial queries.
                //get the midpoint of the line segment for doing spatial queries (intersects)
                IGeometry arcUtransEdits_geometry = utransFeature.ShapeCopy;
                IPolyline arcUtransEdits_polyline = arcUtransEdits_geometry as IPolyline;

                // Get the midpoint of the line, if needed on fields w/o right/left values.
                //IPoint arcUtransEdits_midPoint = new ESRI.ArcGIS.Geometry.Point();
                //get the midpoint of the line, pass it into a point
                //arcUtransEdits_polyline.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, arcUtransEdits_midPoint);

                // Use iconstructpoint.constructoffset method to offset the midpoint of the line.
                IConstructPoint constructionPoint_positiveRight = new ESRI.ArcGIS.Geometry.PointClass();
                IConstructPoint constructionPoint_negativeLeft  = new ESRI.ArcGIS.Geometry.PointClass();

                // call offset mehtod to get a point along the curve's midpoint - offsetting in the postive position (esri documentation states that positive offset will always return point on the right side of the curve)
                constructionPoint_positiveRight.ConstructOffset(arcUtransEdits_polyline, esriSegmentExtension.esriNoExtension, 0.5, true, 15);  // 10 meters is about 33 feet (15 is about 50 feet)
                IPoint outPoint_posRight = constructionPoint_positiveRight as ESRI.ArcGIS.Geometry.IPoint;

                // call offset mehtod to get a point along the curve's midpoint - offsetting in the negative position (esri documentation states that negative offset will always return point on the left-side of curve)
                constructionPoint_negativeLeft.ConstructOffset(arcUtransEdits_polyline, esriSegmentExtension.esriNoExtension, 0.5, true, -15);  // -10 meters is about -33 feet (15 is about 50 feet)
                IPoint outPoint_negLeft = constructionPoint_negativeLeft as ESRI.ArcGIS.Geometry.IPoint;



                // LEFT - ZIP & USPS COMMUNITY
                ISpatialFilter arcSpatialFilter_leftZip = new SpatialFilter();
                arcSpatialFilter_leftZip.Geometry   = outPoint_negLeft;
                arcSpatialFilter_leftZip.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor arcZipCursor_left  = zipsFeatClass.Search(arcSpatialFilter_leftZip, false);
                IFeature       arcFeatureZip_left = arcZipCursor_left.NextFeature();
                if (arcFeatureZip_left != null)
                {
                    spatialFieldValues.Zip_L =
                        arcFeatureZip_left.get_Value(arcFeatureZip_left.Fields.FindField("ZIP5")).ToString().Trim();
                    spatialFieldValues.PostalComm_L = arcFeatureZip_left
                                                      .get_Value(arcFeatureZip_left.Fields.FindField("NAME")).ToString().Trim().ToUpper();
                }
                else
                {
                    spatialFieldValues.Zip_L        = "NA";
                    spatialFieldValues.PostalComm_L = "NA";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcZipCursor_left);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftZip);


                // RIGHT ZIP & USPS COMMUNITY
                ISpatialFilter arcSpatialFilter_rightZip = new SpatialFilter();
                arcSpatialFilter_rightZip.Geometry   = outPoint_posRight;
                arcSpatialFilter_rightZip.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor arcZipCursor_right  = zipsFeatClass.Search(arcSpatialFilter_rightZip, false);
                IFeature       arcFeatureZip_right = arcZipCursor_right.NextFeature();
                if (arcFeatureZip_right != null)
                {
                    spatialFieldValues.Zip_R =
                        arcFeatureZip_right.get_Value(arcFeatureZip_right.Fields.FindField("ZIP5")).ToString().Trim();
                    spatialFieldValues.PostalComm_R = arcFeatureZip_right
                                                      .get_Value(arcFeatureZip_right.Fields.FindField("NAME")).ToString().Trim().ToUpper();
                }
                else
                {
                    spatialFieldValues.Zip_R        = "NA";
                    spatialFieldValues.PostalComm_R = "NA";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcZipCursor_right);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftZip);


                // LEFT - INCORPORATED COMM
                ISpatialFilter arcSpatialFilter_leftIncComm = new SpatialFilter();
                arcSpatialFilter_leftIncComm.Geometry   = outPoint_negLeft;
                arcSpatialFilter_leftIncComm.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor arcIncCommCursor_left  = muniFeatClass.Search(arcSpatialFilter_leftIncComm, false);
                IFeature       arcFeatureIncComm_left = arcIncCommCursor_left.NextFeature();
                if (arcFeatureIncComm_left != null)
                {
                    spatialFieldValues.IncMuni_L =
                        arcFeatureIncComm_left.get_Value(arcFeatureIncComm_left.Fields.FindField("NAME")).ToString().Trim().ToUpper();
                }
                else
                {
                    spatialFieldValues.IncMuni_L = "";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcIncCommCursor_left);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftIncComm);

                // RIGHT - INCORPORATED COMM
                ISpatialFilter arcSpatialFilter_rightIncComm = new SpatialFilter();
                arcSpatialFilter_rightIncComm.Geometry   = outPoint_posRight;
                arcSpatialFilter_rightIncComm.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor arcIncCommCursor_right  = muniFeatClass.Search(arcSpatialFilter_rightIncComm, false);
                IFeature       arcFeatureIncComm_right = arcIncCommCursor_right.NextFeature();
                if (arcFeatureIncComm_right != null)
                {
                    spatialFieldValues.IncMuni_R =
                        arcFeatureIncComm_right.get_Value(arcFeatureIncComm_right.Fields.FindField("NAME")).ToString().Trim().ToUpper();
                }
                else
                {
                    spatialFieldValues.IncMuni_R = "";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcIncCommCursor_right);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_rightIncComm);


                // LEFT - COUNTY
                ISpatialFilter arcSpatialFilter_leftCounty = new SpatialFilter();
                arcSpatialFilter_leftCounty.Geometry   = outPoint_negLeft;
                arcSpatialFilter_leftCounty.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor countyFeatureCursor_left = countyFeatClass.Search(arcSpatialFilter_leftCounty, false);
                IFeature       arcFeatureCounty_left    = countyFeatureCursor_left.NextFeature();
                if (arcFeatureCounty_left != null)
                {
                    spatialFieldValues.County_L =
                        arcFeatureCounty_left.get_Value(arcFeatureCounty_left.Fields.FindField("FIPS_STR")).ToString().Trim();
                }
                else
                {
                    spatialFieldValues.County_L = "NA";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(countyFeatureCursor_left);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftCounty);

                // RIGHT - COUNTY
                ISpatialFilter arcSpatialFilter_rightCounty = new SpatialFilter();
                arcSpatialFilter_rightCounty.Geometry   = outPoint_posRight;
                arcSpatialFilter_rightCounty.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor countyFeatureCursor_right = countyFeatClass.Search(arcSpatialFilter_rightCounty, false);
                IFeature       arcFeatureCounty_right    = countyFeatureCursor_right.NextFeature();
                if (arcFeatureCounty_right != null)
                {
                    spatialFieldValues.County_R =
                        arcFeatureCounty_right.get_Value(arcFeatureCounty_right.Fields.FindField("FIPS_STR")).ToString().Trim();
                }
                else
                {
                    spatialFieldValues.County_R = "NA";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(countyFeatureCursor_right);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_rightCounty);


                // LEFT - ADDRESS SYSTEM
                ISpatialFilter arcSpatialFilter_leftAddrSystem = new SpatialFilter();
                arcSpatialFilter_leftAddrSystem.Geometry   = outPoint_negLeft;
                arcSpatialFilter_leftAddrSystem.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor addrSystemFeatureCursor_left = addrSysFeatClass.Search(arcSpatialFilter_leftAddrSystem, false);
                IFeature       arcFeatureAddrSystem_left    = addrSystemFeatureCursor_left.NextFeature();
                if (arcFeatureAddrSystem_left != null)
                {
                    spatialFieldValues.AddrSystem_L =
                        arcFeatureAddrSystem_left.get_Value(arcFeatureAddrSystem_left.Fields.FindField("GRID_NAME")).ToString().Trim();
                    spatialFieldValues.AddrSystemQuad_L =
                        arcFeatureAddrSystem_left.get_Value(arcFeatureAddrSystem_left.Fields.FindField("QUADRANT")).ToString().Trim();
                }
                else
                {
                    spatialFieldValues.AddrSystem_L     = "NA";
                    spatialFieldValues.AddrSystemQuad_L = "";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(addrSystemFeatureCursor_left);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftAddrSystem);

                // RIGHT - ADDRESS SYSTEM
                ISpatialFilter arcSpatialFilter_rightAddrSystem = new SpatialFilter();
                arcSpatialFilter_rightAddrSystem.Geometry   = outPoint_posRight;
                arcSpatialFilter_rightAddrSystem.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor addrSystemFeatureCursor_right = addrSysFeatClass.Search(arcSpatialFilter_rightAddrSystem, false);
                IFeature       arcFeatureAddrSystem_right    = addrSystemFeatureCursor_right.NextFeature();
                if (arcFeatureAddrSystem_right != null)
                {
                    spatialFieldValues.AddrSystem_R =
                        arcFeatureAddrSystem_right.get_Value(arcFeatureAddrSystem_right.Fields.FindField("GRID_NAME")).ToString().Trim();
                    spatialFieldValues.AddrSystemQuad_R =
                        arcFeatureAddrSystem_right.get_Value(arcFeatureAddrSystem_right.Fields.FindField("QUADRANT")).ToString().Trim();
                }
                else
                {
                    spatialFieldValues.AddrSystem_R     = "NA";
                    spatialFieldValues.AddrSystemQuad_R = "";
                }
                //clear out variables
                // release the cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(addrSystemFeatureCursor_right);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_rightAddrSystem);


                // check if we're in Salt Lake County, if so check for metro townships
                if (utransFeature.get_Value(utransFeature.Fields.FindField("COFIPS")).ToString().Trim() == "49035")
                {
                    // it's in salt lake county - check for metro townships
                    // LEFT - METO TOWNSHIP
                    ISpatialFilter arcSpatialFilter_leftMetroTwnShp = new SpatialFilter();
                    arcSpatialFilter_leftMetroTwnShp.Geometry   = outPoint_negLeft;
                    arcSpatialFilter_leftMetroTwnShp.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                    IFeatureCursor metroTwnShpFeatureCursor_left = metroTwnShp.Search(arcSpatialFilter_leftMetroTwnShp, false);
                    IFeature       arcFeatureMetroTwn_left       = metroTwnShpFeatureCursor_left.NextFeature();
                    if (arcFeatureMetroTwn_left != null)
                    {
                        spatialFieldValues.UnIncMuni_L =
                            arcFeatureMetroTwn_left.get_Value(arcFeatureMetroTwn_left.Fields.FindField("SHORTDESC")).ToString().Trim().ToUpper();
                    }
                    else
                    {
                        spatialFieldValues.UnIncMuni_L = "";
                    }
                    //clear out variables
                    // release the cursor
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(metroTwnShpFeatureCursor_left);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_leftMetroTwnShp);

                    // RIGHT - METO TOWNSHIP
                    ISpatialFilter arcSpatialFilter_rightMetroTwnShp = new SpatialFilter();
                    arcSpatialFilter_rightMetroTwnShp.Geometry   = outPoint_posRight;
                    arcSpatialFilter_rightMetroTwnShp.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                    IFeatureCursor metroTwnShpFeatureCursor_right = metroTwnShp.Search(arcSpatialFilter_rightMetroTwnShp, false);
                    IFeature       arcFeatureMetroTwn_right       = metroTwnShpFeatureCursor_right.NextFeature();
                    if (arcFeatureMetroTwn_right != null)
                    {
                        spatialFieldValues.UnIncMuni_R =
                            arcFeatureMetroTwn_right.get_Value(arcFeatureMetroTwn_right.Fields.FindField("SHORTDESC")).ToString().Trim().ToUpper();
                    }
                    else
                    {
                        spatialFieldValues.UnIncMuni_R = "";
                    }
                    //clear out variables
                    // release the cursor
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(metroTwnShpFeatureCursor_right);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(arcSpatialFilter_rightMetroTwnShp);
                }


                // destroy spatial filters.
                GC.Collect();

                // retrun object
                return(spatialFieldValues);
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected override void OnClick()
        {
            try
            {
                List<ESRI.ArcGIS.Geometry.IPoint> Flags;
                List<ESRI.ArcGIS.Geometry.IPoint> Barriers;
                IWorkspace pWS;
                IFields pFields;
                IPoint pNPt;
                Globals.getFlagsBarriers(ArcMap.Application, out Flags, out Barriers);
                // Open the Workspace
                if ((pWS = Globals.GetInMemoryWorkspaceFromTOC(ArcMap.Document.FocusMap)) == null)
                {
                    pWS = Globals.CreateInMemoryWorkspace();
                }
                pFields = Globals.createFeatureClassFields(ArcMap.Document.FocusMap.SpatialReference, esriGeometryType.esriGeometryPoint);

                IFeatureClass pFlagsFC = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportFlagsName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction);
                IFeatureClass pBarriersFC = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportBarriersName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction);

                IFeatureCursor pntInsertCurs = pFlagsFC.Insert(true);
                IFeatureBuffer pFBuf;
                IFeature pFeat;

                foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Flags) // Loop through List with foreach
                {
                    pFBuf = pFlagsFC.CreateFeatureBuffer();
                    pFeat = (IFeature)pFBuf;
                    pNPt = new ESRI.ArcGIS.Geometry.PointClass();
                    pNPt.X = pnt.X;
                    pNPt.Y = pnt.Y;

                    pFeat.Shape = pNPt;

                    pntInsertCurs.InsertFeature(pFBuf);

                }
                pntInsertCurs = pBarriersFC.Insert(true);
                foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Barriers) // Loop through List with foreach
                {
                    pFBuf = pBarriersFC.CreateFeatureBuffer();
                    pFeat = (IFeature)pFBuf;
                    pNPt = new ESRI.ArcGIS.Geometry.PointClass();
                    pNPt.X = pnt.X;
                    pNPt.Y = pnt.Y;

                    pFeat.Shape = pNPt;
                    pntInsertCurs.InsertFeature(pFBuf);

                }

                IFeatureLayer pFlagsLayer = new FeatureLayerClass();
                pFlagsLayer.FeatureClass = pFlagsFC;
                pFlagsLayer.Name = A4LGSharedFunctions.Localizer.GetString("ExportFlagsName");

                IFeatureLayer pBarriersLayer = new FeatureLayerClass();
                pBarriersLayer.FeatureClass = pBarriersFC;
                pBarriersLayer.Name = A4LGSharedFunctions.Localizer.GetString("ExportBarriersName");

                ArcMap.Document.FocusMap.AddLayer(pFlagsLayer);
                ArcMap.Document.FocusMap.AddLayer(pBarriersLayer);
                ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            { }
        }
        /// <summary>
        /// draw footprints on the map
        /// </summary>
        /// <param name="record">Record for which the footprint needs to be drwan</param>
        /// <param name="refreshview">Indicates if the view is refreshed or not after the element is drawn</param>
        /// <param name="deleteelements">Indicates if the element can be deleted or not</param>
        private void drawfootprint(CswRecord record, bool refreshview, bool deleteelements)
        {
            //create the triangle outline symbol
            ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
            lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            lineSymbol.Width = 2.0;

            //create the triangle's fill symbol
             ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
            simpleFillSymbol.Outline = (ILineSymbol)lineSymbol;
            simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;

            IMxDocument mxDoc;
            mxDoc = (IMxDocument)m_application.Document;

            //the original projection system
            ISpatialReference spatialReference;
            IGeographicCoordinateSystem geographicCoordinateSystem;
            SpatialReferenceEnvironmentClass spatialReferenceEnviorment = new SpatialReferenceEnvironmentClass();
            geographicCoordinateSystem = spatialReferenceEnviorment.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            spatialReference = (ISpatialReference)geographicCoordinateSystem;

            //set the geometry of the element
            IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
            point.SpatialReference = spatialReference;
            point.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Miny);

            IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass();
            point1.SpatialReference = spatialReference;
            point1.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Maxy);

            IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass();
            point2.SpatialReference = spatialReference;
            point2.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Maxy);

            IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass();

               point3.SpatialReference = spatialReference;
               point3.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Miny);

            IPointCollection pointCollection;
            pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass();

            object x = Type.Missing;
            object y = Type.Missing;

            pointCollection.AddPoint(point, ref x, ref y);
            pointCollection.AddPoint(point1, ref x, ref y);
            pointCollection.AddPoint(point2, ref x, ref y);
            pointCollection.AddPoint(point3, ref x, ref y);

            PolygonElementClass element = new PolygonElementClass();
            element.Symbol = simpleFillSymbol;
            element.SpatialReference = spatialReference;
            element.Geometry.SpatialReference = spatialReference;
            element.Geometry = (IGeometry)pointCollection;
            element.Geometry.Project(mxDoc.ActiveView.Extent.SpatialReference);

            //add the graphics element to the map
            IGraphicsContainer graphicsContainer;
            graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap;
            if (deleteelements) {
                graphicsContainer.DeleteAllElements();
            }
            graphicsContainer.AddElement(element, 0);
            if (refreshview) {
                mxDoc.ActiveView.Extent = element.Geometry.Envelope;
                mxDoc.ActiveView.Refresh();
            }
        }
Example #15
0
        /// <summary>
        /// 获得查询结果信息
        /// </summary>
        /// <param name="pGeometry">点</param>
        /// <param name="hdids">巷道ID</param>
        /// <param name="kind">表示巷道掘进还是回采掘进</param>
        /// <returns></returns>
        public Dictionary <string, List <GeoStruct> > GetStructsInfosNew(IPoint pGeometry, List <int> hdids = null, int kind = 1)
        {
            #region

            /*
             * 根据工作面中点坐标,查询对应的掘进面或者回采面的信息
             */
            List <IPoint>  pgeompts = CalculateCirclePnts(pGeometry as IPoint, 1);
            IPolygon       pgeom    = Global.commonclss.CreatePolygonFromPnts(pgeompts, Global.spatialref);
            IFeatureCursor feahds   = null;
            IFeature       feahd    = null;
            if (kind == 1)
            {
                feahds = SpatialSearch(pgeom, "1=1", Global.hdfdfulllyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询巷道分段
                feahd  = feahds.NextFeature();
            }
            else
            {
                feahds = SpatialSearch(pgeom, "1=1", Global.hcqlyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询回采工作面
                feahd  = feahds.NextFeature();
            }
            IGeometry geomsearch = feahd.Shape;
            IHitTest  hitest     = geomsearch as IHitTest;
            ESRI.ArcGIS.Geometry.IPoint hitPoint = new ESRI.ArcGIS.Geometry.PointClass();
            System.Double  hitDistance           = 0;
            System.Int32   hitPartIndex          = 0;
            System.Int32   hitSegmentIndex       = 0;
            System.Boolean rightSide             = false;
            bool           findgeom = hitest.HitTest(pGeometry, 1, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide);
            IPolyline      plingeom = new PolylineClass();
            if (findgeom == true)
            {
                IPolygon         polygon = geomsearch as IPolygon;
                IPointCollection pnts    = polygon as IPointCollection;

                IPoint pntstart = pnts.get_Point(hitSegmentIndex);
                IPoint pntend   = pnts.get_Point(hitSegmentIndex + 1);
                plingeom.FromPoint = pntstart;
                plingeom.ToPoint   = pntend;
            }
            #endregion
            Dictionary <string, List <GeoStruct> > results = new Dictionary <string, List <GeoStruct> >();
            //峒室 1
            List <GeoStruct> dss = BufferAnalyseNew(plingeom, Global.searchlen, Global.dslyr, geomsearch);
            results.Add("1", dss);
            //揭露断层 2
            List <GeoStruct> jls = BufferAnalyseNew(plingeom, Global.searchlen, Global.jllyr, geomsearch);
            results.Add("2", jls);
            //推断断层 3
            List <GeoStruct> tds = BufferAnalyseNew(plingeom, Global.searchlen, Global.tdlyr, geomsearch);
            results.Add("3", tds);
            //钻孔 4
            List <GeoStruct> zks = BufferAnalyseNew(plingeom, Global.searchlen, Global.zklyr, geomsearch);
            results.Add("4", zks);
            //陷落柱 5
            List <GeoStruct> xlzs = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr, geomsearch);
            results.Add("5", xlzs);
            //陷落柱1 6
            List <GeoStruct> xlz1s = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr1, geomsearch);
            results.Add("6", xlz1s);
            //井筒 7
            List <GeoStruct> jts = BufferAnalyseNew(plingeom, Global.searchlen, Global.jtlyr, geomsearch);
            results.Add("7", jts);
            //巷道层 8
            //List<GeoStruct> hds = BufferAnalyseNew(plingeom, Global.searchlen, Global.hdfdfulllyr, geomsearch);
            //for (int i = 0; i < hds.Count; i++)
            //{
            //    GeoStruct geostruct = hds[i];
            //    if (hdids != null)
            //    {
            //        for (int j = 0; j < hdids.Count; j++)
            //        {
            //            if (geostruct.geoinfos[GIS_Const.FIELD_HdId].ToString() == hdids[j].ToString())
            //            {
            //                hds.Remove(geostruct);
            //                i--;
            //            }
            //        }
            //    }
            //}
            //results.Add("8", hds);
            return(results);
        }
        private void DrawLegend(IEnvelope Envelope)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double BoxX = 0.4; //Width
            double BoxY = 0.3; //Height
            double Text2BoxY= 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double ColumnX = 0.5; //Space between columns

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();
            BlackInsides.Blue = 0;
            BlackInsides.Red = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();
            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument Doc = ArcMap.Document;
            IPageLayout pageLayout = Doc.ActiveView as IPageLayout;
            IGraphicsContainer GraphicsContainer = pageLayout as IGraphicsContainer;
            double Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double IndentTerm = 0;
            IPoint Point = null;
            double StringLength = 0;
            string LegendText = "";
            string ItemName = "";
            string ItemDesc = "";
            IElement Ele = null;
            IEnvelope TempEnv = null;
            IRgbColor BoxColr = null;
            ISimpleFillSymbol FillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement FillEle = null;
            IEnvelope FillEnv = new EnvelopeClass();
            WKSEnvelope Patch = new WKSEnvelope();
            IGeometry Geo = null;
            string LabelText = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint = new ESRI.ArcGIS.Geometry.PointClass();
            #endregion

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            // Loop through legend records
            foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
            {
                // Grab the DMU entry itself
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));

                // Find out how far to indent the legend item
                // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                // Get the coordinates of the text for the legend entry - upper left corner
                // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                Point = new PointClass();
                double xAdditions = 0;
                if (isHeading)
                {
                    // Xcoord plus (indentation), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1);
                }
                else
                {
                    //Xcoord plus (indentation) + (Box width and margin), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                }
                Point.PutCoords(Xcoord + xAdditions, Ycoord);

                // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                StringLength = 72 * (Envelope.Width - xAdditions);

                // Fix a couple of special characters in the legend string.
                // Then amalgamate item name and description
                ItemName = FixLegendTextCharacters(aDescription.Name);
                if (!isHeading)
                {
                    LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                }
                else
                {
                    LegendText = ItemName;
                }

                // Format the legend text if it is not a heading. If it is, we're fine.
                if (!isHeading)
                {
                    LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                }

                // Boldify the ItemName
                LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                // See if this legend item should be placed on a new column
                Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                TempEnv = new EnvelopeClass();
                Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                // If the height of the formatted text is larger than the box + space specified
                if (TempEnv.Height > BoxY + Text2BoxY)
                {
                    // If the text will spill out below the envelope drawn by the user
                    if (Ycoord - TempEnv.Height < Envelope.YMin)
                    {
                        // Move to a new column - the last number is a fudge factor, looks like it is in inches
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }
                else // The height of the formatted text is not larfer than the box + space defined
                {
                    // If the box itself will spill out below the envelope drawn by the user
                    if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                    {
                        // Move to a new column
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }

                // Add the text to the map
                GraphicsContainer.AddElement(Ele, 0);

                if (!isHeading)
                {
                    FillEnv = new EnvelopeClass();

                    Patch.XMin = Point.X - BoxX - Text2BoxX;
                    Patch.YMax =  Point.Y;
                    Patch.XMax = Point.X - Text2BoxX;
                    Patch.YMin = Point.Y - BoxY;
                    FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                    Geo = FillEnv as IGeometry;

                    // Get the color of the box
                    BoxColr = new RgbColorClass();
                    if (aDescription.AreaFillRGB == null)
                    {
                        BoxColr.Red = 255;
                        BoxColr.Green = 0;
                        BoxColr.Blue = 0;
                    }
                    else
                    {
                        BoxColr.Red = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                        BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                        BoxColr.Blue = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                    }

                    // Draw the fill
                    FillSym = new SimpleFillSymbolClass();
                    FillSym.Color = BoxColr;
                    FillSym.Style = esriSimpleFillStyle.esriSFSSolid;
                    FillSym.Outline = BlackOutsides;

                    FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                    // Label the box
                    LabelText = aDescription.Label;

                    // Subscripting!!

                    for (int i = 0; i < LabelText.Length; i++)
                    {
                        string thisBit = LabelText.Substring(i, 1);
                        int num;
                        if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                        {
                            LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                            i = i + 5;
                        }
                    }
                    LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                    LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                    // Center the label
                    LabelPoint = new PointClass();
                    LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                    LabelPoint.Y = Point.Y - BoxY / 2;

                    //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                    Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                    // Add the box and label
                    GraphicsContainer.AddElement(FillEle as IElement, 0);
                    GraphicsContainer.AddElement(Ele, 0);
                }

                // Do a partial refresh
                //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                // Setup the Y coordinates for the next entry
                // if the height of this item's text is bigger than the minimum distance between text and box
                if (TempEnv.Height > Text2BoxY)
                {
                    // Subtract the box height and the text height to get the new ycoord
                    Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                }
                else
                {
                    if (isHeading)
                    {
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        Ycoord = Ycoord - (BoxY + Text2BoxY);
                    }
                }
            }

            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }
        private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount)
        {
            IApplication pApp = (IApplication)ArcMap.Application;

            if (pApp == null)
            {
                //if the app is null then must be running from ArcCatalog...based on equivalent test in calling function.
                pApp = (IApplication)ArcCatalog.Application;
            }

            IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass();
            ITrackCancel           pTrackCancel          = new CancelTrackerClass();
            IStepProgressor        pStepProgressor       = pProgressorDialogFact.Create(pTrackCancel, pApp.hWnd);
            IProgressDialog2       pProgressorDialog     = (IProgressDialog2)pStepProgressor;

            try
            {
                pStepProgressor.MinRange    = 0;
                pStepProgressor.MaxRange    = PointTable.RowCount(null);
                pStepProgressor.StepValue   = 1;
                pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                bool bCont = true;

                IRow    pPointFeat = null;
                ICursor pPtCurs    = null;
                ChangedPointCount = 0;
                if (Unversioned)
                {
                    ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table
                    pPtCurs = pTableWr.UpdateRows(QueryFilter, false);
                }
                else
                {
                    pPtCurs = PointTable.Update(QueryFilter, false);
                }

                pPointFeat = pPtCurs.NextRow();

                int iPointIdx_X = pPtCurs.Fields.FindField("X");
                int iPointIdx_Y = pPtCurs.Fields.FindField("Y");

                pProgressorDialog.ShowDialog();
                pStepProgressor.Message = "Updating point data...";

                while (pPointFeat != null)
                {//loop through all of the fabric points, and if any of the point id values are in the deleted set,
                 //then remove the control name from the point's NAME field

                    bCont = pTrackCancel.Continue();
                    if (!bCont)
                    {
                        break;
                    }

                    IFeature pFeat     = (IFeature)pPointFeat;
                    IPoint   pPtSource = (IPoint)pFeat.ShapeCopy;

                    if (pPtSource == null)
                    {
                        Marshal.ReleaseComObject(pPointFeat); //garbage collection
                        pPointFeat = pPtCurs.NextRow();
                        continue;
                    }

                    if (pPtSource.IsEmpty)
                    {
                        Marshal.ReleaseComObject(pPointFeat); //garbage collection
                        pPointFeat = pPtCurs.NextRow();
                        continue;
                    }
                    IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass();
                    pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X));
                    pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y));

                    ILine pLine = new ESRI.ArcGIS.Geometry.LineClass();
                    pLine.PutCoords(pPtSource, pPtTarget);

                    if (pLine.Length > UpdateIfMoreThanTolerance)
                    {
                        pPointFeat.set_Value(iPointIdx_X, pPtSource.X);
                        pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y);

                        //if (Unversioned)
                        pPtCurs.UpdateRow(pPointFeat);
                        //else
                        //  pPointFeat.Store();
                        ChangedPointCount++;
                        string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString();
                        pStepProgressor.Message = "Updating point data..." + sCnt;
                    }

                    Marshal.ReleaseComObject(pPointFeat); //garbage collection
                    pPointFeat = pPtCurs.NextRow();

                    if (pStepProgressor.Position < pStepProgressor.MaxRange)
                    {
                        pStepProgressor.Step();
                    }
                }
                Marshal.ReleaseComObject(pPtCurs); //garbage collection
                return(bCont);
            }
            catch (COMException ex)
            {
                MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode));
                ChangedPointCount = 0;
                return(false);
            }
            finally
            {
                pStepProgressor = null;
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pProgressorDialog = null;
            }
        }
Example #18
0
        private void add2MapBtn_Click(object sender, EventArgs e)
        {
            if ( lam72 == null || adres == null ) return;

            IPoint fromXY = new ESRI.ArcGIS.Geometry.PointClass(){X = xAdres, Y= yAdres, SpatialReference = lam72 } ;
            IPoint toXY = geopuntHelper.Transform(fromXY as IGeometry, view.FocusMap.SpatialReference) as IPoint;

            IRgbColor innerClr = new RgbColor() { Red = 255, Blue = 0, Green = 255 };
            IRgbColor outlineClr = new RgbColor() { Red = 0, Blue = 0, Green = 0 };

            geopuntHelper.AddGraphicToMap(map, toXY, innerClr, outlineClr, 12, false);
            geopuntHelper.AddTextElement(map, toXY, adres);

            view.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #19
0
        /// <summary>
        /// 获得查询结果信息
        /// </summary>
        /// <params name="pGeometry">点</params>
        /// <params name="hdids">巷道ID</params>
        /// <params name="kind">表示巷道掘进还是回采掘进</params>
        /// <returns></returns>
        public Dictionary<string, List<GeoStruct>> GetStructsInfosNew(IPoint pGeometry, List<int> hdids = null, int kind = 1)
        {
            #region
            /*
             * 根据工作面中点坐标,查询对应的掘进面或者回采面的信息
             */
            List<IPoint> pgeompts = CalculateCirclePnts(pGeometry as IPoint, 1);
            IPolygon pgeom = Global.commonclss.CreatePolygonFromPnts(pgeompts, Global.spatialref);
            IFeatureCursor feahds = null;
            IFeature feahd = null;
            if (kind == 1)
            {
                feahds = SpatialSearch(pgeom, "1=1", Global.hdfdfulllyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询巷道分段
                feahd = feahds.NextFeature();
            }
            else
            {
                feahds = SpatialSearch(pgeom, "1=1", Global.hcqlyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询回采工作面
                feahd = feahds.NextFeature();
            }
            IGeometry geomsearch = feahd.Shape;
            IHitTest hitest = geomsearch as IHitTest;
            ESRI.ArcGIS.Geometry.IPoint hitPoint = new ESRI.ArcGIS.Geometry.PointClass();
            System.Double hitDistance = 0;
            System.Int32 hitPartIndex = 0;
            System.Int32 hitSegmentIndex = 0;
            System.Boolean rightSide = false;
            bool findgeom = hitest.HitTest(pGeometry, 1, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide);
            IPolyline plingeom = new PolylineClass();
            if (findgeom == true)
            {
                IPolygon polygon = geomsearch as IPolygon;
                IPointCollection pnts = polygon as IPointCollection;

                IPoint pntstart = pnts.get_Point(hitSegmentIndex);
                IPoint pntend = pnts.get_Point(hitSegmentIndex + 1);
                plingeom.FromPoint = pntstart;
                plingeom.ToPoint = pntend;
            }
            #endregion
            Dictionary<string, List<GeoStruct>> results = new Dictionary<string, List<GeoStruct>>();
            //峒室 1
            List<GeoStruct> dss = BufferAnalyseNew(plingeom, Global.searchlen, Global.dslyr, geomsearch);
            results.Add("1", dss);
            //揭露断层 2
            List<GeoStruct> jls = BufferAnalyseNew(plingeom, Global.searchlen, Global.jllyr, geomsearch);
            results.Add("2", jls);
            //推断断层 3
            List<GeoStruct> tds = BufferAnalyseNew(plingeom, Global.searchlen, Global.tdlyr, geomsearch);
            results.Add("3", tds);
            //钻孔 4
            List<GeoStruct> zks = BufferAnalyseNew(plingeom, Global.searchlen, Global.zklyr, geomsearch);
            results.Add("4", zks);
            //陷落柱 5
            List<GeoStruct> xlzs = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr, geomsearch);
            results.Add("5", xlzs);
            //陷落柱1 6
            List<GeoStruct> xlz1s = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr1, geomsearch);
            results.Add("6", xlz1s);
            //井筒 7
            List<GeoStruct> jts = BufferAnalyseNew(plingeom, Global.searchlen, Global.jtlyr, geomsearch);
            results.Add("7", jts);
            //巷道层 8
            //List<GeoStruct> hds = BufferAnalyseNew(plingeom, Global.searchlen, Global.hdfdfulllyr, geomsearch);
            //for (int i = 0; i < hds.Count; i++)
            //{
            //    GeoStruct geostruct = hds[i];
            //    if (hdids != null)
            //    {
            //        for (int j = 0; j < hdids.Count; j++)
            //        {
            //            if (geostruct.geoinfos[GIS_Const.FIELD_HdId].ToString() == hdids[j].ToString())
            //            {
            //                hds.Remove(geostruct);
            //                i--;
            //            }
            //        }
            //    }
            //}
            //results.Add("8", hds);
            return results;
        }
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            //add all point
            List <IPoint> pointList = new List <IPoint>();

            Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.Application();
            object missing = System.Reflection.Missing.Value;

            myExcel.Application.Workbooks.Open(textBoxX1.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //this.txtFile.Text为Excel文件的全路径
            Microsoft.Office.Interop.Excel.Workbook myBook = myExcel.Workbooks[1];

            //获取第一个Sheet
            Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)myBook.Sheets[1];
            string sheetName = sheet.Name; //Sheet名

            myBook.Close(Type.Missing, Type.Missing, Type.Missing);
            myExcel.Quit();

            //read excel file to creat Field
            string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxX1.Text + ";Extended Properties=Excel 8.0";
            OleDbConnection conn   = new OleDbConnection(strCon);
            string          sql1   = string.Format("select * from [{0}$]", sheetName);

            conn.Open();

            OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon);
            DataSet          ds        = new DataSet();

            myCommand.Fill(ds);
            conn.Close();

            int xIndex = 0;
            int yIndex = 0;
            int zIndex = 0;

            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
            {
                if (ds.Tables[0].Columns[i].ColumnName == "X_经度")
                {
                    xIndex = i;
                }
                if (ds.Tables[0].Columns[i].ColumnName == "Y_纬度")
                {
                    yIndex = i;
                }
                if (ds.Tables[0].Columns[i].ColumnName.Contains("Z_高程"))
                {
                    zIndex = i;
                }
            }

            ISpatialReference pSpaReference = new UnknownCoordinateSystemClass();

            pSpaReference.SetDomain(-8000000, 8000000, -800000, 8000000);
            IFeatureClass pFt = CreateShapeFile(ds, this.textBoxX2.Text, pSpaReference);

            if (pFt == null)
            {
                return;
            }
            else
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //根据XY坐标添加点,edit attribute
                    IsNumberic isNum = new IsNumberic();
                    ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
                    if (ds.Tables[0].Rows[i][xIndex].ToString() == "" || ds.Tables[0].Rows[i][xIndex].ToString() == " ")
                    {
                        break;
                    }
                    if (isNum.IsNumber(ds.Tables[0].Rows[i][xIndex].ToString()) && isNum.IsNumber(ds.Tables[0].Rows[i][yIndex].ToString()))
                    {
                        pPoint.X = System.Convert.ToSingle(ds.Tables[0].Rows[i][xIndex].ToString());
                        pPoint.Y = System.Convert.ToSingle(ds.Tables[0].Rows[i][yIndex].ToString());
                        pPoint.Z = System.Convert.ToSingle(ds.Tables[0].Rows[i][zIndex].ToString());
                        IFeature pFeature = pFt.CreateFeature();
                        pFeature.Shape = pPoint;

                        pFeature.Store();
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            if (ds.Tables[0].Columns[j].ColumnName.Contains("里程"))
                            {
                                continue;
                            }
                            //pFeature.set_Value(pFeature.Fields.FindField(ds.Tables[0].Columns[j].ColumnName), ds.Tables[0].Rows[i][j]);
                            pFeature.set_Value(j + 2, ds.Tables[0].Rows[i][j].ToString());
                        }
                        pFeature.Store();

                        pointList.Add(pPoint);
                    }
                    else
                    {
                        MessageBox.Show("the" + i + "rows x and y value is unvalid!");
                    }
                }
            }

            ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon();
            string           strInputPath      = System.IO.Path.GetDirectoryName(textBoxX2.Text);
            string           strInputName      = System.IO.Path.GetFileName(textBoxX2.Text);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFt;
            pFeatureLayer.Name         = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(strInputName));


            //create line shape file
            IPointCollection PointCollection = ReadPoint(pFeatureLayer);
            string           lineName        = strInputPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInputName) + "_line.shp";

            CreateLineShpFile(lineName, pSpaReference);
            //将所有的点连接成线
            List <IPolyline> Polyline       = CreatePolyline(PointCollection);
            List <double>    lineLengthList = new List <double>();
            //将连接成的线添加到线图层中
            string pLineFile = lineName;
            string pFilePath = System.IO.Path.GetDirectoryName(pLineFile);
            string pFileName = System.IO.Path.GetFileName(pLineFile);
            //打开工作空间
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS  = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0);
            //写入实体对象
            IFeatureLayer plineLayer = new FeatureLayerClass();

            plineLayer.FeatureClass = pWS.OpenFeatureClass(pFileName);
            AddFeature(plineLayer, Polyline, pointList, lineLengthList);
            plineLayer.Name = pFeatureLayer.Name + "_line";

            m_pMapCtl.AddLayer(plineLayer as ILayer, 0);
            m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0);
            m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            ImpSymbolFromFile(textBoxX3.Text, pFeatureLayer, plineLayer);

            this.Close();
        }
Example #21
0
        public void ZoomToSelectedGlobeFeatures(ESRI.ArcGIS.GlobeCore.IGlobe globe, IEnvelope pEv, string name)
        {
            ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay = globe.GlobeDisplay;
            ESRI.ArcGIS.Analyst3D.ISceneViewer  sceneViewer  = globeDisplay.ActiveViewer;
            ESRI.ArcGIS.Analyst3D.ICamera       camera       = sceneViewer.Camera;
            ESRI.ArcGIS.GlobeCore.IGlobeCamera  globeCamera  = (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera;
            ESRI.ArcGIS.Analyst3D.IScene        scene        = globeDisplay.Scene;


            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.SetEmpty();
            ESRI.ArcGIS.Geometry.IEnvelope layersExtentEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            layersExtentEnvelope.SetEmpty();
            ESRI.ArcGIS.Geometry.IZAware ZAware = (ESRI.ArcGIS.Geometry.IZAware)envelope;
            ZAware.ZAware = (true);


            envelope.Union(pEv);
            IFeatureLayer pFlyr = null;

            for (int i = 0; i < scene.LayerCount; ++i)
            {
                if (scene.get_Layer(i).Name == name)
                {
                    pFlyr = scene.get_Layer(i) as IFeatureLayer;
                    break;
                }
            }
            ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)pFlyr;
            if (geoDataset != null)
            {
                ESRI.ArcGIS.Geometry.IEnvelope layerExtent = geoDataset.Extent;
                layersExtentEnvelope.Union(layerExtent);
            }


            System.Double width  = envelope.Width;
            System.Double height = envelope.Height;
            if (width == 0.0 && height == 0.0)
            {
                System.Double dim = 1.0;


                System.Boolean bEmpty = layersExtentEnvelope.IsEmpty;
                if (!bEmpty)
                {
                    System.Double layerWidth  = layersExtentEnvelope.Width;
                    System.Double layerHeight = layersExtentEnvelope.Height;
                    System.Double layerDim    = System.Math.Max(layerWidth, layerHeight) * 0.05;
                    if (layerDim > 0.0)
                    {
                        dim = System.Math.Min(1.0, layerDim);
                    }
                }


                System.Double xMin = envelope.XMin;
                System.Double yMin = envelope.YMin;


                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.X = xMin;
                point.Y = yMin;


                envelope.Width  = dim * 0.8;
                envelope.Height = dim * 0.8;
                envelope.CenterAt(point);
            }
            else if (width == 0.0 || height == 0.0)
            {
                System.Double maxDim = System.Math.Max(width, height);
                envelope.Width  = maxDim;
                envelope.Height = maxDim;
            }


            globeCamera.SetToZoomToExtents(envelope, globe, sceneViewer);
            sceneViewer.Redraw(true);
        }
        private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount)
        {
            IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass();
              ITrackCancel pTrackCancel = new CancelTrackerClass();
              IStepProgressor pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd);
              IProgressDialog2 pProgressorDialog = (IProgressDialog2)pStepProgressor;
              try
              {
            pStepProgressor.MinRange = 0;
            pStepProgressor.MaxRange = PointTable.RowCount(null);
            pStepProgressor.StepValue = 1;
            pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
            bool bCont = true;

            IRow pPointFeat = null;
            ICursor pPtCurs = null;
            ChangedPointCount = 0;
            if (Unversioned)
            {
              ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table
              pPtCurs = pTableWr.UpdateRows(QueryFilter, false);
            }
            else
              pPtCurs = PointTable.Update(QueryFilter, false);

            pPointFeat = pPtCurs.NextRow();

            int iPointIdx_X = pPtCurs.Fields.FindField("X");
            int iPointIdx_Y = pPtCurs.Fields.FindField("Y");

            pProgressorDialog.ShowDialog();
            pStepProgressor.Message = "Updating point data...";

            while (pPointFeat != null)
            {//loop through all of the fabric points, and if any of the point id values are in the deleted set,
              //then remove the control name from the point's NAME field

              bCont = pTrackCancel.Continue();
              if (!bCont)
            break;

              IFeature pFeat = (IFeature)pPointFeat;
              IPoint pPtSource = (IPoint)pFeat.ShapeCopy;

              if (pPtSource == null)
              {
            Marshal.ReleaseComObject(pPointFeat); //garbage collection
            pPointFeat = pPtCurs.NextRow();
            continue;
              }

              if (pPtSource.IsEmpty)
              {
            Marshal.ReleaseComObject(pPointFeat); //garbage collection
            pPointFeat = pPtCurs.NextRow();
            continue;
              }
              IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass();
              pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X));
              pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y));

              ILine pLine = new ESRI.ArcGIS.Geometry.LineClass();
              pLine.PutCoords(pPtSource, pPtTarget);

              if (pLine.Length > UpdateIfMoreThanTolerance)
              {
            pPointFeat.set_Value(iPointIdx_X, pPtSource.X);
            pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y);

            //if (Unversioned)
              pPtCurs.UpdateRow(pPointFeat);
            //else
            //  pPointFeat.Store();
            ChangedPointCount++;
            string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString();
            pStepProgressor.Message = "Updating point data..." + sCnt;
              }

              Marshal.ReleaseComObject(pPointFeat); //garbage collection
              pPointFeat = pPtCurs.NextRow();

              if (pStepProgressor.Position < pStepProgressor.MaxRange)
            pStepProgressor.Step();

            }
            Marshal.ReleaseComObject(pPtCurs); //garbage collection
            return bCont;

              }
              catch (COMException ex)
              {
            MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode));
            ChangedPointCount = 0;
            return false;
              }
              finally
              {
            pStepProgressor = null;
            if (!(pProgressorDialog == null))
              pProgressorDialog.HideDialog();
            pProgressorDialog = null;
              }
        }
Example #23
0
 public IBalloonCallout CreateBalloonCallout(double x, double y)
 {
     IRgbColor pRgbClr = new RgbColorClass();
     pRgbClr.Red = 255;
     pRgbClr.Blue = 255;
     pRgbClr.Green = 255;
     ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass();
     pSmplFill.Color = pRgbClr;
     pSmplFill.Style = esriSimpleFillStyle.esriSFSSolid;
     IBalloonCallout pBllnCallout = new BalloonCalloutClass();
     pBllnCallout.Style = esriBalloonCalloutStyle.esriBCSRectangle;
     pBllnCallout.Symbol = pSmplFill;
     pBllnCallout.LeaderTolerance = 1;
     IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
     pPoint.X = x;
     pPoint.Y = y;
     pBllnCallout.AnchorPoint = pPoint;
     return pBllnCallout;
 }
Example #24
0
 private void MapViewer_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     ESRI.ArcGIS.Geometry.Point pPoint = new ESRI.ArcGIS.Geometry.PointClass();
     pPoint.PutCoords(e.mapX, e.mapY);
     MainMap.CenterAt(pPoint);
 }
Example #25
0
        /// <summary>
        /// 面积、体积统计及三维效果绘制    张琪  20110629
        /// </summary>
        private void StaTisTic()
        {
            SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条");
            try
            {
                vProgress.EnableCancel    = false;//设置进度条
                vProgress.ShowDescription = true;
                vProgress.FakeProgress    = true;
                vProgress.TopMost         = true;
                vProgress.ShowProgress();
                vProgress.SetProgress("正在计算");
                object before = Type.Missing;
                object after  = Type.Missing;
                if (m_StaPolygon == null)
                {
                    txtArea2DSel.Text   = m_SurFace.GetProjectedArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString();
                    txtAreaAbove.Text   = m_SurFace.GetSurfaceArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString();
                    txtAreaBelow.Text   = m_SurFace.GetSurfaceArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow).ToString();
                    txtVolumeBelow.Text = m_SurFace.GetVolume(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow).ToString();
                    txtVolumeAbove.Text = m_SurFace.GetVolume(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString();
                }
                else//在地图上绘制多边形时
                {
                    if (m_IsTin)//为true是指数据为TIN
                    {
                        ITinSurface  pTinsurface  = m_SurFace as ITinSurface;
                        ITinAdvanced pTinAdvanced = pTinsurface as ITinAdvanced;
                        ////ITriangleLabelInPolyFilter  = new
                        //ITinFilter pTCFilterBasic = pTCFilter as ITinFilter;
                        //pTCFilterBasic.DataElementsOnly = true;
                        int Criteria = 4;
                        IEnumTinTriangle pEnumTriangles = pTinAdvanced.MakeTriangleEnumerator(m_StaPolygon.Envelope, Criteria, null);
                        object           dVolumeBelow   = null;
                        object           dSurfaceArea   = null;
                        object           dProjectedArea = null;
                        //根据绘制的多边形和Z值来计算基准面以上的面积和体积
                        pTinsurface.GetPartialVolumeAndArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove, pEnumTriangles, ref dVolumeBelow, ref dSurfaceArea, ref dProjectedArea);
                        txtAreaAbove.Text   = Convert.ToDouble(dSurfaceArea).ToString();
                        txtVolumeAbove.Text = dVolumeBelow.ToString();
                        txtArea2DSel.Text   = dProjectedArea.ToString();
                        //根据绘制的多边形和Z值来计算基准面以下的面积和体积
                        pTinsurface.GetPartialVolumeAndArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow, pEnumTriangles, ref dVolumeBelow, ref dSurfaceArea, ref dProjectedArea);
                        txtAreaBelow.Text   = dSurfaceArea.ToString();
                        txtVolumeBelow.Text = dVolumeBelow.ToString();
                    }
                    else
                    {
                        MessageBox.Show("抱歉该功能暂不支持Raster数据", "提示!");

                        vProgress.Close();
                        return;
                    }
                }

                IPointCollection            pPolygon;
                ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
                //IPolygon pOutPoly;
                if (m_StaPolygon == null)//当绘制范围为空,获取整张图的范围
                {
                    pPolygon = new PolygonClass();
                    IZAware pZawre;
                    pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                    pPoint.X      = m_SurFace.Domain.Envelope.XMin;
                    pPoint.Y      = m_SurFace.Domain.Envelope.YMin;
                    pZawre        = pPoint as IZAware;
                    pZawre.ZAware = true;
                    pPoint.Z      = Convert.ToDouble(txtPlaneHeight.Text);
                    pPolygon.AddPoint(pPoint, ref before, ref after);

                    pPoint                  = new ESRI.ArcGIS.Geometry.PointClass();
                    pZawre                  = pPoint as IZAware;
                    pZawre.ZAware           = true;
                    pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                    pPoint.X                = m_SurFace.Domain.Envelope.XMax;
                    pPoint.Y                = m_SurFace.Domain.Envelope.YMin;
                    pPoint.Z                = Convert.ToDouble(txtPlaneHeight.Text);
                    pPolygon.AddPoint(pPoint, ref before, ref after);

                    pPoint                  = new ESRI.ArcGIS.Geometry.PointClass();
                    pZawre                  = pPoint as IZAware;
                    pZawre.ZAware           = true;
                    pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                    pPoint.X                = m_SurFace.Domain.Envelope.XMax;
                    pPoint.Y                = m_SurFace.Domain.Envelope.YMax;
                    pPoint.Z                = Convert.ToDouble(txtPlaneHeight.Text);
                    pPolygon.AddPoint(pPoint, ref before, ref after);

                    pPoint                  = new ESRI.ArcGIS.Geometry.PointClass();
                    pZawre                  = pPoint as IZAware;
                    pZawre.ZAware           = true;
                    pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                    pPoint.X                = m_SurFace.Domain.Envelope.XMin;
                    pPoint.Y                = m_SurFace.Domain.Envelope.YMax;
                    pPoint.Z                = Convert.ToDouble(txtPlaneHeight.Text);
                    pPolygon.AddPoint(pPoint, ref before, ref after);

                    pPoint                  = new ESRI.ArcGIS.Geometry.PointClass();
                    pZawre                  = pPoint as IZAware;
                    pZawre.ZAware           = true;
                    pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                    pPoint.X                = m_SurFace.Domain.Envelope.XMin;
                    pPoint.Y                = m_SurFace.Domain.Envelope.YMin;
                    pPoint.Z                = Convert.ToDouble(txtPlaneHeight.Text);
                    pPolygon.AddPoint(pPoint, ref before, ref after);
                    //获得整张图范围组成的多边形
                    IGeometry pGeometry = pPolygon as IGeometry;
                    pGeometry.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference;
                }
                else
                {
                    pPolygon = m_StaPolygon as IPointCollection;
                }

                if (pPolygon == null)
                {
                    vProgress.Close();
                    return;
                }
                //显示参考面
                ShowRefPlane(pPolygon as IPolygon);
                //显示周边
                ShowCountour(pPolygon as IPolygon);
                //获取轮廓线的周长
                m_ScenePoly = pPolygon as IPolygon;
                ITopologicalOperator pTopo     = pPolygon as ITopologicalOperator;
                IPolyline            pPolyLine = pTopo.Boundary as IPolyline;
                txtPara.Text = pPolyLine.Length.ToString();
                vProgress.Close();
            }
            catch
            {
                vProgress.Close();
            }
        }
Example #26
0
        /// <summary>
        /// 通过鼠标点击获取观察点与被观察点同时进行两点间通视分析
        /// </summary>
        /// <param name="Button"></param>
        /// <param name="Shift"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_frm3DLineOfSight.m_Layer == null || m_frm3DLineOfSight.m_Surface == null)
            {
                MessageBox.Show("请设置有效的表面数据", "提示!");
                return;
            }
            if (m_frm3DLineOfSight.txtObsOffset.Text == "" || m_frm3DLineOfSight.txtTarOffset.Text == "")
            {
                MessageBox.Show("观察点高度和被观察点高度不能为空", "提示!");
                return;
            }
            m_frm3DLineOfSight.TopMost = true;
            ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph;

            m_pNewLineFeedback = new NewLineFeedbackClass();
            IPolyline       pPolyline        = m_pNewLineFeedback.Stop(); //用于判断是否已经获取两点
            ISceneControl   pSceneControl    = m_sceneHookHelper.Hook as ISceneControl;
            Cls3DModulsefun pCls3DModulsefun = new Cls3DModulsefun();     //用于绘制通视分析结果的方法
            object          pOwner;
            object          pObject;

            ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
            pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out pOwner, out pObject);//获取鼠标点击的位置并转化为地理坐标
            if (pPoint == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IPoint pFlashPoint = new ESRI.ArcGIS.Geometry.PointClass();
            IClone pClone = pPoint as IClone;

            pFlashPoint   = pClone.Clone() as ESRI.ArcGIS.Geometry.IPoint;
            pFlashPoint.Z = pFlashPoint.Z / pSceneGraph.VerticalExaggeration;
            pFlashPoint.SpatialReference = pSceneGraph.Scene.SpatialReference;
            IDisplay3D pDisplay = pSceneGraph as IDisplay3D;

            pDisplay.FlashLocation(pFlashPoint);//闪烁显示被点击的位置
            IGeometry pGeometry = null;

            if (m_pScenePoints == null)
            {
                m_pScenePoints             = new PolylineClass();
                pGeometry                  = m_pScenePoints as IGeometry;
                pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference;
            }
            object before = Type.Missing;
            object after  = Type.Missing;

            m_pScenePoints.AddPoint(pPoint, ref before, ref after);//添加获取的点到点集合中
            if (m_pScenePoints.PointCount == 2)
            {
                pClone         = m_pScenePoints as IClone;
                pPolyline      = pClone.Clone() as  ESRI.ArcGIS.Geometry.IPolyline;//当点集合中点数达到两个时生成一条线用于判断观察点与被观察点是否确定
                m_pScenePoints = null;
            }
            if (pPolyline != null)
            {
                m_pScenePoints = null;
                ISurface pSurface = m_SurFace;
                ESRI.ArcGIS.Geometry.IPoint fPoint = pPolyline.FromPoint; //获取观察点
                fPoint.Z = pSurface.GetElevation(fPoint);                 //获取观察点的高程
                ESRI.ArcGIS.Geometry.IPoint tPoint = pPolyline.ToPoint;
                tPoint.Z = pSurface.GetElevation(tPoint);
                if (pSurface.IsVoidZ(fPoint.Z) || pSurface.IsVoidZ(tPoint.Z))
                {
                    return;
                }
                fPoint.Z = fPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtObsOffset.Text);//观察者的高度加上观察者所在的高程才是观察点实际的高程
                tPoint.Z = tPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtTarOffset.Text);
                ESRI.ArcGIS.Geometry.IPoint pObstruct;
                IPolyline pVisPolyline;
                IPolyline pInVisPolyline;
                bool      bIsVis;
                object    pRefractionFactor = Type.Missing;
                //进行两点间的通视分析
                pSurface.GetLineOfSight(fPoint, tPoint, out pObstruct, out pVisPolyline, out pInVisPolyline, out bIsVis, m_frm3DLineOfSight.checkBoxCurv.Checked, m_frm3DLineOfSight.checkBoxCurv.Checked, ref pRefractionFactor);

                ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                pSimpleLineSymbol.Width = 2;
                pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                //绘制可视与不可视的沿地表线要素
                if (pVisPolyline != null)
                {
                    pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0);
                    pCls3DModulsefun.AddGraphic(pSceneControl, pVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol);
                }
                if (pInVisPolyline != null)
                {
                    pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0);
                    pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol);
                }
                IGeometryCollection pVisPatch = new MultiPatchClass();//用于存储可视域的要素
                pGeometry = pVisPatch as IGeometry;
                pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference;
                double              dTargetHeightForVis = 0;
                ISimpleFillSymbol   pSimpleFillSymbol   = new SimpleFillSymbolClass();
                IGeometryCollection pInVisPatch         = new MultiPatchClass();//存储不可视域的要素
                pGeometry = pInVisPatch as IGeometry;
                pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference;
                IGeometryCollection pPathGeo = pInVisPolyline as IGeometryCollection;
                if (pPathGeo != null)
                {
                    //下面的作用是将不可视域线每段path生成线要素进行绘制       张琪  20110623
                    for (int i = 0; i < pPathGeo.GeometryCount; i++)
                    {
                        IGeometryCollection pInPolyline = new PolylineClass();
                        IPath path = pPathGeo.get_Geometry(i) as IPath;
                        pInPolyline.AddGeometry(path as IGeometry, ref before, ref after);
                        pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInPolyline as IPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis);
                    }
                }
                else//当不可视域为空时,直接分析生成可视域与不可视域
                {
                    pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInVisPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis);
                }
                //
                // 对可视域与不可视域要素在场景中绘制出来
                if (pInVisPatch != null)
                {
                    pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0);
                    pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPatch as IGeometry, pSimpleFillSymbol as ISymbol);
                }
                if (pVisPatch != null)
                {
                    pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0);
                    pCls3DModulsefun.AddGraphic(pSceneControl, pVisPatch as IGeometry, pSimpleFillSymbol as ISymbol);
                }
            }
        }
Example #27
0
        /// <summary>
        /// TIN数据转栅格数据并进行坡度分析      张琪    20110614
        /// </summary>
        /// <param name="pTinAdvanced"></param>
        /// <param name="pRastConvType"></param>
        /// <param name="sDir"></param>
        /// <param name="sName"></param>
        /// <param name="ePixelType"></param>
        /// <param name="cellsize"></param>
        /// <param name="pExtent"></param>
        /// <param name="bPerm"></param>
        /// <param name="strType"></param>
        /// <returns></returns>
        public IRasterDataset TinToRaster(ITinAdvanced pTinAdvanced, esriRasterizationType pRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm, String strType)
        {
            try
            {
                ESRI.ArcGIS.Geometry.IPoint pOrigin = pExtent.LowerLeft;
                pOrigin.X = pOrigin.X - (cellsize * 0.5);
                pOrigin.Y = pOrigin.Y - (cellsize * 0.5);
                int nCol, nRow;
                nCol = Convert.ToInt32(Math.Round(pExtent.Width / cellsize)) + 1;
                nRow = Convert.ToInt32(Math.Round(pExtent.Height / cellsize)) + 1;
                IGeoDataset         pGeoDataset        = pTinAdvanced as IGeoDataset;
                ISpatialReference2  pSpatialReference2 = pGeoDataset.SpatialReference as ISpatialReference2;
                IRasterDataset      pRasterDataset     = CreateRasterSurf(sDir, sName, strType, pOrigin, nCol, nRow, cellsize, cellsize, ePixelType, pSpatialReference2, bPerm);
                IRawPixels          pRawPixels         = GetRawPixels(pRasterDataset, 0);
                object              pCache             = pRawPixels.AcquireCache();
                ITinSurface         pTinSurface        = pTinAdvanced as ITinSurface;
                IGeoDatabaseBridge2 pbridge2           = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass();

                IRasterProps pRasterProps = pRawPixels as IRasterProps;
                //float nodataFloat;
                //int nodataInt;
                double dZMin = pTinAdvanced.Extent.ZMin;
                object vNoData;
                if (ePixelType.ToString() == "PT_FLOAT")
                {
                    vNoData = (dZMin - 1).ToString();
                }
                else
                {
                    vNoData = Convert.ToInt32((dZMin - 1));
                }
                pRasterProps.NoDataValue = vNoData;
                IPnt pOffset    = new DblPntClass();
                int  lMaxBlockX = 2048;
                if (nCol < lMaxBlockX)
                {
                    lMaxBlockX = nCol;
                }
                int lMaxBlockY = 2048;
                if (nRow < lMaxBlockY)
                {
                    lMaxBlockY = nRow;
                }
                IPnt pBlockSize = new DblPntClass();
                pBlockSize.X = lMaxBlockX;
                pBlockSize.Y = lMaxBlockY;
                IPixelBlock3 pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3;
                object       blockArray  = pPixelBlock.get_PixelDataByRef(0);
                ITrackCancel pCancel     = new CancelTrackerClass();
                pCancel.CancelOnClick    = false;
                pCancel.CancelOnKeyPress = true;
                int lBlockCount = Convert.ToInt32(Math.Round((nCol / lMaxBlockX) + 0.49) * Math.Round((nRow / lMaxBlockY) + 0.49));
                ESRI.ArcGIS.Geometry.IPoint pBlockOrigin = new ESRI.ArcGIS.Geometry.PointClass();
                int lColOffset, lRowOffset;

                for (lRowOffset = 0; lRowOffset < (nRow - 1);)
                {
                    for (lColOffset = 0; lColOffset < (nCol - 1);)
                    {
                        if ((nCol - lColOffset) < lMaxBlockX)
                        {
                            pBlockSize.X = (nCol - lColOffset);
                            pPixelBlock  = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3;
                            blockArray   = pPixelBlock.get_PixelDataByRef(0);
                        }
                        pBlockOrigin.X = pOrigin.X + (lColOffset * cellsize) + (cellsize * 0.5);
                        pBlockOrigin.Y = pOrigin.Y + ((nRow - lRowOffset) * cellsize) - (cellsize * 0.5);
                        pbridge2.QueryPixelBlock(pTinSurface, pBlockOrigin.X, pBlockOrigin.Y, cellsize, cellsize, pRastConvType, vNoData, ref blockArray);
                        //pTinSurface.QueryPixelBlock(pBlockOrigin.X, pBlockOrigin.Y, cellsize, cellsize, pRastConvType, vNoData, blockArray);
                        pOffset.X = lColOffset;
                        pOffset.Y = lRowOffset;
                        pPixelBlock.set_PixelData(0, (System.Object)blockArray);
                        pRawPixels.Write(pOffset, pPixelBlock as IPixelBlock);
                        if (lBlockCount > 1)
                        {
                            if (!pCancel.Continue())
                            {
                                break;
                            }
                            else if (pTinAdvanced.ProcessCancelled)
                            {
                                break;
                            }
                        }
                        lColOffset = lColOffset + lMaxBlockX;
                    }
                    bool bReset = false;
                    if (pBlockSize.X != lMaxBlockX)
                    {
                        pBlockSize.X = lMaxBlockX;
                        bReset       = true;
                    }
                    if ((nRow - lRowOffset) < lMaxBlockY)
                    {
                        pBlockSize.Y = (nRow - lRowOffset);
                        bReset       = true;
                    }
                    if (bReset)
                    {
                        pPixelBlock.set_PixelData(0, blockArray);
                        pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3;
                        blockArray  = pPixelBlock.get_PixelDataByRef(0);
                    }
                    lRowOffset = lRowOffset + lMaxBlockY;
                }

                pRawPixels.ReturnCache(pCache);
                pCache         = null;
                pRawPixels     = null;
                pPixelBlock    = null;
                pRasterProps   = null;
                blockArray     = 0;
                pRasterDataset = OpenRasterDataset(sDir, sName);
                if (lBlockCount == 1)
                {
                    pTinAdvanced.TrackCancel = null;
                }
                return(pRasterDataset);
            }
            catch
            {
                return(null);
            }
        }
Example #28
0
        /// <summary>
        /// 绘制点缓冲
        /// </summary>
        private void DrawBufferByPoint(ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt)
        {
            //1.连接服务器
            AGSServerConnection connection = new AGSServerConnection();

            connection.Host = "localhost";
            connection.Connect();

            //2.获得服务器
            IServerObjectManager pSom      = connection.ServerObjectManager;
            IServerContext       pSc       = pSom.CreateServerContext("china", "MapServer");//服务名和类型
            IMapServer           mapServer = pSc.ServerObject as IMapServer;

            //3.使用服务器对象 几何对象转换
            IMapServerObjects pMso = mapServer as IMapServerObjects;
            //ESRI.ArcGIS.Geometry.IGeometry comPt = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(adfPt, pSc)
            //    as ESRI.ArcGIS.Geometry.IGeometry;////ValueObjectToComObject(pnt, pSC);
            IPoint pt = new ESRI.ArcGIS.Geometry.PointClass();

            pt.X = adfPt.X;
            pt.Y = adfPt.Y;
            ESRI.ArcGIS.Geometry.IGeometry comPt = pt;

            ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
            ISpatialReference pSR = sre.CreateGeographicCoordinateSystem(4326);

            comPt.SpatialReference = pSR;

            //绘制buffer
            ITopologicalOperator pTOPO = comPt as ITopologicalOperator;

            pTOPO.Simplify();//??
            double   bufDis  = Map1.Extent.Width / 2;
            IPolygon bufPoly = pTOPO.Buffer(10) as IPolygon;

            bufPoly.Densify(0, 0);
            ESRI.ArcGIS.ADF.ArcGISServer.PolygonN valuePolyN = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufPoly, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)) as ESRI.ArcGIS.ADF.ArcGISServer.PolygonN;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon  adfPoly    = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(valuePolyN) as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;


            #region Densify
            ////***Densify
            // ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)bufPoly;
            // ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(com_pointcollection, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.poly));
            //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
            //for (int i = 0; i < com_pointcollection.PointCount - 1; i++)
            //{
            //    ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_pt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();
            //    new_adf_pt.X = com_pointcollection.get_Point(i).X;
            //    new_adf_pt.Y = com_pointcollection.get_Point(i).Y;
            //    new_adf_pointcollection.Add(new_adf_pt);
            //}
            //ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
            //new_adf_ring.Points = new_adf_pointcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
            //new_adf_ringcollection.Add(new_adf_ring);
            //ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
            //new_adf_polygon.Rings = new_adf_ringcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = new_adf_polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            ////*******Densify
            #endregion

            ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = adfPoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            GraphicElement geoEle = new GraphicElement(geom, System.Drawing.Color.Red);
            try
            {
                Map1.Zoom(adfPoly);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            geoEle.Symbol.Transparency = 50;

            IEnumerable gfc = Map1.GetFunctionalities();

            MapResource gMap = null;
            foreach (IGISFunctionality gfunc in gfc)
            {
                if (gfunc.Resource.Name == "graph")
                {
                    gMap = (MapResource)gfunc.Resource;
                    break;
                }
            }
            if (gMap == null)
            {
                return;
            }
            ElementGraphicsLayer glayer = null;
            foreach (DataTable dt in gMap.Graphics.Tables)
            {
                if (dt is ElementGraphicsLayer)
                {
                    glayer = dt as ElementGraphicsLayer;
                    break;
                }
            }
            if (glayer == null)
            {
                glayer = new ElementGraphicsLayer();
                gMap.Graphics.Tables.Add(glayer);
            }

            glayer.Clear();//清除数据
            glayer.Add(geoEle);

            //4.释放服务器对象
            pSc.ReleaseContext();

            if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
            {
                Map1.Refresh();
            }
            else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
            {
                Map1.RefreshResource(gMap.Name);
            }
            return;
        }
        /// <summary>
        /// Event handler for "Display Footprint" button click event
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>  
        private void displayFootprinttoolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                CswRecord record = (CswRecord)(resultsListBox.SelectedItem);
                drawfootprint(record, false, false);
                //add the graphics element to the map
                IMxDocument mxDoc;
                mxDoc = (IMxDocument)m_application.Document;

                IGraphicsContainer graphicsContainer;
                graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap;
                BoundingBox currentExtent = new BoundingBox();
                currentExtent.Maxx = mxDoc.ActiveView.Extent.XMax;
                currentExtent.Minx = mxDoc.ActiveView.Extent.XMin;
                currentExtent.Maxy = mxDoc.ActiveView.Extent.YMax;
                currentExtent.Miny = mxDoc.ActiveView.Extent.YMin;
                BoundingBox newExtent = updatedExtent(currentExtent, record.BoundingBox);

                IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.PutCoords(newExtent.Minx, newExtent.Maxy);

                IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass();
                point1.PutCoords(newExtent.Maxx, newExtent.Maxy);

                IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass();
                point2.PutCoords(newExtent.Maxx, newExtent.Miny);

                IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass();

                point3.PutCoords(newExtent.Minx, newExtent.Miny);

                IPointCollection pointCollection;
                pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass();

                object x = Type.Missing;
                object y = Type.Missing;
                pointCollection.AddPoint(point, ref x, ref y);
                pointCollection.AddPoint(point1, ref x, ref y);
                pointCollection.AddPoint(point2, ref x, ref y);
                pointCollection.AddPoint(point3, ref x, ref y);
                PolygonElementClass element = new PolygonElementClass();
                element.Geometry = (IGeometry)pointCollection;
                graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap;
                mxDoc.ActiveView.Extent = element.Geometry.Envelope;
                mxDoc.ActiveView.Refresh();
            }
            catch (Exception ex)
            {

                ShowErrorMessageBox(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #30
0
        public void OtherRule(string idname, string checkname, string IN_RuleType, string TABLENAME, string SUPTABLE, string inputtext, IHookHelper m_hookHelper)
        {
            CommonClass common = new CommonClass();

            IFeatureClass     IN_FeatureClass     = common.GetLayerByName(TABLENAME).FeatureClass;
            IGeoDataset       pGeoDataset         = IN_FeatureClass as IGeoDataset;
            ISpatialReference spatialReference    = pGeoDataset.SpatialReference;
            IFeatureClass     IN_Sup_FeatureClass = null;

            if (SUPTABLE != null)
            {
                IN_Sup_FeatureClass = common.GetLayerByName(SUPTABLE).FeatureClass;
            }
            string ErrorFilePath = this.topoDir + "\\" + checkname + idname + ".shp";

            if (IN_RuleType == "面多部件检查")
            {
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    List <ErrorEntity> list   = new List <ErrorEntity>();
                    IFeatureCursor     cursor = IN_FeatureClass.Search(null, false);
                    int      tempCount        = 0;
                    IFeature pFeature         = cursor.NextFeature();
                    while (pFeature != null)
                    {
                        IGeometry            pGeo          = pFeature.ShapeCopy;
                        ITopologicalOperator pTopoOperator = pGeo as ITopologicalOperator;
                        int iCount = 0;
                        if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            iCount = (pGeo as IPolygon).ExteriorRingCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            iCount = ((pGeo as IPolyline) as IGeometryCollection).GeometryCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint)
                        {
                            iCount = ((pGeo as IMultipoint) as IPointCollection).PointCount;
                        }
                        if (iCount > 1)
                        {
                            tempCount++;
                            common.GenerateSHPFile(pFeature.ShapeCopy, ErrorFilePath);
                        }
                        pFeature = cursor.NextFeature();
                    }
                    //new ErrorTable().AddErr(list, ErrType.MultiPart, idname);
                    if (!DicTopoError.ContainsKey(idname))
                    {
                        DicTopoError.Add(idname, tempCount);
                    }
                    else
                    {
                        DicTopoError[idname] = tempCount;
                    }

                    Marshal.ReleaseComObject(cursor);

                    if (tempCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
            }
            else if (IN_RuleType == "面自相交检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPoint, checkname + idname);
                    IFeatureLayer pLayer = new FeatureLayer();
                    pLayer.FeatureClass = IN_FeatureClass;
                    TopoClassChecker topo = new TopoClassChecker();

                    IFeatureCursor cursor;
                    IQueryFilter   filter = new QueryFilterClass();
                    filter.SubFields = pLayer.FeatureClass.OIDFieldName + "," + pLayer.FeatureClass.ShapeFieldName;
                    cursor           = pLayer.FeatureClass.Search(filter, true);
                    IFeature feature = null;
                    object   missing = Type.Missing;
                    while ((feature = cursor.NextFeature()) != null)
                    {
                        IPoint              tempPoint = null;
                        StringBuilder       builder   = new StringBuilder();
                        IGeometryCollection shape     = feature.Shape as IGeometryCollection;
                        for (int i = 0; i < shape.GeometryCount; i++)
                        {
                            esriNonSimpleReasonEnum enum2;
                            IPointCollection        newPoints = shape.get_Geometry(i) as IPointCollection;
                            IRing ring = newPoints as IRing;
                            int   num2 = 0;
                            if (ring.IsClosed)
                            {
                                num2 = 1;
                            }
                            PolylineClass o = new PolylineClass();
                            o.AddPointCollection(newPoints);
                            o.SpatialReference = spatialReference;

                            ITopologicalOperator3 @operator = o;
                            @operator.IsKnownSimple_2 = false;
                            if ([email protected]_IsSimpleEx(out enum2) && (enum2 == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections))
                            {
                                List <string> list2 = new List <string>();
                                List <string> list3 = new List <string>();
                                for (int j = num2; j < newPoints.PointCount; j++)
                                {
                                    IPoint point = newPoints.get_Point(j);
                                    tempPoint = point;
                                    string item = point.X.ToString() + "," + point.Y.ToString();
                                    if (list2.Contains(item))
                                    {
                                        if (!list3.Contains(item))
                                        {
                                            builder.Append(";");
                                            builder.Append(item);
                                            list3.Add(item);
                                        }
                                    }
                                    else
                                    {
                                        list2.Add(item);
                                    }
                                }
                            }
                            Marshal.ReleaseComObject(o);
                            o = null;
                        }
                        if (builder.Length > 0)
                        {
                            errorCount++;

                            string[] strArray = builder.ToString().Substring(1).Split(new char[] { ';' });
                            ESRI.ArcGIS.Geometry.IPointCollection pPointCollection1 = new ESRI.ArcGIS.Geometry.MultipointClass();
                            foreach (string str in strArray)
                            {
                                if (!string.IsNullOrEmpty(str))
                                {
                                    string[] strArray2 = str.Split(new char[] { ',' });
                                    double   pX        = double.Parse(strArray2[0]);
                                    double   pY        = double.Parse(strArray2[1]);
                                    ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                                    point.X = pX;
                                    point.Y = pY;
                                    common.GenerateSHPFile(point, ErrorFilePath);
                                }
                            }
                        }
                    }
                    Marshal.ReleaseComObject(cursor);
                    if (errorCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "缝隙检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    this.m_hookHelper = m_hookHelper;
                    IFeatureClass pFClass = IN_FeatureClass;
                    //获取空间参考
                    IGeometry   geometryBag = new GeometryBagClass();
                    IGeoDataset geoDataset  = pFClass as IGeoDataset;
                    geometryBag.SpatialReference = geoDataset.SpatialReference;

                    ////属性过滤
                    IFeatureCursor featureCursor = pFClass.Search(null, false);

                    // 遍历游标
                    IFeature            currentFeature     = featureCursor.NextFeature();
                    IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
                    object missing = Type.Missing;
                    while (currentFeature != null)
                    {
                        geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                        currentFeature = featureCursor.NextFeature();
                    }

                    // 合并要素
                    ITopologicalOperator unionedPolygon = null;
                    unionedPolygon = new Polygon() as ITopologicalOperator;
                    unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);

                    Marshal.ReleaseComObject(featureCursor);
                    IPolygon4           pMergerPolygon     = unionedPolygon as IPolygon4;
                    IGeometryBag        pOutGeometryBag    = pMergerPolygon.ExteriorRingBag; //获取外部环
                    IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection;

                    for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++)   //对外部环遍历
                    {
                        IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环
                        //【此处可以对外部环进行操作】
                        IPointCollection pOutRingCollection = pOutRing as IPointCollection;
                        for (int j = 0; j < pOutRingCollection.PointCount; j++)
                        {
                            IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点
                        }

                        IGeometryBag        pInteriotGeometryBag        = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环
                        IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection;

                        for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++)
                        {
                            ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection;

                            IPolygon           PPolygon  = new PolygonClass();
                            ISegmentCollection newSegCol = PPolygon as ISegmentCollection;
                            newSegCol.AddSegmentCollection(SegCol);
                            //pInteriorGeometry即为多边形的内部环
                            IGeometry inRing = PPolygon as IGeometry;
                            inRing.SpatialReference = geometryBag.SpatialReference;
                            IArea  area    = inRing as IArea;
                            Double getarea = System.Math.Abs(Convert.ToDouble(area.Area));
                            if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext))
                            {
                                Boolean        flag   = true;
                                ISpatialFilter filter = new SpatialFilterClass();
                                filter.Geometry   = inRing;
                                filter.SubFields  = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName;
                                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                IFeatureCursor o       = pFClass.Search(filter, true);
                                IFeature       feature = o.NextFeature();
                                while (feature != null && flag)
                                {
                                    IPolygon4           pPolygon           = feature.Shape as IPolygon4;
                                    IGeometryBag        iOutGeometryBag    = pPolygon.ExteriorRingBag; //获取外部环
                                    IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection;

                                    for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++)  //对外部环遍历
                                    {
                                        IGeometry           outGeo     = iOutGmtyCollection.get_Geometry(m);
                                        IGeometryCollection polyGonGeo = new PolygonClass();
                                        polyGonGeo.AddGeometry(outGeo);
                                        IPolygon iPolygon = polyGonGeo as IPolygon;
                                        iPolygon.SimplifyPreserveFromTo();
                                        IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2;
                                        if (!pRelationalOperator2.Contains(inRing))
                                        {
                                            errorCount++;
                                            common.GenerateSHPFile(inRing, ErrorFilePath);
                                            flag = false;
                                        }
                                    }
                                    feature = o.NextFeature();
                                }
                                Marshal.ReleaseComObject(o);
                            }
                        }
                        if (errorCount == 0)
                        {
                            string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                            IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                            IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                            IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                            if (System.IO.File.Exists(ErrorFilePath))
                            {
                                IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                                if (pFCChecker != null)
                                {
                                    IDataset pds = pFCChecker as IDataset;
                                    pds.Delete();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "面重叠检查")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = common.GetPathByName(TABLENAME);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                    Console.WriteLine(ex.Message);
                }

                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }

                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            else if (IN_RuleType == "面重叠检查(与其他图层)")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = @common.GetPathByName(TABLENAME) + ";" + @common.GetPathByName(SUPTABLE);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            Marshal.ReleaseComObject(IN_FeatureClass);
            if (SUPTABLE != null)
            {
                Marshal.ReleaseComObject(IN_Sup_FeatureClass);
            }
        }
        /// <summary>
        /// Event handler for "Show All Footprint" button click event
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void showAllFootprint_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                IMxDocument mxDoc;
                mxDoc = (IMxDocument)m_application.Document;

                IGraphicsContainer graphicsContainer;
                graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap;
                BoundingBox currentExtent = new BoundingBox();
                currentExtent.Maxx = mxDoc.ActiveView.Extent.XMax;
                currentExtent.Minx = mxDoc.ActiveView.Extent.XMin;
                currentExtent.Maxy = mxDoc.ActiveView.Extent.YMax;
                currentExtent.Miny = mxDoc.ActiveView.Extent.YMin;
                BoundingBox newExtent = currentExtent;
                if (showAll)
                {
                    showAll = false;
                    System.Windows.Forms.ToolTip toolTipForshowAll = new System.Windows.Forms.ToolTip();
                    toolTipForshowAll.SetToolTip(showAllFootprintToolStripButton, StringResources.hideAllFootprintTooltip);
                    //showAllFootprintToolStripButton = StringResources.hideAllFootprintTooltip;
                    showAllFootprintToolStripButton.Image = StringResources.hideAll;
                    foreach (Object obj in resultsListBox.Items)
                    {
                        currentExtent = newExtent;
                        CswRecord record = (CswRecord)obj;
                        if (record.BoundingBox.Maxx != NONEXSISTANTNUMBER)
                        {
                            drawfootprint(record, true, false);
                            newExtent = updatedExtent(currentExtent, record.BoundingBox);
                        }
                    }
                    IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                    point.PutCoords(newExtent.Minx, newExtent.Maxy);

                    IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass();
                    point1.PutCoords(newExtent.Maxx, newExtent.Maxy);

                    IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass();
                    point2.PutCoords(newExtent.Maxx, newExtent.Miny);

                    IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass();
                    point3.PutCoords(newExtent.Minx, newExtent.Miny);

                    IPointCollection pointCollection;
                    pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass();

                    object x = Type.Missing;
                    object y = Type.Missing;

                    pointCollection.AddPoint(point, ref x, ref y);
                    pointCollection.AddPoint(point1, ref x, ref y);
                    pointCollection.AddPoint(point2, ref x, ref y);
                    pointCollection.AddPoint(point3, ref x, ref y);

                    PolygonElementClass element = new PolygonElementClass();
                    element.Geometry = (IGeometry)pointCollection;

                    graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap;
                    mxDoc.ActiveView.Extent = element.Geometry.Envelope;
                    mxDoc.ActiveView.Refresh();
                }
                else
                {
                    showAll = true;
                    System.Windows.Forms.ToolTip toolTipForshowAll = new System.Windows.Forms.ToolTip();
                    toolTipForshowAll.SetToolTip(showAllFootprintToolStripButton, StringResources.showAllFootPrintToolTip);
                    showAllFootprintToolStripButton.Image = StringResources.showAll;
                    deleteelements();

                }
                mxDoc.ActiveView.Refresh();
            }
            catch (Exception ex)
            {

                ShowErrorMessageBox(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        private static void DrawMapUnits(IEnvelope Envelope, bool showText, double ColumnX)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double Text2BoxY = 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double BoxX      = 0.4; //Width
            double BoxY      = 0.3; //Height

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();

            BlackInsides.Blue  = 0;
            BlackInsides.Red   = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();

            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument        Doc = ArcMap.Document;
            IPageLayout        pageLayout = Doc.ActiveView as IPageLayout;
            IGraphicsContainer GraphicsContainer = pageLayout as IGraphicsContainer;
            double             Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double                      IndentTerm   = 0;
            IPoint                      Point        = null;
            double                      StringLength = 0;
            string                      LegendText   = "";
            string                      ItemName     = "";
            string                      ItemDesc     = "";
            IElement                    Ele          = null;
            IEnvelope                   TempEnv      = null;
            IRgbColor                   BoxColr      = null;
            ISimpleFillSymbol           FillSym      = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement           FillEle      = null;
            IEnvelope                   FillEnv      = new EnvelopeClass();
            WKSEnvelope                 Patch        = new WKSEnvelope();
            IGeometry                   Geo          = null;
            string                      LabelText    = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint   = new ESRI.ArcGIS.Geometry.PointClass();

            // Get the transparency of the MapUnitPolys Layer
            double transparency = 100;
            try
            {
                IFeatureLayer polyLayer    = commonFunctions.FindFeatureLayer(ArcMap.Editor.EditWorkspace, "MapUnitPolys");
                ILayerEffects layerEffects = polyLayer as ILayerEffects;
                transparency = layerEffects.Transparency;
            }
            catch { }

            #endregion

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            // Loop through legend records
            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
            {
                // Grab the DMU entry itself
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));


                // Find out how far to indent the legend item
                // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                // Get the coordinates of the text for the legend entry - upper left corner
                // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                Point = new PointClass();
                double xAdditions = 0;
                if (isHeading)
                {
                    // Xcoord plus (indentation), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1);
                }
                else
                {
                    //Xcoord plus (indentation) + (Box width and margin), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                }
                Point.PutCoords(Xcoord + xAdditions, Ycoord);

                // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                StringLength = 72 * (Envelope.Width - xAdditions);

                // Fix a couple of special characters in the legend string.
                // Then amalgamate item name and description
                ItemName = FixLegendTextCharacters(aDescription.Name);
                if (!isHeading)
                {
                    LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                }
                else
                {
                    LegendText = ItemName;
                }



                // Format the legend text if it is not a heading. If it is, we're fine.
                if (!isHeading)
                {
                    LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                }

                // Boldify the ItemName
                LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                // If the StratCorDiagram is being drawn
                if (showText == false)
                {
                    LegendText   = ".";     // placeholder
                    StringLength = 1;
                }

                // See if this legend item should be placed on a new column
                Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;

                TempEnv = new EnvelopeClass();
                Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                // If the height of the formatted text is larger than the box + space specified
                if (TempEnv.Height > BoxY + Text2BoxY)
                {
                    // If the text will spill out below the envelope drawn by the user
                    if (Ycoord - TempEnv.Height < Envelope.YMin)
                    {
                        // Move to a new column - the last number is a fudge factor, looks like it is in inches
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }
                else     // The height of the formatted text is not larger than the box + space defined
                {
                    // If the box itself will spill out below the envelope drawn by the user
                    if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                    {
                        // Move to a new column
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }

                // Only write the legend text if the legend is being drawn (not the StratCorDiagram)
                if (showText == true)
                {
                    GraphicsContainer.AddElement(Ele, 0);
                }

                if (!isHeading)
                {
                    FillEnv = new EnvelopeClass();

                    Patch.XMin = Point.X - BoxX - Text2BoxX;
                    Patch.YMax = Point.Y;
                    Patch.XMax = Point.X - Text2BoxX;
                    Patch.YMin = Point.Y - BoxY;
                    FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                    Geo = FillEnv as IGeometry;

                    // Get the color of the box
                    BoxColr = new RgbColorClass();
                    if (aDescription.AreaFillRGB == null)
                    {
                        BoxColr.Red   = 255;
                        BoxColr.Green = 0;
                        BoxColr.Blue  = 0;
                    }
                    else
                    {
                        BoxColr.Red   = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                        BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                        BoxColr.Blue  = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                    }

                    // Set the transparency for the legend color boxes
                    BoxColr.Red   = (int)((255 - BoxColr.Red) * transparency / 100 + BoxColr.Red);
                    BoxColr.Green = (int)((255 - BoxColr.Green) * transparency / 100 + BoxColr.Green);
                    BoxColr.Blue  = (int)((255 - BoxColr.Blue) * transparency / 100 + BoxColr.Blue);

                    // Draw the fill
                    FillSym         = new SimpleFillSymbolClass();
                    FillSym.Color   = BoxColr;
                    FillSym.Style   = esriSimpleFillStyle.esriSFSSolid;
                    FillSym.Outline = BlackOutsides;

                    FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                    // Label the box
                    LabelText = aDescription.Label;

                    // Subscripting!!

                    for (int i = 0; i < LabelText.Length; i++)
                    {
                        string thisBit = LabelText.Substring(i, 1);
                        int    num;
                        if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                        {
                            LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                            i         = i + 5;
                        }
                    }
                    LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                    LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                    // Center the label
                    LabelPoint   = new PointClass();
                    LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                    LabelPoint.Y = Point.Y - BoxY / 2;

                    //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                    Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                    // Add the box and label
                    IGroupElement3 group = new GroupElementClass();
                    group.AddElement(FillEle as IElement);
                    group.AddElement(Ele);
                    GraphicsContainer.AddElement(group as IElement, 0);
                }

                // Do a partial refresh
                //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                // Setup the Y coordinates for the next entry
                // if the height of this item's text is bigger than the minimum distance between text and box
                if (TempEnv.Height > Text2BoxY)
                {
                    // Subtract the box height and the text height to get the new ycoord
                    Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                }
                else
                {
                    if (isHeading)
                    {
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        Ycoord = Ycoord - (BoxY + Text2BoxY);
                    }
                }
            }

            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }
Example #33
0
        /// <summary>
        /// 获取点击地图上的点
        /// </summary>
        /// <param name="Button"></param>
        /// <param name="Shift"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();;
                ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph;
                object      pOwner;
                object      pObject;
                object      before   = Type.Missing;
                object      after    = Type.Missing;
                object      StepSize = Type.Missing;
                IDisplay3D  pDisplay;
                pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pMapPoint, out pOwner, out pObject); //获取鼠标点击的位置并转化为地理坐标
                if (pMapPoint == null)
                {
                    return;
                }
                pMapPoint.Z = pMapPoint.Z / m_sceneHookHelper.Scene.ExaggerationFactor;
                pMapPoint.Z = m_psurface.GetElevation(pMapPoint);
                pMapPoint.SpatialReference = pSceneGraph.Scene.SpatialReference;
                pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D;
                pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置
                IGeometry pGeom = null;
                Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                //根据绘制对象类型的不同定义不同的类型
                switch (m_DrawType.ToString())
                {
                case "esriGeometryPoint":
                    m_Geometry = pMapPoint;
                    break;

                case "esriGeometryLine":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolylineClass();
                        pGeom        = new PolylineClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolygonClass();
                        pGeom        = new PolygonClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;
                }

                //BeginDrawed(true);

                IGroupElement pGroup = null;
                if (m_pPointColl.PointCount == 1)
                {
                    //当为一个点时绘制点
                    Cls3DMarkDraw.AddSimpleGraphic(pMapPoint, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                }
                else if (m_DrawType.ToString() == "esriGeometryLine")
                {
                    pGeom = m_pPointColl as IGeometry;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                    m_pPointColl = pGeom as IPointCollection;
                }
                else
                {
                    ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator;
                    pGeom = pTopo.Boundary;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                }

                m_sceneHookHelper.SceneGraph.RefreshViewers();
            }
            catch
            {
                return;
            }
        }
Example #34
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();;
                object before   = Type.Missing;
                object after    = Type.Missing;
                object StepSize = Type.Missing;
                m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference;
                pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                if (pMapPoint == null)
                {
                    return;
                }
                pMapPoint.Project(m_psurface.Domain.SpatialReference);
                pMapPoint.Z = m_psurface.GetElevation(pMapPoint);

                //pMapPoint.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                //pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D;
                //pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置

                IGeometry pGeom = null;
                ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                //根据绘制对象类型的不同定义不同的类型
                switch (m_DrawType.ToString())
                {
                case "esriGeometryPoint":
                    m_Geometry = pMapPoint;
                    break;

                case "esriGeometryLine":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolylineClass();
                        pGeom        = new PolylineClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolygonClass();
                        pGeom        = new PolygonClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;
                }

                //BeginDrawed(true);

                IGroupElement pGroup = null;
                if (m_pPointColl.PointCount == 1)
                {
                    //当为一个点时绘制点
                    ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                }
                else if (m_DrawType.ToString() == "esriGeometryLine")
                {
                    pGeom = m_pPointColl as IGeometry;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                    m_pPointColl = pGeom as IPointCollection;
                }
                else
                {
                    ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator;
                    pGeom = pTopo.Boundary;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                }

                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
            catch
            {
                return;
            }
        }
        protected override void OnClick()
        {
            try
            {
                ConfigUtil.type = "water";
                List <ESRI.ArcGIS.Geometry.IPoint> Flags;
                List <ESRI.ArcGIS.Geometry.IPoint> Barriers;
                IWorkspace pWS;
                IFields    pFields;
                IPoint     pNPt;
                Globals.getFlagsBarriers(ArcMap.Application, out Flags, out Barriers);
                // Open the Workspace
                if ((pWS = Globals.GetInMemoryWorkspaceFromTOC(ArcMap.Document.FocusMap)) == null)
                {
                    pWS = Globals.CreateInMemoryWorkspace();
                }
                pFields = Globals.createFeatureClassFields(ArcMap.Document.FocusMap.SpatialReference, esriGeometryType.esriGeometryPoint, null, null);

                IFeatureClass pFlagsFC    = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportFlagsName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction);
                IFeatureClass pBarriersFC = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportBarriersName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction);


                IFeatureCursor pntInsertCurs = pFlagsFC.Insert(true);
                IFeatureBuffer pFBuf;
                IFeature       pFeat;

                foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Flags) // Loop through List with foreach
                {
                    pFBuf  = pFlagsFC.CreateFeatureBuffer();
                    pFeat  = (IFeature)pFBuf;
                    pNPt   = new ESRI.ArcGIS.Geometry.PointClass();
                    pNPt.X = pnt.X;
                    pNPt.Y = pnt.Y;

                    pFeat.Shape = pNPt;

                    pntInsertCurs.InsertFeature(pFBuf);
                }
                pntInsertCurs = pBarriersFC.Insert(true);
                foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Barriers) // Loop through List with foreach
                {
                    pFBuf  = pBarriersFC.CreateFeatureBuffer();
                    pFeat  = (IFeature)pFBuf;
                    pNPt   = new ESRI.ArcGIS.Geometry.PointClass();
                    pNPt.X = pnt.X;
                    pNPt.Y = pnt.Y;

                    pFeat.Shape = pNPt;
                    pntInsertCurs.InsertFeature(pFBuf);
                }



                IFeatureLayer pFlagsLayer = new FeatureLayerClass();
                pFlagsLayer.FeatureClass = pFlagsFC;
                pFlagsLayer.Name         = A4LGSharedFunctions.Localizer.GetString("ExportFlagsName");


                IFeatureLayer pBarriersLayer = new FeatureLayerClass();
                pBarriersLayer.FeatureClass = pBarriersFC;
                pBarriersLayer.Name         = A4LGSharedFunctions.Localizer.GetString("ExportBarriersName");


                ArcMap.Document.FocusMap.AddLayer(pFlagsLayer);
                ArcMap.Document.FocusMap.AddLayer(pBarriersLayer);
                ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            { }
        }
Example #36
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdRasterRegister.OnClick implementation
            IMapControl3 pMapCtrl = null;

            if (m_hookHelper.Hook is IToolbarControl)
            {
                if (((IToolbarControl)m_hookHelper.Hook).Buddy is IMapControl3)
                {
                    pMapCtrl = (IMapControl3)((IToolbarControl)m_hookHelper.Hook).Buddy;
                }
            }
            //In case the container is MapControl
            else if (m_hookHelper.Hook is IMapControl3)
            {
                pMapCtrl = (IMapControl3)m_hookHelper.Hook;
            }
            else
            {
                return;
            }

            System.GC.Collect();
            FrmSiftMatching frmSiftMatching = new FrmSiftMatching(pMapCtrl, pRasterLayer);

            if (frmSiftMatching.ShowDialog() == DialogResult.OK)
            {
                ClsSiftMatching pSiftMatching = new ClsSiftMatching();
                double[]        dbMatchPts;
                int             nCount = 0;
                if (pSiftMatching.siftMatching(frmSiftMatching.m_pSiftMatchPara, out dbMatchPts, out nCount))
                {
                    IRaster2     pLeftRaster    = frmSiftMatching.m_pRasterLeft;
                    IRasterProps pLeftProps     = pLeftRaster as IRasterProps;
                    IPoint       pLeftLowerLeft = pLeftProps.Extent.LowerLeft;

                    IRaster2     pRightRaster    = frmSiftMatching.m_pRasterRight;
                    IRasterProps pRightProps     = pRightRaster as IRasterProps;
                    IPoint       pRightLowerLeft = pRightProps.Extent.LowerLeft;

                    //SIFT匹配出来的都是影像坐标,应该先转换成MAPCTRL单位为准
                    for (int i = 0; i < nCount; i++)
                    {
                        int x = (int)dbMatchPts[4 * i];
                        int y = (int)(dbMatchPts[4 * i + 1]);
                        //y = (int)(-1*dbMatchPts[4 * i + 1]);
                        pLeftRaster.PixelToMap(x, y, out dbMatchPts[4 * i], out dbMatchPts[4 * i + 1]);

                        x = (int)dbMatchPts[4 * i + 2];
                        y = (int)(dbMatchPts[4 * i + 3]);
                        //y = (int)(-1*dbMatchPts[4 * i + 3]);
                        pRightRaster.PixelToMap(x, y, out dbMatchPts[4 * i + 2], out dbMatchPts[4 * i + 3]);

                        #region 废弃代码
                        //int x = (int)dbMatchPts[4 * i];
                        //int y = (int)(dbMatchPts[4 * i + 1]);
                        //dbMatchPts[4 * i] = x * pLeftProps.MeanCellSize().X + pLeftLowerLeft.X;
                        //dbMatchPts[4 * i + 1] = y * pLeftProps.MeanCellSize().Y + pLeftLowerLeft.Y;

                        //x = (int)dbMatchPts[4 * i + 2];
                        //y = (int)(dbMatchPts[4 * i + 3]);
                        //dbMatchPts[4 * i + 2] = x * pRightProps.MeanCellSize().X + pRightLowerLeft.X;
                        //dbMatchPts[4 * i + 3] = y * pRightProps.MeanCellSize().Y + pRightLowerLeft.Y;
                        //IPoint ptFrom = pMapCtrl.ToMapPoint(Convert.ToInt32(dbMatchPts[4 * i + 0]), Convert.ToInt32(dbMatchPts[4 * i + 1]));
                        //IPoint ptTo = pMapCtrl.ToMapPoint(Convert.ToInt32(dbMatchPts[4 * i + 2]), Convert.ToInt32(dbMatchPts[4 * i + 3]));

                        //dbMatchPts[4 * i + 0] = ptFrom.X;
                        //dbMatchPts[4 * i + 1] = ptFrom.Y;
                        //dbMatchPts[4 * i + 2] = ptTo.X;
                        //dbMatchPts[4 * i + 3] = ptTo.Y;
                        #endregion
                    }
                    pSiftMatching.outputMatchPointsToFile("d:\\b.txt", dbMatchPts, nCount);

                    //添加到控制点中
                    m_FrmLink.DelAllPoints();
                    for (int i = 0; i < nCount; i++)
                    {
                        IPoint ptOrg = new ESRI.ArcGIS.Geometry.PointClass();
                        ptOrg.PutCoords(dbMatchPts[4 * i], dbMatchPts[4 * i + 1]);
                        m_FrmLink.OriginPoints.AddPoint(ptOrg);

                        IPoint ptTarget = new ESRI.ArcGIS.Geometry.PointClass();
                        ptTarget.PutCoords(dbMatchPts[4 * i + 2], dbMatchPts[4 * i + 3]);
                        m_FrmLink.TargetPoints.AddPoint(ptTarget);
                    }
                    m_FrmLink.RefreshControlAllPoints();
                    m_FrmLink.Show();
                    pMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    //MessageBox.Show("匹配成功!");
                }
                else
                {
                    MessageBox.Show("匹配失败!");
                }

                //把临时创建的文件删除
                try
                {
                    string szLeftFilename  = frmSiftMatching.m_pSiftMatchPara.szLeftFilename;
                    string szRightFilename = frmSiftMatching.m_pSiftMatchPara.szRightFilename;
                    if (System.IO.File.Exists(szLeftFilename))
                    {
                        System.IO.File.Delete(szLeftFilename);
                    }

                    if (System.IO.File.Exists(szRightFilename))
                    {
                        System.IO.File.Delete(szRightFilename);
                    }
                }
                catch (System.Exception ex)
                {
                    return;
                }
            }
        }