Пример #1
0
        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);
                }
            }
        }
Пример #2
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();
        }
        /// <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;
            }
        }
        /// <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();
            }
        }
        /// <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;
            }
        }
Пример #6
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);
 }
Пример #7
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);
        }
Пример #8
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;
                }
            }
        }