标签:
# -*- coding: utf-8 -*- import arcpy import sys import datetime import cx_Oracle import json import os import time import uuid from arcpy import env from arcpy.sa import * env.workspace = r"F:\py"; mapPath = r"F:\py"; imagepath = r‘F:\py\images\2016-06-07‘ arcpy.AddMessage("1.查询数据库"); cnxn = cx_Oracle.connect(‘jinan/jinan@127.0.0.1:1521/orcl‘) cursor = cnxn.cursor(); sql = "select citycode,aqi from city "; cursor.execute(sql); cursorData = cursor ; arcpy.AddMessage("2.数据保存到fc"); for item in cursorData: print item[0]+‘-‘+item[1]; fc = "F:\py\jinan.gdb/city"; where = "CITYCODE=" +item[0]; rows = arcpy.UpdateCursor(fc,where); for row in rows: row.setValue(‘aqi1‘,item[1]); rows.updateRow(row) del rows ,fc; arcpy.AddMessage("3.进行差值操作"); inPointFeatures = "F:\py\jinan.gdb/city"; inBarrierFeature = "F:\py\jinan.gdb/barrier"; cellSize = 10000.0 arcpy.CheckOutExtension("Spatial") outSplineBarriers = SplineWithBarriers(inPointFeatures, ‘aqi1‘, inBarrierFeature, cellSize, 1); tif = "pointraster.tif"; tif1 = "pointraster1.tif"; outSplineBarriers.save(tif); arcpy.AddMessage("4.根据行政区边界图层剪切栅格") outExtractByMask = ExtractByMask(tif, inBarrierFeature) outExtractByMask.save(tif1) arcpy.AddMessage("5.更新mxd"); mxdPath = mapPath + r"\pointraster1.mxd"; mxd = arcpy.mapping.MapDocument(mxdPath); df = arcpy.mapping.ListDataFrames(mxd, "")[0]; for lyr in arcpy.mapping.ListLayers(mxd, "", df): arcpy.mapping.RemoveLayer(df, lyr); addLayer = arcpy.mapping.Layer(mapPath + r"\pointraster1.lyr") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") arcpy.AddMessage("6.输出图片png"); fileName ="aqi.png" df.extent = addLayer.getSelectedExtent() arcpy.mapping.ExportToPNG(mxd, imagepath+"\\" + fileName , df, background_color="255,255,255", transparent_color="255,255,255",world_file=True); arcpy.AddMessage("7.清理内存") del mxd, addLayer,df,outSplineBarriers,inPointFeatures,inBarrierFeature
标签:
原文地址:http://www.cnblogs.com/tiandi/p/5585966.html