地图输出栅格图片的简单方法,返回输出的文件名

/// <summary>
        /// 地图输出栅格图片的简单方法,返回输出的文件名
        /// </summary>
        /// <param name="pActiveView"></param>
        /// <returns></returns>
        public  static string  ExportImage(IActiveView pActiveView)
        {

            if (pActiveView == null)
            {
                return "";
            }
 
            SaveFileDialog pSaveFileDialog = new SaveFileDialog();
            pSaveFileDialog.Filter = "JPEG(*.jpeg)|*.jpeg|AI(*.ai)|*.ai|BMP(*.BMP)|*.bmp|EMF(*.emf)|*.emf|GIF(*.gif)          |*.gif|PDF(*.pdf)|*.pdf|PNG(*.png)|*.png|EPS(*.eps)|*.eps|SVG(*.svg)|*.svg|TIFF(*.tif)|*.tif";
            pSaveFileDialog.Title = "输出地图";
            pSaveFileDialog.RestoreDirectory = true;
            pSaveFileDialog.FilterIndex = 1;
 
            if (pSaveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return "";
            }
            string FileName = pSaveFileDialog.FileName;
           
            IExport pExporter = null;
            switch (pSaveFileDialog.FilterIndex)
            {
                case 1:
                    pExporter = new ExportJPEGClass();
                    break;
                case 2:
                    pExporter = new ExportBMPClass();
                    break;
                case 3:
                    pExporter = new ExportEMFClass();
                    break;
                case 4:
                    pExporter = new ExportGIFClass();
                    break;
 
                case 5:
                    pExporter = new ExportAIClass();
                    break;
 
                case 6:
                    pExporter = new ExportPDFClass();
                    break;
                case 7:
                    pExporter = new ExportPNGClass();
                    break;
                case 8:
                    pExporter = new ExportPSClass();
                    break;
                case 9:
                    pExporter = new ExportSVGClass();
                    break;
                case 10:
                    pExporter = new ExportTIFFClass();
                    break;
                default:
                    MessageBox.Show("输出格式错误");
                    return null;
 
            }
 
            int pResolution = (int)(pActiveView.ScreenDisplay.DisplayTransformation.Resolution);

            tagRECT ptagRECT = pActiveView.ExportFrame;//注意该处的代码,改为其他会出错

            IEnvelope pEnvelope = new EnvelopeClass();
            pEnvelope.PutCoords(ptagRECT.left, ptagRECT.bottom, ptagRECT.right, ptagRECT.top);

            ITrackCancel pTrackCancel = new CancelTrackerClass();

            pExporter.Resolution = pResolution;
            pExporter.ExportFileName = FileName;
            pExporter.PixelBounds = pEnvelope;

            pActiveView.Output(pExporter.StartExporting(), pResolution, ref ptagRECT, pActiveView.Extent, pTrackCancel);
            pExporter.FinishExporting();
            pExporter.Cleanup();
          
            //释放资源
            pSaveFileDialog.Dispose();
 
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pExporter);
 
            return FileName;

}

import rasterio import math import os import pandas as pd import numpy as np cellsize = 5 k=5 desktop = os.path.join(os.path.expanduser("~"), "Desktop") filename = "map.tif" file_path = os.path.join(desktop, filename) pi=math.pi def read_map(file_path): with rasterio.open(file_path) as src: # 读取地图的数据 map_data= src.read(1) return map_data def get_elevation(map_data, x, y): [r, c] = (np.array([12499 - y, x])).astype(np.int16) elevation = map_data[r, c] return elevation # 返回高程值 def deltax(map_data,x,y): if x==0 or y==0 or y==12499 or x==12499: return None # 边界情况 else: a=get_elevation(map_data, x-1, y+1) c=get_elevation(map_data,x+1, y+1) d=get_elevation(map_data, x-1, y) f=get_elevation(map_data,x+1, y) i=get_elevation(map_data,x+1, y-1) g=get_elevation(map_data, x-1, y-1) m=c+2*f+i n=a+2*d+g return k*(m-n)/(8*cellsize) def deltay(map_data,x,y): if x==0 or y==0 or y==12499 or x==12499: return None # 边界情况 else: a=get_elevation(map_data,x-1, y+1) c=get_elevation(map_data, x+1, y+1) b=get_elevation(map_data, x, y+1) h=get_elevation(map_data,x, y-1) i=get_elevation(map_data,x+1, y-1) g=get_elevation(map_data,x-1, y-1) m=a+2*b+c n=g+2*h+i return k*(m-n)/(8*cellsize) def podu(map_data,x,y): a=deltax(map_data,x,y) b=deltay(map_data,x,y) if a is None and b is None: return -2#边界 else: m=a**2+b**2 n=math.sqrt(m) x=math.atan(n) return round(x*180/pi,4) def poxiang(map_data,x,y):#a,deltax;b,deltay表格 a=deltax(map_data,x,y) b=deltay(map_data,x,y) if b==0 and a<0: return 90 elif a==0 and b>0: return 180 elif b==0 and a>0 : return 270 elif a==0 and b<0: return 0 elif a==0 and b==0: return -1#水平面 elif a is None and b is None: return -2#边界 else: c=abs(b) return round(270+math.atan(a/b) *180/pi-90*(b/c)) def faxiangliang(map_data,x,y): S=podu(map_data,x,y) A=poxiang(map_data,x,y) if A==-1:#水平面 n1=0 n2=0 n3=1 elif S==-2:#边界 n1=2 n2=2 n3=2 else: radianS = S*pi/180 radianA=A*pi/180 sS = math.sin(radianS) sA=math.sin(radianA) cA=math.cos(radianA) cS=math.cos(radianS) n1=round(sA*sS,2) n2=round(cA*sS,2) n3=round(cS,2) return [n1,n2,n3] # 定义参数 map_data = read_map(file_path) # 横纵坐标范围 x_coords = np.arange(0,12599) y_coords = np.arange(0,12599) # 创建空列表存储结果 data = [] # 遍历所有横纵坐标组合并计算新列 for x in x_coords: for y in y_coords: c = get_elevation(map_data ,x, y) d = podu(map_data,x, y) e = poxiang(map_data,x, y) f=faxiangliang(map_data,x, y) data.append({'栅格x坐标': x, '栅格y坐标': y, '栅格高程(m)': c, '栅格坡度': d, '栅格坡向': e, '法向量':f}) # 构建 DataFrame df = pd.DataFrame(data) # 指定文件名和完整路径 file_path = os.path.join(desktop, "问题二范围.xlsx") # 将 DataFrame 写入 Excel 文件 df.to_excel(file_path, index=False, engine="openpyxl")我这个代码运行效率太低了,无法完成计算,可以如何优化
最新发布
07-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值