案例:将栅格(tif)格式数据范围导出到一个矢量(shp)格式文件中
场景: 想要将datatif格式数据导出到datashp格式文件中并添加属性名称
脚本:Python脚本示范
def Export_TifRangeToShp_WithAttr(src_data, dst_data, attr_name, attr_value):
arcpyenvworkspace = r'C:/Users/Administrator/Documents/ArcGIS/Defaultgdb'
arcpyRasterDomain_3d(src_data, dst_data, 'POLYGON')
arcpyAddField_management(dst_data, attr_name, 'TEXT')
# arcpyAddField_management(dst_shp, attr_name, "TEXT", "", "", 32, "", "NULLABLE")
arcpyCalculateField_management(dst_data, attr_name, '"%s"' % attr_value, 'PYTHON_93')
Export_TifRangeToShp_WithAttr(r'datatif', r'datashp', 'NAME', 'Data')
判断是程序编写的一个基本的 *** 作,也是增强程序稳定性的重要方式。在ArcPy处理数据时,要保证数据存在才能做后续的 *** 作,为源GIS提示使用arcpy自带的Exists函数可判断要素类、表、数据集、shapefile、工作空间、图层和文件等是否存在。
使用方法
如果是文件路径,可以使用Python中的ospathexists来判断,但如果文件地理数据库中数据集、要素类等则需要使用ArcPy提供的Exists函数(非工具函数)。
使用方法:
支持检查的格式包括要素类、表、数据集、shapefile、工作空间、图层和文件;
返回Bool类型表示是否存在;
Exists 支持地理处理工作空间环境,允许只输出数据的基本名称;
如果是企业地理数据库中,则必须对名称进行完全限定。
语法参数
Exists (dataset)
参数 说明 数据类型
dataset 要检查其是否存在的数据集的路径。 String
返回值
数据类型 说明
Boolean 如果指定元素存在,则返回布尔值 True。
代码示例
import arcpy
# 设置工作空间
arcpyenvworkspace = "C:/TemplateData/TemplateDatagdb"
fc = "city"
# 如果存在则进行相关 *** 作
if arcpyExists(fc):
arcpyClip_analysis(fc, "Continents", "Continents_clip)
分类: 脚本开发
1、点类型的转栅格:
PointToRaster example 1 (Pythonwindow)
Converts point features to a raster dataset
import arcpy
from arcpy import env
envworkspace = "c:/data"
arcpyPointToRaster_conversion("ca_ozone_ptsshp", "ELEVATION",
"c:/output/ca_elev", "MAXIMUM", "", 2000)
PointToRaster example 2
(stand-alone script)
Converts point features to a raster dataset
# Name: PointToRaster_Ex_02py
# Description: Converts point features to a raster dataset
# Requirements: ArcInfo
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
envworkspace = "C:/data"
# Set local variables
inFeatures = "ca_ozone_ptsshp"
valField = "ELEVATION"
outRaster = "c:/output/ca_elev02"
assignmentType = "MAXIMUM"
priorityField = ""
cellSize = 2000
# Execute PointToRaster
arcpyPointToRaster_conversion(inFeatures, valField, outRaster,
assignmentType, priorityField, cellSize)
2、面类型的转栅格:
PolygonToRaster example 1(Python window)
Converts polygon features to a raster dataset
import arcpy
from arcpy import env
envworkspace = "c:/data"
arcpyPolygonToRaster_conversion("ca_countiesshp", "NAME",
"c:/output/ca_countiesimg",
"MAXIMUM_AREA", "MALES", 025)
PolygonToRaster example 2
(stand-alone script)
Converts polygon features to a raster dataset
# Name: PolygonToRaster_Ex_02py
# Description: Converts polygon features to a raster dataset
# Requirements: ArcInfo
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
envworkspace = "C:/data"
# Set local variables
inFeatures = "ca_countiesshp"
valField = "NAME"
outRaster = "c:/output/ca_counties"
assignmentType = "MAXIMUM_AREA"
priorityField = "MALES"
cellSize = 05
# Execute PolygonToRaster
arcpyPolygonToRaster_conversion(inFeatures, valField, outRaster,
assignmentType, priorityField, cellSize)
3、线类型转栅格
PolylineToRaster example 1(Python window)
Converts polyline features to a raster dataset
import arcpy
from arcpy import env
envworkspace = "c:/data"
arcpyPolylineToRaster_conversion("roadsshp", "CLASS", "c:/output/roadsimg",
"MAXIMUM_COMBINED_LENGTH", "LENGTH", 30)
PolylineToRaster example 2
(stand-alone script)
Converts polyline features to a raster dataset
# Name: PolylineToRaster_Ex_02py
# Description: Converts polyline features to a raster dataset
# Requirements: ArcInfo
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
envworkspace = "C:/data"
# Set local variables
inFeatures = "roadsshp"
valField = "CLASS"
outRaster = "c:/output/roadstif"
assignmentType = "MAXIMUM_COMBINED_LENGTH"
priorityField = "LENGTH"
cellSize = 30
# Execute PolylineToRaster
arcpyPolylineToRaster_conversion(inFeatures, valField, outRaster,
assignmentType, priorityField, cellSize)
以上就是关于Arcgis之栅格数据范围导出到矢量文件全部的内容,包括:Arcgis之栅格数据范围导出到矢量文件、python中判断图层是否存在、关于arcgis的python脚本编程, shape文件出png图片问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)