예제 #1
0
파일: FarmInfo.cs 프로젝트: lidan233/C---
        private void button7_Click(object sender, EventArgs e)
        {
            if (currentFeatureLayer == null)
            {
                MessageBox.Show("当前无加载地图!");
                return;
            }
            string       tbh         = dataGridView1.Rows[row].Cells[2].Value.ToString();//获取图斑号
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = "gid = '" + tbh + "'";
            IFeatureCursor featurecursor;

            featurecursor = currentFeatureLayer.FeatureClass.Search(queryFilter, false);
            IFeature feature = featurecursor.NextFeature();

            //定义新的IEnvelope接口对象获取该要素的空间范围
            if (feature == null)
            {
                MessageBox.Show("无法定位,没有此图斑!");
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope outEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            //通过IGeometry接口的QueryEnvelope方法获取要素的空间范围
            feature.Shape.QueryEnvelope(outEnvelope);
            //将主窗体地图的当前可视范围定义为要素的空间范围,并刷新地图
            IActiveView activeView = currentMap as IActiveView;

            activeView.Extent = outEnvelope;
            activeView.Refresh();
        }
        ///<summary>Add a North Arrow to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///
        ///<remarks></remarks>
        public void AddNorthArrow(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(1, 24, 5, 24); //  Specify the location and size of the north arrow

            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.MarkerNorthArrow";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;                    // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView        activeView        = pageLayout as ESRI.ArcGIS.Carto.IActiveView;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = frameElement as ESRI.ArcGIS.Carto.IMapFrame;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement           element           = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement;                        // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            ESRI.ArcGIS.Carto.IMarkerNorthArrow        markerNorthArrow      = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow;         // Dynamic Cast
            ESRI.ArcGIS.Display.IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
            ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
            characterMarkerSymbol.CharacterIndex = 200;                                                                                    // change the symbol for the North Arrow
            markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
        }
예제 #3
0
        public static Dictionary <int, KeyValuePair <string, IEnumInvalidObject> > TransferMapDataWithinExtents(IMap map, IFeatureWorkspace outputWorkspace, IFeatureDatasetName outputFeatureDatasetName, ESRI.ArcGIS.ADF.Web.Geometry.Envelope downloadDataExtent, ISpatialReference outputSpatialReference)
        {
            Dictionary <int, KeyValuePair <string, IEnumInvalidObject> > invalidObjects = new Dictionary <int, KeyValuePair <string, IEnumInvalidObject> >();
            IWorkspaceName outWorkspaceName = GeodatabaseUtil.GetWorkspaceName((IWorkspace)outputWorkspace);

            List <IFeatureLayer> featureLayers = GetFeatureLayers(map);

            int counter = 0;

            foreach (IFeatureLayer featureLayer in featureLayers)
            {
                IFeatureClass     inFeatureClass     = featureLayer.FeatureClass;
                IDataset          dataset            = (IDataset)inFeatureClass;
                IFeatureWorkspace inFeatureWorkspace = (IFeatureWorkspace)dataset.Workspace;

                IEnvelope env = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                env.XMin = downloadDataExtent.XMin;
                env.YMin = downloadDataExtent.YMin;
                env.XMax = downloadDataExtent.XMax;
                env.YMax = downloadDataExtent.YMax;

                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry      = env;
                spatialFilter.GeometryField = inFeatureClass.ShapeFieldName;
                spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureClassName outputFeatureClassName = GeodatabaseUtil.GetFeatureClassName(outWorkspaceName, dataset.Name);

                IEnumInvalidObject eInvalidObject = TransferData(inFeatureWorkspace, inFeatureClass, outputWorkspace, outputFeatureClassName, outputFeatureDatasetName, spatialFilter, outputSpatialReference);
                invalidObjects.Add(counter, new KeyValuePair <string, IEnumInvalidObject>(dataset.Name, eInvalidObject));
                counter++;
            }

            return(invalidObjects);
        }
예제 #4
0
        // ArcGIS Snippet Title:
        // Create JPEG from ActiveView
        //
        // Long Description:
        // Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.Output
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.</summary>
        ///
        ///<param name="activeView">An IActiveView interface</param>
        ///<param name="pathFileName">A System.String that the path and filename of the JPEG you want to create. Example: "C:\temp\test.jpg"</param>
        ///
        ///<returns>A System.Boolean indicating the success</returns>
        ///
        ///<remarks></remarks>
        public System.Boolean CreateJPEGFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }
            IExport export = (IExport) new ExportJPEG();

            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution
            export.Resolution = 96;
            tagRECT exportRECT = activeView.ExportFrame;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();

            return(true);
        }
예제 #5
0
        // ArcGIS Snippet Title:
        // Add Legend
        //
        // Long Description:
        // Add a Legend to the Page Layout from the Map.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        ///
        ///<remarks></remarks>
        public void AddLegend(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;              // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IUID          uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
예제 #6
0
        private void _3DLink2D(double x, double y, double z)
        {
            if (b3To2 || b2To3)
            {
                b3To2 = false;
                b2To3 = false;
                return;
            }
            b3To2 = true;

            DF2DApplication app2D = DF2DApplication.Application;
            DF3DApplication app3D = DF3DApplication.Application;

            if (app2D == null || app3D == null || app2D.Current2DMapControl == null || app3D.Current3DMapControl == null)
            {
                return;
            }
            ICamera camera3D = app3D.Current3DMapControl.Camera;

            Gvitech.CityMaker.Math.IEulerAngle angle = new Gvitech.CityMaker.Math.EulerAngle();
            Gvitech.CityMaker.Math.IVector3    pos   = new Gvitech.CityMaker.Math.Vector3();
            camera3D.GetCamera(out pos, out angle);

            ESRI.ArcGIS.Geometry.IEnvelope env = app2D.Current2DMapControl.Extent;
            double width  = env.XMax - env.XMin;
            double height = env.YMax - env.YMin;
            double rate   = width / height;

            double xmin, ymin, xmax, ymax;

            Link2DAnd3D._3DLink2D(x, y, z, Math.Abs(angle.Tilt * Math.PI / 180), camera3D.VerticalFieldOfView * Math.PI / 180, rate, out xmin, out ymin, out xmax, out ymax);
            ESRI.ArcGIS.Geometry.IEnvelope env1 = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            env1.PutCoords(xmin, ymin, xmax, ymax);
            app2D.Current2DMapControl.Extent = env1;
        }
예제 #7
0
        private void PerformAttributeSelect()
        {
            try
            {
                IQueryFilter  pQueryFilter = new QueryFilterClass();
                IFeatureLayer pFeatureLayer;

                pQueryFilter.WhereClause = textBoxWhereClause.Text;
                pFeatureLayer            = GetLayerByName(comboBoxLayers.SelectedItem.ToString()) as IFeatureLayer;
                pFeatureSelection        = pFeatureLayer as IFeatureSelection;

                int iSelectedFeaturesCount = pFeatureSelection.SelectionSet.Count;
                pFeatureSelection.SelectFeatures(pQueryFilter, selectmethod, false);//执行查询

                //如果本次查询后,查询的结果数目没有改变,则认为本次查询没有产生新的结果
                if (pFeatureSelection.SelectionSet.Count == iSelectedFeaturesCount || pFeatureSelection.SelectionSet.Count == 0)
                {
                    MessageBox.Show("没有符合本次查询条件的结果!");
                    return;
                }

                //如果复选框被选中,则定位到选择结果
                if (checkBoxZoomtoSelected.Checked == true)
                {
                    IEnumFeature pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    IFeature     pFeature     = pEnumFeature.Next();
                    ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                    while (pFeature != null)
                    {
                        pEnvelope.Union(pFeature.Extent);
                        pFeature = pEnumFeature.Next();
                    }
                    MainAxMapControl.ActiveView.Extent = pEnvelope;
                    MainAxMapControl.ActiveView.Refresh(); //如果不这样刷新,只要查询前地图已经被放大所效果的话,定位后
                                                           //底图没有刷新,选择集倒是定位和刷新了
                }
                else
                {
                    MainAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                }

                //double i = MainAxMapControl.Map.SelectionCount;
                //i = Math.Round(i, 0);//小数点后指定为0位数字
                //pMainform = "当前共有" + i.ToString() + "个查询结果";
            }
            catch (Exception ex)
            {
                MessageBox.Show("您的查询语句可能有误,请检查 | " + ex.Message);
                return;
            }
        }
        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        ///
        ///<remarks></remarks>
        public void AddLegend(IPageLayout pageLayout, IMap map, Double posX, Double posY, Double legW)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;              // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast


            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            //
            ILegend pLegend = mapSurroundFrame.MapSurround as ILegend;

            pLegend.Title = "图例";
            pLegend.Format.TitlePosition = esriRectanglePosition.esriLeftSide | esriRectanglePosition.esriTopSide;
            pLegend.Format.TitleSymbol   = new TextSymbolClass()
            {
                Font = GetFontDisp(24)
            };
            pLegend.get_Item(0).ShowLayerName   = true;
            pLegend.get_Item(0).LayerNameSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(22)
            };
            pLegend.get_Item(0).LegendClassFormat.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast

            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
예제 #9
0
        private void PerformLocationQuery(ISpatialFilter pSpatialFilter)
        {
            try
            {
                frmPromptQuerying frmPrompt = new frmPromptQuerying(); //提示:空间查询中
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();           //'转让控制权,没有这一句的话提示窗口不能正常显示
                string            strLayerName;
                IFeatureLayer     pFeatureLayer;
                IFeatureSelection pFeatureSelection;                                      //用来记录查询的结果
                foreach (object itemChecked in checkedListBoxFeaturesLayer1.CheckedItems) //对于每一个选中的层都执行查询,结果合并
                {
                    strLayerName      = itemChecked.ToString();                           //这个才是待查询的layer
                    pFeatureLayer     = GetLayerbyName(strLayerName) as IFeatureLayer;
                    pFeatureSelection = pFeatureLayer as IFeatureSelection;
                    pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);//待选的层可能不止一个
                    //通过循环依次查询每个层,把结果add起来
                }
                //如果复选框被选中,则定位到选择结果
                if (checkBoxZoomtoSelected.Checked == true)
                {
                    IEnumFeature pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    IFeature     pFeature     = pEnumFeature.Next();
                    ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                    while (pFeature != null)
                    {
                        pEnvelope.Union(pFeature.Extent);
                        pFeature = pEnumFeature.Next();
                    }
                    MainAxMapControl.ActiveView.Extent = pEnvelope;
                    MainAxMapControl.ActiveView.Refresh();//如果不这样刷新,只要查询前地图已经被放大所效果的话,定位后
                    //底图没有刷新,选择集倒是定位和刷新了
                }
                frmPrompt.Dispose();
                //把结果显示出来
                MainAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                //double i = MainAxMapControl.Map.SelectionCount;
                //i = Math.Round(i, 0);//小数点后指定为0位数字
                //pMainform.toolStripStatusLabel1.Text = "当前共有" + i.ToString() + "个查询结果";
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成查询结果出错!请检查 | " + ex.Message);
                return;
            }
        }
예제 #10
0
        public static string CreateJPEGFromActiveView(IRaster pRaster,IEnvelope pEnv,string outurl, System.String pathFileName)
        {
            //创建rasterlayer
            IRasterLayer pRasterLayer = new RasterLayerClass();

            //获取mapServer中所有的图层
            IMap pMap = new MapClass();
            pRasterLayer.CreateFromRaster(pRaster);
            pMap.AddLayer(pRasterLayer as ILayer);

            IActiveView activeView = pMap as IActiveView;
            activeView.Extent = pEnv;
            //parameter check
            if (activeView == null)
            {
                return null;
            }
            string imageName = System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ".png";
            pathFileName = System.IO.Path.Combine(pathFileName, imageName);

            ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportPNGClass();
            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT = new ESRI.ArcGIS.esriSystem.tagRECT();
            exportRECT.top = 0;
            exportRECT.left = 0;
            exportRECT.right = 800;
            exportRECT.bottom = 600;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.top,exportRECT.left,exportRECT.right,exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();

            return outurl + "/" + imageName;
        }
예제 #11
0
        ///<summary>Add a Scale Bar to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///
        ///<remarks></remarks>
        public void AddScalebar(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(7, 1, 25, 1.5); // Specify the location and size of the scalebar
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.AlternatingScaleBar";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;                    // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView        activeView        = pageLayout as ESRI.ArcGIS.Carto.IActiveView;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = frameElement as ESRI.ArcGIS.Carto.IMapFrame;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement           element           = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement;                        // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;


            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));

            markerScaleBar.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };
            markerScaleBar.UnitLabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
        }
예제 #12
0
        public System.Boolean ExportMap(IActiveView activeView, String pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }
            ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportJPEGClass();
            export.ExportFileName = pathFileName;

            // Because we are exporting to a resolution that differs from screen
            // resolution, we should assign the two values to variables for use
            // in our sizing calculations
            System.Int32 screenResolution = 96;
            System.Int32 outputResolution = 300;

            export.Resolution = outputResolution;

            tagRECT exportRECT; // This is a structure

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = activeView.ExportFrame.right * (outputResolution / screenResolution);
            exportRECT.bottom = activeView.ExportFrame.bottom * (outputResolution / screenResolution);

            // Set up the PixelBounds envelope to match the exportRECT
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            System.Int32 hDC = export.StartExporting();

            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
            export.FinishExporting();
            export.Cleanup();

            return(true);
        }
예제 #13
0
        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        /// 
        ///<remarks></remarks>
        public static void Addlegend(AxPageLayoutControl axpageLayoutControl, ESRI.ArcGIS.Carto.IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            IPageLayout pageLayout;
            pageLayout = axpageLayoutControl.PageLayout;
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
예제 #14
0
        protected override void OnClick()
        {
            // Get the min/max zoom from user input
            int minzoom = 0;
            int maxzoom = 6;

            Ecotrust.Form1 form1 = new Ecotrust.Form1();
            if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                minzoom = (int)form1.numericUpDown1.Value;
                maxzoom = (int)form1.numericUpDown2.Value;
            }
            else
            {
                return; //TODO
            }

            // Use the FolderBrowserDialog Class to choose export folder
            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
            folderDialog.Description = "Select output folder for map tiles...";
            string exportDir = "";

            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp"
                exportDir = folderDialog.SelectedPath;
                if (exportDir == "")
                {
                    return;  // TODO raise error
                }
            }
            else
            {
                return; //TODO
            }

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView    activeView = mxDocument.ActiveView;
            ESRI.ArcGIS.Carto.IMap           map        = activeView.FocusMap;

            ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent;

            // Set up export object and tile pixel coordinates
            int tileSizeX = 256;
            int tileSizeY = 256;

            // set up exporter with transparent background
            ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass();
            ESRI.ArcGIS.Display.IColor    tcolor    = new ESRI.ArcGIS.Display.RgbColorClass();
            // Warning: 254,254,254 will be set to transparent; don't use in any of map styling
            ((IRgbColor)tcolor).Red   = 254;
            ((IRgbColor)tcolor).Green = 254;
            ((IRgbColor)tcolor).Blue  = 254;
            ((ExportPNG)pngexport).BackgroundColor = tcolor;
            pngexport.TransparentColor             = tcolor;
            ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport;

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT;
            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = tileSizeX;
            exportRECT.bottom = tileSizeY;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            map.DelayDrawing(true);

            // Turn off all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = false;
            }

            // Calculate total number of tiles needed
            GlobalMercator mercator = new GlobalMercator();

            GlobalMercator.Coords tempmins;
            GlobalMercator.Coords tempmaxs;
            Double numTiles = 0;

            for (int tz = minzoom; tz <= maxzoom; tz++)
            {
                tempmins  = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                tempmaxs  = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);
                numTiles += ((tempmaxs.y - tempmins.y) + 1) * ((tempmaxs.x - tempmins.x) + 1);
            }
            numTiles *= map.LayerCount;

            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
            statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles");

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

            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

            // Set the properties of the Step Progressor
            System.Int32 int32_hWnd = ArcMap.Application.hWnd;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
            stepProgressor.MinRange  = 0;
            stepProgressor.MaxRange  = (int)numTiles;
            stepProgressor.StepValue = 1;
            stepProgressor.Message   = "Calculating " + numTiles.ToString() + " tiles";

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

            // Set the properties of the ProgressDialog
            progressDialog2.CancelEnabled = true;
            progressDialog2.Description   = "Rendering " + numTiles.ToString() + " map tiles";
            progressDialog2.Title         = "Creating map tiles...";
            progressDialog2.Animation     = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
            System.Boolean boolean_Continue = true;

            int tileCount = 0;

            for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++)
            {
                // Turn on the layer of interest
                ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum);
                layer.Visible = true;

                // Set extents
                //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest;
                ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass();

                // Create layer directory if it doesn't exist
                DirectoryInfo dir = new DirectoryInfo(exportDir + "\\" + layer.Name);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                DateTime startTime = DateTime.Now;

                // Loop through zoom levels, rows, cols
                for (int tz = minzoom; tz <= maxzoom; tz++)
                {
                    GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                    GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);

                    // Create zoom directory if it doesn't exist
                    DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz);
                    if (!dir2.Exists)
                    {
                        dir2.Create();
                    }

                    for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++)
                    {
                        // Create X directory if it doesn't exist
                        DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx);
                        if (!dir3.Exists)
                        {
                            dir3.Create();
                        }

                        for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++)
                        {
                            // Flip y-axis for output tile name
                            int invertTy = (int)((Math.Pow(2, tz) - 1) - ty);

                            tileCount += 1;

                            // TODO Calculate time and set new message
                            // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1));
                            // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds;
                            //(" + ((int)timeRemaining).ToString() +" remaining)";

                            stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy +
                                                     ".png (" + tileCount + " of " + numTiles + ")";


                            export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png";

                            GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz);
                            aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy);
                            aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator?
                            // Use FullExtent instead of Extent to make the extent independent of the activeView ratio
                            activeView.FullExtent = aoi;

                            // Export
                            System.Int32 hDC = export.StartExporting();
                            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                            export.FinishExporting();
                            export.Cleanup();

                            stepProgressor.Position = tileCount;

                            //Check if the cancel button was pressed. If so, break out of row
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                            {
                                break;
                            }
                        }
                        //Check if the cancel button was pressed. If so, break out of col
                        boolean_Continue = trackCancel.Continue();
                        if (!boolean_Continue)
                        {
                            break;
                        }
                    }
                    //Check if the cancel button was pressed. If so, break out of layers
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        break;
                    }

                    // Write log
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(exportDir + "\\log.txt", true))
                    {
                        file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" +
                                       mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y);
                    }
                }
                // Turn it off
                layer.Visible = false;
            }

            map.DelayDrawing(false);

            // Turn ON all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = true;
            }

            // restore extent
            activeView.FullExtent = mapaoi;
            activeView.Refresh();

            // Done
            trackCancel    = null;
            stepProgressor = null;
            progressDialog2.HideDialog();
            progressDialog2 = null;
        }
예제 #15
0
        /// <summary>
        /// 将符号转化为图片
        /// </summary>
        /// <param name="pSymbol">符号</param>
        /// <param name="width">图片宽度</param>
        /// <param name="height">图片高度</param>
        /// <returns>图片</returns>
        public static Image Symbol2Picture(ISymbol pSymbol, int width, int height)
        {
            if (pSymbol == null || width < 1 || height < 1)
            {
                return(null);
            }

            //根据高宽创建图象
            Bitmap   bmp    = new Bitmap(width, height);
            Graphics gImage = Graphics.FromImage(bmp);

            gImage.Clear(Color.White);
            double dpi = gImage.DpiX;

            ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            pEnvelope.PutCoords(0, 0, (double)bmp.Width, (double)bmp.Height);

            tagRECT deviceRect;

            deviceRect.left   = 0;
            deviceRect.right  = bmp.Width;
            deviceRect.top    = 0;
            deviceRect.bottom = bmp.Height;

            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

            pDisplayTransformation.VisibleBounds = pEnvelope;
            pDisplayTransformation.Bounds        = pEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = dpi;

            System.IntPtr hdc = new IntPtr();
            hdc = gImage.GetHdc();

            ESRI.ArcGIS.Geometry.IGeometry pGeo = CreateSymShape(pSymbol, pEnvelope);

            //将符号的形状绘制到图象中
            pSymbol.SetupDC((int)hdc, pDisplayTransformation);
            pSymbol.Draw(pGeo);
            pSymbol.ResetDC();
            gImage.ReleaseHdc(hdc);
            gImage.Dispose();
            return(bmp);

            ////IStyleGalleryClass pStyleClass = null;
            ////if (pSymbol is IMarkerSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.MarkerSymbolStyleGalleryClassClass();
            ////else if (pSymbol is ILineSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.LineSymbolStyleGalleryClassClass();
            ////else if (pSymbol is IFillSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.FillSymbolStyleGalleryClassClass();
            ////else
            ////    return null;

            //IStyleGalleryItem pStyleItem = new ServerStyleGalleryItemClass();
            //pStyleItem.Name = "tempSymbol";
            //pStyleItem.Item = pSymbol;

            //Bitmap bitmap = new Bitmap(width, height);
            //System.Drawing.Graphics pGraphics = System.Drawing.Graphics.FromImage(bitmap);
            //tagRECT rect = new tagRECT();
            //rect.right = bitmap.Width;
            //rect.bottom = bitmap.Height;
            ////生成预览
            //IntPtr hdc = new IntPtr();
            //hdc = pGraphics.GetHdc();

            //pStyleClass.Preview(pStyleItem, hdc.ToInt32(), ref rect);

            //pGraphics.ReleaseHdc(hdc);
            //pGraphics.Dispose();

            //return bitmap;
        }
예제 #16
0
파일: Form3.cs 프로젝트: 16Lovia/GISDiary
        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 void ExportPNG(IActiveView activeView, string pathFileName,IColor bg,string depth)
        {
            IExport export = new ExportPNGClass();
            export.ExportFileName = pathFileName;
            IExportPNG png = export as IExportPNG;
            png.TransparentColor = bg;
            IExportImage img = export as IExportImage;
            if(depth=="8bit")
            { img.ImageType = esriExportImageType.esriExportImageTypeIndexed; }
            else if(depth=="32bit")
            { img.ImageType = esriExportImageType.esriExportImageTypeTrueColor; }

            // Microsoft Windows default DPI resolution
            export.Resolution = 96;
            tagRECT exportRECT = activeView.ExportFrame;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();
        }
예제 #18
0
        //输出当前地图至指定的文件
        public static void ExportActiveView(IActiveView pView, Size outRect, string outPath)
        {
            try
            {
                //参数检查
                if (pView == null)
                {
                    throw new Exception("输入参数错误,无法生成图片文件!");
                }

                //根据给定的文件扩展名,来决定生成不同类型的对象
                ESRI.ArcGIS.Output.IExport export = null;
                if (outPath.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportJPEGClass();
                }
                else if (outPath.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportTIFFClass();
                }
                else if (outPath.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportBMPClass();
                }
                else if (outPath.EndsWith(".emf", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportEMFClass();
                }
                else if (outPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportPNGClass();
                }
                else if (outPath.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
                {
                    export = new ESRI.ArcGIS.Output.ExportGIFClass();
                }

                SetOutputQuality(pView, 1);

                export.ExportFileName = outPath;
                IEnvelope pEnvelope = pView.Extent;
                //导出参数
                export.Resolution = 300;

                tagRECT exportRect = new tagRECT();
                exportRect.left = exportRect.top = 0;
                exportRect.right = outRect.Width;
                exportRect.bottom = (int)(exportRect.right * pEnvelope.Height / pEnvelope.Width);
                ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                //输出范围
                envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom);
                export.PixelBounds = envelope;
                //可用于取消操作
                ITrackCancel pCancel = new CancelTrackerClass();
                export.TrackCancel = pCancel;
                pCancel.Reset();
                //点击ESC键时,中止转出
                pCancel.CancelOnKeyPress = true;
                pCancel.CancelOnClick = false;
                pCancel.ProcessMessages = true;
                //获取handle
                System.Int32 hDC = export.StartExporting();
                //开始转出
                pView.Output(hDC, (System.Int32)export.Resolution, ref exportRect, pEnvelope, pCancel);
                bool bContinue = pCancel.Continue();
                //捕获是否继续
                if (bContinue)
                {
                    export.FinishExporting();
                    export.Cleanup();
                }
                else
                {
                    export.Cleanup();
                }

                bContinue = pCancel.Continue();
            }
            catch (Exception e)
            {
                //错误信息提示
            }
        }
예제 #19
0
        private void ExportPDF(IActiveView activeView, string pathFileName)
        {
            IExport export = new ExportPDFClass();
            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution
            export.Resolution = 96;
            tagRECT exportRECT = activeView.ExportFrame;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();
        }
예제 #20
0
        protected override void OnClick()
        {
            // Get the min/max zoom from user input
            int minzoom = 0;
            int maxzoom = 6;
            Ecotrust.Form1 form1 = new Ecotrust.Form1();
            if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                minzoom = (int)form1.numericUpDown1.Value;
                maxzoom = (int)form1.numericUpDown2.Value;
            }
            else
            {
                return; //TODO
            }

            // Use the FolderBrowserDialog Class to choose export folder
            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
            folderDialog.Description = "Select output folder for map tiles...";
            string exportDir = "";
            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp"
                exportDir = folderDialog.SelectedPath;
                if (exportDir == "")
                    return;  // TODO raise error
            }
            else
            {
                return; //TODO
            }

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView;
            ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;

            ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent;

            // Set up export object and tile pixel coordinates
            int tileSizeX = 256;
            int tileSizeY = 256;

            // set up exporter with transparent background
            ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass();
            ESRI.ArcGIS.Display.IColor tcolor = new ESRI.ArcGIS.Display.RgbColorClass();
            // Warning: 254,254,254 will be set to transparent; don't use in any of map styling
            ((IRgbColor)tcolor).Red = 254;
            ((IRgbColor)tcolor).Green = 254;
            ((IRgbColor)tcolor).Blue = 254;
            ((ExportPNG)pngexport).BackgroundColor = tcolor;
            pngexport.TransparentColor = tcolor;
            ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport;

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT;
            exportRECT.left = 0;
            exportRECT.top = 0;
            exportRECT.right = tileSizeX;
            exportRECT.bottom = tileSizeY;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            map.DelayDrawing(true);

            // Turn off all layers
            for (int i = 0; i < map.LayerCount; i++)
                map.get_Layer(i).Visible = false;

            // Calculate total number of tiles needed
            GlobalMercator mercator = new GlobalMercator();
            GlobalMercator.Coords tempmins;
            GlobalMercator.Coords tempmaxs;
            Double numTiles = 0;
            for (int tz = minzoom; tz <= maxzoom; tz++)
            {
                tempmins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                tempmaxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);
                numTiles += ((tempmaxs.y - tempmins.y)+1) * ((tempmaxs.x - tempmins.x)+1);
            }
            numTiles *= map.LayerCount;

            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
            statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles");

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

            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

            // Set the properties of the Step Progressor
            System.Int32 int32_hWnd = ArcMap.Application.hWnd;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
            stepProgressor.MinRange = 0;
            stepProgressor.MaxRange = (int)numTiles;
            stepProgressor.StepValue = 1;
            stepProgressor.Message = "Calculating " + numTiles.ToString() + " tiles";

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

            // Set the properties of the ProgressDialog
            progressDialog2.CancelEnabled = true;
            progressDialog2.Description = "Rendering " + numTiles.ToString() + " map tiles";
            progressDialog2.Title = "Creating map tiles...";
            progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
            System.Boolean boolean_Continue = true;

            int tileCount = 0;

            for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++)
            {
                // Turn on the layer of interest
                ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum);
                layer.Visible = true;

                // Set extents
                //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest;
                ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass();

                // Create layer directory if it doesn't exist
                DirectoryInfo dir = new DirectoryInfo(exportDir  + "\\" + layer.Name);
                if (!dir.Exists)
                    dir.Create();

                DateTime startTime = DateTime.Now;

                // Loop through zoom levels, rows, cols
                for (int tz = minzoom; tz <= maxzoom; tz++)
                {
                    GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                    GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);

                    // Create zoom directory if it doesn't exist
                    DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz);
                    if (!dir2.Exists)
                        dir2.Create();

                    for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++)
                    {
                        // Create X directory if it doesn't exist
                        DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx);
                        if (!dir3.Exists)
                            dir3.Create();

                        for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++)
                        {

                            // Flip y-axis for output tile name
                            int invertTy = (int) ((Math.Pow(2, tz) - 1) - ty);

                            tileCount += 1;

                            // TODO Calculate time and set new message
                            // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1));
                            // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds;
                            //(" + ((int)timeRemaining).ToString() +" remaining)";

                            stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy +
                                ".png (" + tileCount + " of " + numTiles + ")";

                            export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png";

                            GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz);
                            aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy);
                            aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator?
                            // Use FullExtent instead of Extent to make the extent independent of the activeView ratio
                            activeView.FullExtent = aoi;

                            // Export
                            System.Int32 hDC = export.StartExporting();
                            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                            export.FinishExporting();
                            export.Cleanup();

                            stepProgressor.Position = tileCount;

                            //Check if the cancel button was pressed. If so, break out of row
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                                break;
                        }
                        //Check if the cancel button was pressed. If so, break out of col
                        boolean_Continue = trackCancel.Continue();
                        if (!boolean_Continue)
                            break;
                    }
                    //Check if the cancel button was pressed. If so, break out of layers
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                        break;

                    // Write log
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter( exportDir + "\\log.txt", true))
                    {
                        file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" +
                          mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y);
                    }

                }
                // Turn it off
                layer.Visible = false;
            }

            map.DelayDrawing(false);

            // Turn ON all layers
            for (int i = 0; i < map.LayerCount; i++)
                map.get_Layer(i).Visible = true;

            // restore extent
            activeView.FullExtent = mapaoi;
            activeView.Refresh();

            // Done
            trackCancel = null;
            stepProgressor = null;
            progressDialog2.HideDialog();
            progressDialog2 = null;
        }
예제 #21
0
        private void PerformLocationQuery(ISpatialFilter pSpatialFilter)
        {
            try
            {
                frmPromptQuerying frmPrompt = new frmPromptQuerying();//��ʾ���ռ��ѯ��
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();//'ת�ÿ���Ȩ��û����һ��Ļ���ʾ���ڲ���������ʾ
                string strLayerName;
                IFeatureLayer pFeatureLayer;
                IFeatureSelection pFeatureSelection;//������¼��ѯ�Ľ��
                foreach (object itemChecked in checkedListBoxFeaturesLayer1.CheckedItems)    //����ÿһ��ѡ�еIJ㶼ִ�в�ѯ������ϲ�
                {

                    strLayerName = itemChecked.ToString();    //������Ǵ���ѯ��layer
                    pFeatureLayer = GetLayerbyName(strLayerName) as IFeatureLayer;
                    pFeatureSelection = pFeatureLayer as IFeatureSelection;
                    pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);//��ѡ�IJ���ܲ�ֹһ��
                    //ͨ��ѭ�����β�ѯÿ���㣬�ѽ��add����

                }
                //�����ѡ��ѡ�У���λ��ѡ����
                if (checkBoxZoomtoSelected.Checked == true)
                {
                    IEnumFeature pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    IFeature pFeature = pEnumFeature.Next();
                    ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                    while (pFeature != null)
                    {
                        pEnvelope.Union(pFeature.Extent);
                        pFeature = pEnumFeature.Next();
                    }
                    MainAxMapControl.ActiveView.Extent = pEnvelope;
                    MainAxMapControl.ActiveView.Refresh();//���������ˢ�£�ֻҪ��ѯǰ��ͼ�Ѿ����Ŵ���Ч���Ļ�����λ��
                    //��ͼû��ˢ�£�ѡ�񼯵��Ƕ�λ��ˢ����
                }
                frmPrompt.Dispose();
                //�ѽ����ʾ����
                MainAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                //double i = MainAxMapControl.Map.SelectionCount;
                //i = Math.Round(i, 0);//С�����ָ��Ϊ��λ����
                //pMainform.toolStripStatusLabel1.Text = "��ǰ����" + i.ToString() + "����ѯ���";
            }
            catch (Exception ex)
            {
                MessageBox.Show("���ɲ�ѯ�������!���� | "+ex.Message);
                return;
            }
        }
예제 #22
0
        public static void AddNorthArrow(AxPageLayoutControl axpagelayoutcontrol, ESRI.ArcGIS.Carto.IMap map)
        {
            IPageLayout pageLayout;
               pageLayout = axpagelayoutcontrol.PageLayout;

            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(16, 24, 21, 29); //  Specify the location and size of the north arrow

            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.MarkerNorthArrow";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            ESRI.ArcGIS.Carto.IMarkerNorthArrow markerNorthArrow = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow; // Dynamic Cast
            ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;
            ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
            characterMarkerSymbol.CharacterIndex = 202; // change the symbol for the North Arrow
            markerNorthArrow.MarkerSymbol = characterMarkerSymbol;
        }
예제 #23
0
        public static void AddScalebar(AxPageLayoutControl axpagelayoutcontrol, ESRI.ArcGIS.Carto.IMap map)
        {
            IPageLayout pageLayout;
            pageLayout = axpagelayoutcontrol.PageLayout;

            if (pageLayout == null || map == null)
            {
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(8, 3, 15, 3.8); // Specify the location and size of the scalebar
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.AlternatingScaleBar";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));
            ITextSymbol scalbarsm = markerScaleBar.LabelSymbol;
            markerScaleBar.Units = esriUnits.esriKilometers;
            markerScaleBar.Name = "比例尺";
            markerScaleBar.Map = axpagelayoutcontrol.ActiveView.FocusMap;

            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriTop;
            //markerScaleBar.UseMapSettings();
        }
예제 #24
0
        /// <summary>
        /// 要素转成Grid
        /// </summary>
        /// <param name="pFeaureClass"></param>
        /// <param name="pRasterWorkspaceFolder"></param>
        /// <param name="pCellsize"></param>
        /// <param name="pGridName"></param>
        /// <returns></returns>
        public IGeoDataset CreateGridFromFeatureClass(IFeatureClass pFeaureClass, String pRasterWorkspaceFolder, double pCellsize ,string pGridName)
        {
            IGeoDataset pGeoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)pFeaureClass; // Explicit Cast

             ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;

            IConversionOp pConversionOp = new ESRI.ArcGIS.GeoAnalyst.RasterConversionOpClass();

             IWorkspaceFactory pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();

             IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pRasterWorkspaceFolder, 0);

             IRasterAnalysisEnvironment pAnalysisEnvironment = (ESRI.ArcGIS.GeoAnalyst.IRasterAnalysisEnvironment)pConversionOp; // Explicit Cast
             pAnalysisEnvironment.OutWorkspace = pWorkspace;

             ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
             pEnvelope = pGeoDataset.Extent;

             object pObjectCellSize = (System.Object)pCellsize;
             pAnalysisEnvironment.SetCellSize(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, ref pObjectCellSize);

             object object_Envelope = (System.Object)pEnvelope;
             object object_Missing = Type.Missing;
             pAnalysisEnvironment.SetExtent(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, ref object_Envelope, ref object_Missing);

             pAnalysisEnvironment.OutSpatialReference = pSpatialReference;

             IRasterDataset pRasterDataset = new ESRI.ArcGIS.DataSourcesRaster.RasterDatasetClass();

             pRasterDataset = pConversionOp.ToRasterDataset(pGeoDataset, "GRID", pWorkspace, pGridName);

            IGeoDataset pGeoOutput = (ESRI.ArcGIS.Geodatabase.IGeoDataset)pRasterDataset;

             return pGeoOutput;
        }