如何用raster切割python shapefilee

ArcGIS Python实现批量化栅格数据重命名
[python]&&
import arcpy arcpy.env.workspace = F:\NDVI\
rasters = arcpy.ListRasters(*, grid) for raster in rasters:
Rename=Re_+raster arcpy.Rename_management(raster, Rename, RasterDataset)
print(raster+----&+Rename) print(All done)
import arcpy
arcpy.env.workspace = F:\NDVI\
rasters = arcpy.ListRasters(*, grid)
for raster in rasters:
Rename=Re_+raster
arcpy.Rename_management(raster, Rename, RasterDataset)
print(raster+----&+Rename)
print(All done)
1.本次处理的是栅格数据,也可以用来处理矢量(ShapeFile)和文本文件(TextFile)
2.不改变数据的格式;
3.只能在原数据的基础上重命名,不能生成新文件。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'【IDL代码库】利用shp文件裁剪栅格图像
的shpO(∩_∩)o
ENVI& file='D:\temp\image.dat'
envi_open_file,
file, r_fid=fid
ENVI& shpFile =
'D:\temp\vector.shp'
RasterSubsetViaShapefile,
shpFile=shpFile,&&&&
outFile='D:\temp\result.dat',
r_fid=r_fid
; :Description:
利用shapefile对栅格图像进行裁剪.
RasterSubsetViaShapefile, Fid, shpFile=string,
[pos=array],
[inside={0|1}], [outFile={string|variable}],
[r_fid=variable]
; :Params:
输入文件FID
;&&&&&&&&&&&&&&
注:可通过ENVI_OPEN_FILE、ENVI_SELECT、ENVIRasterToFID等获取
; :Keywords:
保留波段索引数组(可选),默认保留所有波段。
shpFile --
用于裁剪的shapefile完整路径
保留shp文件外或内(可选,0或1),默认保留内部。
;&&&&&&&&&&&&&&&&&&&&&&&&
注:设置0时,保留外部;设置1时,保留内部。
outFile --
裁减结果文件路径(可选)
;&&&&&&&&&&&&&&&&&&&&&&&
注:如果不设置或设置为变量,则裁剪结果保存在临时目录中,outFile将保存输出文件名
;&&&&&&&&&&&&&&&&&&&&&&&&
注:如果设置为文件路径,则裁剪结果保存在指定路径中
返回裁剪结果文件FID,如果范围-1,则表示裁剪失败。
; :Author: .cn
; :Date: 2015年9月2日
RasterSubsetViaShapefile,
Fid, shpFile=shpFile, pos=pos, $
inside=inside, outFile=outFile, r_fid=r_fid
COMPILE_OPT
/RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT
+ !ERROR_STATE.MSG
ENVI_FILE_QUERY,
fid, ns=ns, nl=nl, nb=nb, $
dims=dims, fname=fname, bnames=bnames
~N_ELEMENTS(pos)&&&&&
LINDGEN(nb)
~N_ELEMENTS(inside)&&
~KEYWORD_SET(outFile)
outFile = envi_get_tmp()
;读取shp文件的信息
oshp=OBJ_NEW('IDLffShape',shpFile)
~OBJ_VALID(oshp)
oshp-&GETPROPERTY,n_entities=n_ent,$
Attribute_info=attr_info,$
;属性信息,结构体,
name为属性名
ATTRIBUTE_NAMES = attr_names, $
n_attributes=n_attr,$
Entity_type=ent_type&
ENVI_PROJ_CREATE(/geographic)
;自动读取prj文件获取投影坐标系
STRPOS(shpFile,'.',/reverse_search)&
STRMID(shpFile,0,potPos[0])+'.prj'
FILE_TEST(prjfile)
lun, prjFile, /GET_LUN
lun, strprj
STRMID(strprj,
ENVI_PROJ_CREATE(PE_COORD_SYS_STR=strprj,
ENVI_PROJ_CREATE(PE_COORD_SYS_STR=strprj,
ENVI_GET_PROJECTION(fid
;然后使用ROI进行掩膜统计
& roi_ids =
ent = oshp-&GETENTITY(i,
/ATTRIBUTES)
;第i条记录
;如果ent不是多边形,则继续
ent.SHAPE_TYPE
N_VERTICES=ent.N_VERTICES
parts=*(ent.PARTS)
verts=*(ent.VERTICES)
将顶点坐标转换为输入文件的地理坐标
ENVI_CONVERT_PROJECTION_COORDINATES,&
verts[0,*],
verts[1,*],
oXmap, oYmap, oProj
转换为文件坐标
ENVI_CONVERT_FILE_COORDINATES,fid,&&&
xFile,yFile,oXmap,oYmap
MIN(xFile)
MIN(yFile)
MAX(xFile)
MAX(yFile)
;记录XY的区间,裁剪用
ROUND(MIN(xFile,max
ROUND(MIN(yFile,max
xmin = xMin &&/SPAN&
ROUND(MIN(xFile))
xMax = xMax &
ROUND(MAX(xFile))
yMin = yMin &&/SPAN&
ROUND(MIN(yFile))
yMax = yMax &
ROUND(MAX(yFile))
N_ELEMENTS(Parts)
ENVI_CREATE_ROI(color=i,&&&&
ns = ns ,&
tmpFileX = xFile[Parts[j]:*]
tmpFileY = yFile[Parts[j]:*]
tmpFileX = xFile[Parts[j]:Parts[j+1]-1]
tmpFileY = yFile[Parts[j]:Parts[j+1]-1]
ENVI_DEFINE_ROI,
roi_id, /polygon,&&&
xpts=REFORM(tmpFileX),
ypts=REFORM(tmpFileY)
;如果有的ROI像元数为0,则不保存
ENVI_GET_ROI_INFORMATION,
roi_id, NPTS=npts
roi_ids = [roi_ids, roi_id]
;创建掩膜,裁剪后掩
ENVI_MASK_DOIT,&&&&&&&&
2,&&&&&&&&&&
IN_MEMORY=0,&&&&&&&&&
ROI_IDS= roi_ids,&&&&
ns = ns, nl = nl,&&&&
inside=inside,&&&&&&&
;区域内或外
r_fid = m_fid,&&&&&&&
out_name = envi_get_tmp()
out_dims=dims
---即不规则裁剪
;out_dims必须round,否则报错
xMin = xMin &0
ROUND(xMax)
yMin = yMin &0
ROUND(yMax)
out_dims = [-1,xMin,xMax,yMin,yMax]
ENVI_MASK_APPLY_DOIT,
FID = fid,&&&&&
POS = POS,&&&&&&&&&&&&&&&&&&&&&&&&&
DIMS = out_dims,&&&&&&&&&&&&&&&&&&&
M_FID = m_fid, M_POS = [0],&&&&&&&&
r_fid = r_fid,&&&&&&&&&&
OUT_NAME = outFile
掩膜文件ID移除
ENVI_FILE_MNG,
ID = m_fid,/REMOVE,/DELETE
OBJ_DESTROY,oshp
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。怎么利用ARCGIS裁剪图像
可以根据1、范围来采集\x0dclip(arctoolbox里面).矩形范围\x0d2、好像也可以通过多边形裁剪,如果没有,程序肯定可以的\x0d3、通过mosaic也可以\x0d1、对矢量数据进行裁减:Arctoolbox中,spatial tool\x0dextractclip\x0d在InputFeatures中选择被裁剪的图层,在ClipFeatures中选择裁剪形状\x0d2、利用矩形对栅格数据裁剪:Arctoolbox中,data\x0dmanagementrasterclip\x0dInputRaster中选择被裁剪的栅格数据,设定好矩形四个顶点即可\x0d3、在Spatial Analyst Tools中提供了多种对栅格数据的提取方法,Arctoolbox中,SpatialAnalystToolsextraction包括提取值到点,根据属性提取,用圆提取,用多边形提取,用掩模提取,用点提取,用矩形提取等,其中的用掩模提取功能可以让我们通过不规则边界来获取需要的栅格数据.\x0darcgis图层裁剪\x0d首先在ArcCatlog 里创建一个shapefile得面,加载到arcmap里,同时也要\x0d把你剪切的shapefile文件和长方形区域的shapefile文件也加载上,切忌这两个文件不能处于编辑状态,点击arctoolbox-analysis\x0dtools-extract-clip,在打开的窗口的第一个框里输入要剪切的文件,第二个框里输入长方形区域文件,点ok就好了.
为您推荐:
其他类似问题
扫描下载二维码字号:大 中 小
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.}}" id=paperPicArea0 style="DISPLAY: none" src="http://edu./ac/b.gif">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.}}" id=paperPicArea style="DISPLAY: none" src="http://edu./ac/b.gif">
ArcGIS9:&& ArcToolbox--&Spatail Analyst Tools--&Extraction
ArcGIS8.X: 在ArcMap --& Spatial Analyst扩展模块工具条--〉Raster& Calculator 或者直接使用Mask
1、对矢量数据进行裁减:Arctoolbox中,spatialtool&extract&clip 在InputFeatures中选择被裁剪的图层,在ClipFeatures中选择裁剪形状 2、利用矩形对栅格数据裁剪:Arctoolbox中,datamanagement&raster&clip InputRaster中选择被裁剪的栅格数据,设定好矩形四个顶点即可 3、在SpatialAnalystTools中提供了多种对栅格数据的提取方法,Arctoolbox中,SpatialAnalyst Tools&extraction包括提取值到点,根据属性提取,用圆提取,用多边形提取,用掩模提取,用点提取,用矩形提取等,其中的用掩模提取功能可以让我们通过不规则边界来获取需要的栅格数据。
可以先建一个polygon的图层,再用这个图层clip那个raster
加载空间分析模块,
option选项中设置mask图层,范围,cell尺寸,
用其栅格计算器计算:
图层名.shape*1,
点击evaluation,
如果不要求一定要多变形裁剪的话,建议使用clipdata management toolbox---clip这个工具可以保持原有像元信息,但是这里arcmap只提供了矩形切割。这个约束应该不会影响一般的应用,否则的话建议使用图像处理软件中的mask裁剪。
另外上面大家说得mask什么的方法,只能出来灰度图,可能原先是设计成处理grid的数据吧
(2) 用任意多边形剪切栅格数据(矢量数据转换为栅格数据) 2.1在ArcCatlog下新建一个要素类(要素类型为:多边形),命名为:ClipPoly.shp 2.2在ArcMap中,加载栅格数据:例如 kunming.img、和ClipPoly.shp 2.3打开 编辑器 工具栏,开始编辑 ClipPoly ,根据要剪切的区域,绘制一个任意形状的多边形。打开属性表,修改多边形的字段“ID”的值为1,保存修改,停止编辑。 2.4打开 空间分析 工具栏&& 执行命令:&空间分析&-&转换&--&要素到栅格& 指定栅格大小:查询要剪切的栅格图层kunming的栅格大小,这里假设指定为1 指定输出栅格的名称为路径 2.5执行命令: &空间分析&-&栅格计算器& 2.6构造表达式:[kunming]*[polyClip4-polyclip4] ,执行 栅格图层:kunming和 用以剪切的栅格 polyClip4 之间的 相乘运算
两种方法差不多,第一种可能更好些,第二种是自己发现的虽然不怎么好 但也分享下,希望有用& 呵呵
(1) 是否需要裁剪栅格图象区域通过一个面状的shapefile表达出来? 如果可以,那么就很简单了。 在ArcMap中,调用空间分析扩展模块,将你感兴趣区的shapefile多边形图层设置为掩膜,然后在栅格计算器中重新计算一下你的图象,它就会沿掩膜裁出。 &设置掩膜:空间分析工具条的下拉菜单&option里面设置 &(2) 用任意多边形剪切栅格数据(矢量数据转换为栅格数据) 2.1在ArcCatlog下新建一个要素类(要素类型为:多边形),命名为:ClipPoly.shp 2.2在ArcMap中,加载栅格数据:例如 kunming.img、和ClipPoly.shp 2.3打开 编辑器 工具栏,开始编辑 ClipPoly ,根据要剪切的区域,绘制一个任意形状的多边形。打开属性表,修改多边形的字段“ID”的值为1,保存修改,停止编辑。 2.4打开 空间分析 工具栏&& 执行命令:&空间分析&-&转换&--&要素到栅格& 指定栅格大小:查询要剪切的栅格图层kunming的栅格大小,这里假设指定为1 指定输出栅格的名称为路径 2.5执行命令: &空间分析&-&栅格计算器& 2.6构造表达式:[kunming]*[polyClip4-polyclip4] ,执行 栅格图层:kunming和 用以剪切的栅格 polyClip4 之间的 相乘运算
&使用ArcGIS的Raster Caclutaor剪切栅格文件
如果我们需要把一个栅格文件(可以是tif、grid等arcgis所能识别的)的一部分特定感兴趣区截取出来,而且是任意形状的那种,就可以使用arcgis的Raster Caclutaor功能实现。利用Raster Caclutaor功能我们也可以把某个栅格图像与某一个矢量文件的相重叠部分单独切出来。两者的步骤基本一致,都是需要把矢量文件先转成栅格格式,然后利用进行象元间的加减乘除操作。步骤:1.& 将矢量文件和栅格文件同时添加到arcmap当中。2.& 先将矢量文件转为栅格文件” polygonRaster - polygonraster”Spatial analysis工具条下的convert, Features to Raster3. Spatial analysis工具条打开Raster Caclutaor,在计算框内输入:[Topo.sid] - [polygonRaster - polygonraster]。&Tips:这里采用的是两图层相剪操作,是因为polygonRaster C polygonrasterd栅格文件的Value为0,这样两图层象素间Value值对应相减,得到的是Topo.sid的Value值。如果说polygonRaster C polygonrasterd的value值为1.为了获得Topo.sid的value值则应该选择两图层象素值相乘操作。有时候这样的图层相剪操作会不成功,提示“Error:& Failed to evaluate the calculator expression”。目前我还不太清楚具体原因是什么,在ESRI支持中心找到一篇文章,提到了可能的原因(语法错误、像元大小不一致、大小写不一致等)()&The error message "Failed to evaluate the calculator equation" appears after clicking Evaluate on the Raster Calculator dialog box.CauseThere are several causes for this problem: • You have a syntax error in the calculator expression. • The extent and cell size of your input raster is different than the extent set for your analysis results. • The expression will not be evaluated if there are carriage returns before or after the expression. • The Raster Calculator is case sensitive. • There are too many open grids. There is a limit of 50 open rasters of the grid format at any one time.Solution or WorkaroundSome of these issues have been addressed in ArcGIS Version 8.1.2.
The corresponding workarounds for the above causes are:Check your syntax. Type Map Algebra in the index of the online Help system for information on Map Algebra and its syntax. Make sure the extent and cell size of your analysis result is set appropriately in the Extent and cell size tabs of the Options dialog box. The extent of your analysis results should be set the same as, or encompass, the extent of the layer you are using in the Raster Calculator. Do not use carriage returns in your expression. Allow the expression to word-wrap if it is lengthy. This problem has been resolved in ArcGIS 8.1.2. Make sure the layer name typed into the expression box case-matches the name of the layer in the Layers list. For example: Layer name: ElevationExpression typed: slope([elevation]) This expression will not work. The first letter of "elevation" should be capitalized. This problem has been resolved in ArcGIS 8.1.2. Remove any un-needed grids from the ArcMap Table of Contents. The total number of open grids, including the one being created by the Spatial Analyst function, cannot exceed 50. This limit does not apply to non-grid rasters. A workaround is to convert grids to rasters in ArcCatalog with the Export & Raster To Different Format option
function open_phone(e) {
var context = document.title.replace(/%/g, '%');
var url = document.location.
open("/ishare.do?m=t&u=" + encodeURIComponent(url) + "&t=" + encodeURIComponent(context) + "&sid=70cd6ed4a0");
!觉得精彩就顶一下,顶的多了,文章将出现在更重要的位置上。
大 名:&&[]&&[注册成为和讯用户]
(不填写则显示为匿名者)
(您的网址,可以不填)
请根据下图中的字符输入验证码:
(您的评论将有可能审核后才能发表)
已成功添加“”到
请不要超过6个字

我要回帖

更多关于 shapefile地图下载 的文章

 

随机推荐