ArcGIS中python对图层固定边界字段进行插值、渲染并输出图片

    最近项目中有需要对shp中某一字段进行自动进行出图,在平时制作相应的模型然后输出python或发布成地图服务即可,但是因为涉及到出题出图要具体边界及渲染,功能实现比较简单,代码尽管各处都有可以作参考,但是还是都是零散的,还得花点时间去查找和重新组织,这里楼主对python代码进行组织和整理,希望能对有需要的人提供帮助。其他解释不多说,直接上代码:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# in.py
# Created on: 2017-11-03 17:26:10.00000
#   (generated by ArcGIS/ModelBuilder)LB
# Usage: in <abcd> <test_shp> <Z_value_field> <Output_cell_size> <fj_pro_shp> <Extract_abcd1>
# Description: 插值、渲染并输出图片
# ---------------------------------------------------------------------------
print "程序开始运行"

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Script arguments
abcd = arcpy.GetParameterAsText(0)
if abcd == '#' or not abcd:
    abcd = "F:\py\print_toPNG\\ccc" # provide a default value if unspecified

test_shp = arcpy.GetParameterAsText(1)
if test_shp == '#' or not test_shp:
    test_shp = "F:\\Fujian\\test.shp" # provide a default value if unspecified

Z_value_field = arcpy.GetParameterAsText(2)
if Z_value_field == '#' or not Z_value_field:
    Z_value_field = "jsl" # provide a default value if unspecified

Output_cell_size = arcpy.GetParameterAsText(3)
if Output_cell_size == '#' or not Output_cell_size:
    Output_cell_size = ".01" # provide a default value if unspecified

fj_pro_shp = arcpy.GetParameterAsText(4)
if fj_pro_shp == '#' or not fj_pro_shp:
    fj_pro_shp = "F:\\Fujian\\fj_pro.shp" # provide a default value if unspecified

Extract_abcd1 = arcpy.GetParameterAsText(5)
if Extract_abcd1 == '#' or not Extract_abcd1:
    Extract_abcd1 = "F:\py\print_toPNG\\cbd" # provide a default value if unspecified

# Local variables:
arcpy.env.extent = arcpy.Extent(115.848281860352,23.53125,120.837638854981,28.3126068115235)
print "进行插值运算中...."

# Process: IDW
arcpy.gp.Idw_sa(test_shp, Z_value_field, abcd, Output_cell_size, "2", "VARIABLE 12", "")

print "进行裁剪中...."
# Process: Extract by Mask
arcpy.gp.ExtractByMask_sa(abcd, fj_pro_shp, Extract_abcd1)

print "图层输出过程中...."

# Process:export map  mxd需要提供具体的渲染图层 格式为lyr
mxd = arcpy.mapping.MapDocument(r"F:\py\base.mxd")
lyr=arcpy.mapping.ListLayers(mxd)[0]
lyr.replaceDataSource(r"F:\py\print_toPNG","RASTER_WORKSPACE","cbd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.extent=arcpy.Extent(115.848281860352,23.53125,120.837638854981,28.3126068115235)
arcpy.mapping.ExportToPNG(mxd, r"F:\py\print_toPNG\kk.png", df,
                          df_export_width=1600,
                          df_export_height=1200,
                          world_file=True)

del mxd
print "运行结束"


  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值