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)
你好:
我这有个删除空涂层的:
供你参考下:
# -- coding: cp936 --import arcpy,os
from arcpy import env
## 删除空要素层
def deleteNullFeature(gdbsPath):
for r,ds,fs in oswalk(gdbsPath):
for d in ds:
if d[-4:] in ["gdb"]:
envworkspace=r+ossep+d
fcs=arcpyListFeatureClasses()
print "--------正在处理:"+d+"--------"
index=0
for fc in fcs:
rowCount=arcpyGetCount_management(fc)
if int(str(rowCount))==0:
arcpyDelete_management(fc)
index=index+1
print index,fc,"删除成功!"
print "--------共删除空图层:"+str(index)+"个--------"
if __name__=="__main__":
gdbsPath=osgetcwd()
print gdbsPath
deleteNullFeature(gdbsPath)
print "--------------------------------"
想用python 是下面含有经纬度表格的csv 文件转成点数据,并且存在gdb数据库中。

2、效果展示:

3、源代码展示
import arcpy
import os
from arcpy import env
arcpyenvworkspace = r"F:\publicClass\Ziongdb"
arcpyXYTableToPoint_management("F:\\publicClass\\testcsv","环境数据test22","X","Y")
arcpyAddMessage("我运行完了,主人!")

的坐标系是WGS1984

可以在代码里加输出坐标系:
arcpyXYTableToPoint_management("F:\\publicClass\\testcsv","环境数据2shp","X","Y",coordinate_system=arcpySpatialReference(4326) )
那导出shp 怎么做?看下面代码
import arcpy
import os
from arcpy import env
arcpyenvworkspace = r"F:\publicClass"
arcpyXYTableToPoint_management("F:\\publicClass\\testcsv","环境数据shp","X","Y")
arcpyAddMessage("我运行完了,主人!")
SQL语句存在问题,参见下图示例代码:
SQL语句最外层由双引号包含,然后是相应sql语句。
另外,对于文件存放位置也有要求:
最后,是我自己的测试,图层文件(layer)位于文件夹,不在数据库中:
判断是程序编写的一个基本的 *** 作,也是增强程序稳定性的重要方式。在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)
分类: 脚本开发
以上就是关于关于arcgis的python脚本编程, shape文件出png图片问题全部的内容,包括:关于arcgis的python脚本编程, shape文件出png图片问题、arcgis python 中,如何判断某个gdb数据库中某个图层存在、csv转gdb等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)