我是靠谱客的博主 小巧黑裤,这篇文章主要介绍关于Arcpy的一些笔记,现在分享给大家,希望可以做个参考。

(1)从mdb格式中提取shp格式的面图层

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
# coding:utf-8 #encoding:gbk import arcpy import os path=r'mdb格式输入路径' for filename in os.listdir(path): in_mdbpath=os.path.join(path,filename) arcpy.env.workspace = in_mdbpath lstFC = arcpy.ListFeatureClasses() outlocation=r'输出路径' arcpy.FeatureClassToShapefile_conversion(u'字段名',outlocation)

(2)合并shp文件,合并后shp文件最多2GB。

复制代码
1
2
3
4
5
6
7
arcpy.env.workspace=r"文件所在路径" fcs=arcpy.ListFeatureClasses() lspt=[] for fc in fcs: lspt.append(fc) arcpy.Merge_management(lspt,"输出名称")

(3)合并tif影像。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
path = '输入影像' outpath = '输出路径' outname = '输出名称.tif' tif_list=os.listdir(path) raster_list=[] for filename in tif_list: in_path=os.path.join(path,filename) raster_list.append(in_path) #raster_list为要合并的影像,outpath为输出影像路径,outname为输出影像名称,“”输入投影可以为空,其他可对应argis该功能来看参数指的是什么 arcpy.MosaicToNewRaster_management(raster_list,outpath,outname,"", "8_BIT_UNSIGNED","","1","LAST","FIRST")

(4)txt格式的点转换成lyr,并从影像上提取信息

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import arcpy import os import shutil from arcpy import env from arcpy.sa import * inpathicesat2="输入点的路径" inpathpoint="输出点图层.lyr路径" inpathdempoint="输出提取影像信息后的点路径" inRaster = "输入影像路径" #创建文件夹,如果文件夹存在则清空 if not os.path.exists(inpathpoint): os.mkdir(inpathpoint) else: shutil.rmtree(inpathpoint) os.mkdir(inpathpoint) if not os.path.exists(inpathdempoint): os.mkdir(inpathdempoint) else: shutil.rmtree(inpathdempoint) os.mkdir(inpathdempoint) mylists=os.listdir(inpathicesat2) for list in mylists: list=os.path.splitext(list)[0] try: list=os.path.basename(list) in_Table = inpathicesat2+list+".txt" x_coords = "Field1" y_coords = "Field2" z_coords = "Field3" out_Layer = list+".lyr" saved_Layer = inpathpoint+list+".lyr" spRef = r"Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj" # 把txt点信息转换成点.lyr arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords) # Print the total rows print arcpy.GetCount_management(out_Layer) # Save to a layer file arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) #RASTERVALU如果存在,则替换 fieldName1 = "替换" arcpy.AddField_management(in_Table, fieldName1, "FLOAT") arcpy.CalculateField_management(in_Table, "替换", "!RASTERVALU!", "PYTHON_9.3") arcpy.DeleteField_management(in_Table, "RASTERVALU") # 点从影像提取信息 inPointFeatures = out_Layer outPointFeatures = inpathdempoint+list+".shp" # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Execute ExtractValuesToPoints ExtractValuesToPoints(inPointFeatures, inRaster, outPointFeatures) except: # If an error occurred print the message to the screen print arcpy.GetMessages()

(5)输出表格

复制代码
1
2
3
4
5
out_xls = "表格路径.xls" outLocation = "gdb路径" outPointFeatures = "路径.shp" arcpy.TableToTable_conversion(outPointFeatures, outLocation, out_xls)

(6) shp转tif

复制代码
1
2
3
4
5
6
7
8
9
arcpy.env.workspace="shp文件输入路径" output="输出路径" shplist=arcpy.ListFeatureClasses() for inFeature in shplist: field="字段名" outRaster=os.path.join(output,inFeature+".tif") cellSize=1(自定义) arcpy.FeatureToRaster_conversion(inFeature, field, outRaster, cellSize)

最后

以上就是小巧黑裤最近收集整理的关于关于Arcpy的一些笔记的全部内容,更多相关关于Arcpy内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部