#-*-coding:utf-8-*-ImportarcpyImportSYSImportdatetimeImportcx_oracleImportJSONImportOSImport TimeImportUUID fromarcpyImportEnv fromArcpy.saImport*Env.workspace= R"F:\py"; MapPath= R"F:\py"; ImagePath= R'F:\py\images\2016-06-07'arcpy. AddMessage ("1. Querying the database"); Cnxn= Cx_oracle.connect ('Jinan/[email PROTECTED]:1521/ORCL') Cursor=cnxn.cursor (); SQL="Select Citycode,aqi from city"; cursor.execute (sql); Cursordata=cursor, arcpy. AddMessage ("2. Data saved to FC"); forIteminchCursordata:Printitem[0]+'-'+item[1]; FC="f:\py\jinan.gdb/city"; where="citycode="+Item[0]; Rows=arcpy. Updatecursor (Fc,where); forRowinchRows:row.setValue ('Aqi1', item[1]); Rows.updaterow (Row)delrows, fc;arcpy. AddMessage ("3. Perform a difference operation"); Inpointfeatures="f:\py\jinan.gdb/city"; Inbarrierfeature="F:\py\jinan.gdb/barrier"; Cellsize= 10000.0arcpy. Checkoutextension ("Spatial") Outsplinebarriers= Splinewithbarriers (Inpointfeatures,'Aqi1', Inbarrierfeature, cellsize, 1); TIF="pointraster.tif"; TIF1="pointraster1.tif"; Outsplinebarriers.save (TIF); arcpy. AddMessage ("4. Cut the raster according to the Administrative Region boundary layer") Outextractbymask=Extractbymask (TIF, inbarrierfeature) outextractbymask.save (TIF1) arcpy. AddMessage ("5. Update Mxd"); Mxdpath= MapPath + R"\pointraster1.mxd"; Mxd=arcpy.mapping.MapDocument (Mxdpath);d F= Arcpy.mapping.ListDataFrames (Mxd,"") [0]; forLyrinchArcpy.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. Output image 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. Clean up memory")delMXD, Addlayer,df,outsplinebarriers,inpointfeatures,inbarrierfeature
Python reads National City AQI data, and the difference generates PNG images