arcgis 栅格计算器,img叠加运算,con函数,img转txt
# -*-coding:utf-8 -*-import arcpy
from arcpy import env
import os
import shutilclass GridCalculator(object):""":栅格计算器 con函数的使用"""def __init__(self):#img文件临时存储路径self.OUTPATH = 'F:/arcgis_temp/raster/'#img文件存储路径self.IMGPATH = 'F:/arcgis_temp/img/'#环境变量设置 上下左右经纬度self.x_min = 104.250self.y_min = 35.200self.x_max = 107.700self.y_max = 39.400def overlay(self,dicts,formula,out_path,file_name):""":栅格计算器img栅格图层叠加运算:params dicts :计算公式中用到的img文件名称{"img1":r"F:/test/test.img","img2":r"F:/test2/test2.img",}formula :栅格计算器使用的公式out_path:输出文件路径file_name:输出的文件名称 *.img:return 返回输出的文件路径"""try:#组合形成完整的栅格计算器的计算公式for key,values in dicts.items():formula = formula.replace('{'+key+'}','"'+values+'"')env.overwriteOutput = Truefilepath = self.OUTPATH+'overlay/'+out_path#如果路径不存在,新建目录if not os.path.exists(filepath):os.makedirs(filepath)#工作空间env.workspace = filepath#环境变量设置 上下左右经纬度env.extent = arcpy.Extent( self.x_min, self.y_min, self.x_max, self.y_max)arcpy.gp.RasterCalculator_sa(formula, file_name)#如果路径不存在,新建目录if not os.path.exists(self.IMGPATH+'overlay/'+out_path):os.makedirs(self.IMGPATH+'overlay/'+out_path)img_name = self.IMGPATH+'overlay/'+out_path+"/"+file_name+".img"#将文件永久保存shutil.copyfile(filepath+"/"+file_name,img_name)#删除所有的临时文件self.remove_all_file(filepath)#返回输出的文件路径return img_nameexcept:raisedef remove_all_file(self,path):""":删除文件夹下多有文件"""try:for i in os.listdir(path):path_file = os.path.join(path,i) #取文件绝对路径os.remove(path_file)except:raisedef img_to_txt(self,in_raster,out_txt,filename):""":将img文件转换为格点数据文件:params in_raster :需要转换的img文件路径 F:/test.imgout_txt :输出的txt文件路径 F:/filename :输出的txt文件名称 test.txt"""try:#如果路径不存在,新建目录if not os.path.exists(out_txt):os.makedirs(out_txt)arcpy.RasterToASCII_conversion (in_raster, out_txt+"/"+filename)except:raiseif __name__ == '__main__':"""栅格图层叠加预算示例————即公式计算"""formula = '0.2*{img1}-1+0.8*{img2}+1.25'dicts = {"img1" : r"F:/arcgis_temp/img/CDCF/test.img","img2" : r"F:/arcgis_temp/img/aaaa/aaa.img",}out_path = 'test'file_name = 'test.img'gc=GridCalculator()gc.overlay(dicts, formula,out_path,file_name)"""栅格计算器,con函数 ————即指标判断"""formula = ( 'Con( ({img1}<=10),1,''Con( ({img1}>10)&({img1}<=20),2,3))')dicts = {"img1" : r"F:/arcgis_temp/img/CDCF/test.img",}out_path = 'test'file_name = 'test1.img'gc=GridCalculator()gc.overlay(dicts, formula,out_path,file_name)
arcgis 栅格计算器,img叠加运算,con函数,img转txt相关推荐
- ArcGIS 栅格计算器con函数用法
笔记: 调出栅格计算器: Spatial Analyst tools → Map Algebra → Raster Calculator con(条件)函数用法: 基本语句: con(条件(语句),真 ...
- ArcGIS 栅格计算器 Con用法
ArcGIS 栅格计算器 Con用法 前言 栅格计算器 Con函数用法 ArcGIS 案例操作 关注公众号,分享GIS知识.ArcGIS教程.SCI论文与科研日常等 前言 栅格计算器 栅格计算器界面如 ...
- arcgis栅格计算器python教程_ArcGIS栅格计算器
栅格计算是栅格数数据空间分析中数据处理和分析中最为常用的方法,应用非常广泛,能够解决各种类型的问题,尤其重要的是,它是建立复杂的应用数学模型的基本模块.ArcGIS提供了非常友好的图形化栅格计算器,利 ...
- ArcGIS栅格计算器
栅格计算是栅格数数据空间分析中数据处理和分析中最为常用的方法,应用非常广泛,能够解决各种类型的问题,尤其重要的是,它是建立复杂的应用数学模型的基本模块.ArcGIS提供了非常友好的图形化栅格计算器,利 ...
- Arcgis 栅格计算器小操作【转】
arcgis栅格计算器发生错误ERROR 000539:Error running expression:rcexec()<type 'exceptions.ValueError'>:Th ...
- ArcGIS 栅格计算器con()函数用法
函数的基本语句:con(条件(语句),真(语句),假(语句)) 若"真(语句)"或"假(语句)"存在缺失,则对应栅格单元的值赋值为空(NoData). 三处语句 ...
- Python实现ARCGIS栅格计算器con函数功能
目的 现有某地区土地利用类型图,图中不同的数值代表不同的土地利用类型,如像元值为20的,我们重新赋值为0,像元值为123的,我们重新赋值为15等等. 图1 原始图像 图2 结果图像 代码如下 from ...
- [ArcGIS] 栅格计算器
[规定]{SQL表达式}表示此为可选参数(用{}标识) 未完- 文章目录 函数 常用例子 详细说明 示例 函数 常用例子 函数名称 例子 Con Con( %elevation% > 2000, ...
- arcgis 栅格计算器(Spatial Analyst/Raster Calculator)
原文地址:点击打开链接 栅格计算器中用得到$$相关函数 $$NROWS: the number of rows in the analysis window (行数) $$NCOLS: the num ...
最新文章
- linux shell if [[ ]]和[ ]区别 ||
- CPU是怎样制造的?解析intel Core i7生产全过程
- html 鼠标单击单元格,vue-easytable点击表格中某个单元格操作
- 力扣两数之和 II - 输入有序数组
- python的整数类型_Python int 数字整型类型 定义int()范围大小转换
- Spark2.3.1在Idea控制台调整日志等级
- tree命令生成目录结构
- 怎么找回计算机用户名密码怎么办,电脑steam账号密码忘记了怎么办|电脑找回steam账户的方法...
- 一纬度横直线等于多公里_【地理】高中地理必修一知识点总结,考前必看
- LVS负载均衡器的原理简单介绍
- 别人都在谈降维攻击和下沉市场,而我却偏偏就要讲升维
- 在CityEngine中制作绘制路网
- 号外号外 !新媒之家APP2.1.0版本震撼上线!!!
- TypeError Class constructor ExampleService cannot be invoked withou ‘new‘ at
- 开发小程序需要多少钱
- Android中铃声的使用
- vue调用电脑端摄像头实时拍照
- 职中计算机一级证,职中计算机等级一级考证教学网站的设计
- 拓嘉辰丰电商:多多国际入驻,需要什么资质条件
- js:三种简单的矩形绘制方法(画布canvas)