码迷,mamicode.com
首页 > 编程语言 > 详细

python 读取全国城市aqi数据,差值生成png图片

时间:2016-06-15 01:29:23      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

# -*- 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 = rF:\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

 

python 读取全国城市aqi数据,差值生成png图片

标签:

原文地址:http://www.cnblogs.com/tiandi/p/5585966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!