# -*- coding: utf-8 -*-
import struct
import decimal
import itertools
import arcpy
import math
import sys
import datetime
import cx_Oracle
import json
import os
import time
import uuid
import logging
from arcpy import env
from arcpy.sa import * #参数:文件路径,字段序列,字段类型序列,数据记录序列
def dbfwriter(f, fieldnames, fieldspecs, records):
""" Return a string suitable for writing directly to a binary dbf file. File f should be open for writing in a binary mode. Fieldnames should be no longer than ten characters and not include \x00.
Fieldspecs are in the form (type, size, deci) where
type is one of:
C for ascii character data
M for ascii character memo data (real memo fields not supported)
D for datetime objects
N for ints or decimal objects
L for logical values 'T', 'F', or '?'
size is the field width
deci is the number of decimal places in the provided decimal object
Records can be an iterable over the records (sequences of field values). """
# header info
ver = 3
now = datetime.datetime.now()
yr, mon, day = now.year - 1900, now.month, now.day
numrec = len(records)
numfields = len(fieldspecs)
lenheader = numfields * 32 + 33
lenrecord = sum(field[1] for field in fieldspecs) + 1
hdr = struct.pack('<BBBBLHH20x', ver, yr, mon, day, numrec, lenheader, lenrecord)
f.write(hdr) # field specs
for name, (typ, size, deci) in itertools.izip(fieldnames, fieldspecs):
name = name.ljust(11, '\x00')
fld = struct.pack('<11sc4xBB14x', name, typ, size, deci)
f.write(fld) # terminator
f.write('\r') # records
for record in records:
f.write(' ') # deletion flag
for (typ, size, deci), value in itertools.izip(fieldspecs, record):
if typ == "N":
value = str(value).rjust(size, ' ')
elif typ == 'D':
value = value.strftime('%Y%m%d')
elif typ == 'L':
value = str(value)[0].upper()
else:
value = str(value)[:size].ljust(size, ' ')
assert len(value) == size
f.write(value) # End of file
f.write('\x1A')
##################################################################### LOG_FILENAME="E:\update\log.txt";
t = datetime.datetime.now();
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG);
logging.debug(str(t)+"闪电数据处理开始:"); #修改默认系统编码格式,让系统支持中文
reload(sys);
#print sys.getdefaultencoding();
sys.setdefaultencoding('utf8'); env.workspace = r"e:\update";
logging.debug("1、从数据库查询数据,然后保存到dbtable.dbf中(计算值工具不能用于python编辑)");
cnxn = cx_Oracle.connect('ycybyj/ycybyj@127.0.0.1:1521/orcl');
cursor0 = cnxn.cursor();
#查询出字段用ID,SHI1,XIAN1 分析完后字段用SHI,XIAN,SHENG
querySql="select ID,LONGITUDE,LATITUDE,SHI SHI1,XIAN XIAN1 from lightning where sheng is not null and rownum<=100";
cursor0.execute(querySql);
records=[];
for item in cursor0:
records.append(item); #生成dbtable之前,需要先把现有的dbtable.dbf删除
filename ='e:/update/shp/dbtable.dbf'
if arcpy.Exists(filename):
try:
arcpy.Delete_management(filename, "")
except:
arcpy.AddError("无法删除dbtable.dbf:" + filename)
f = open(filename, 'wb+')
fieldnames=['ID','LONGITUDE','LATITUDE','SHI1','XIAN1'];
fieldspecs=[('N',10,0),('N',10,4),('N',10,4),('C',50,0),('C',50,0)];
dbfwriter(f, fieldnames, fieldspecs, records)
f.close() logging.debug("2、利用XY事件图层工具,把数据库表转换成要素类");
arcpy.MakeXYEventLayer_management(filename, "LONGITUDE", "LATITUDE", "out_layer");
nums=arcpy.GetCount_management("out_Layer");
logging.debug("2.1、 该次处理的数据行数是:"+str(nums)); logging.debug("3、利用空间链接工具,获取到闪电的行政区");
joinfc=r"e:\update\shp\xian.shp";
outfc=r"e:\update\shp\out.shp";
#生成out.shp之前,需要先把现有的out.shp删除
if arcpy.Exists(outfc):
try:
arcpy.Delete_management(outfc, "")
except:
arcpy.AddError("无法删除out.shp:" + outfc)
arcpy.SpatialJoin_analysis("out_layer", joinfc, outfc); logging.debug("4、将结果shp里的信息更新到数据库,唯一标识用ID");
cursor = cnxn.cursor();
cursor1 = arcpy.SearchCursor(outfc)
for row in cursor1:
ids=row.getValue("ID");
ids=int(ids);
xian=row.getValue("XIAN");
shi=row.getValue("SHI");
sheng=row.getValue("SHENG");
if sheng==' ':
sheng='非安徽省';
updatesql="update lightning set sheng='"+sheng+"', xian='"+xian+"',shi='"+shi+"' where id="+str(ids);
cursor.execute(updatesql);
cnxn.commit(); #删除不在行政区边界内的闪电点位
delSql="delete from lightning where sheng='非安徽省'";
cursor.execute(updatesql);
cnxn.commit(); #关闭系统资源
cursor0.close;
cursor.close;
cnxn.close; tt = datetime.datetime.now();
logging.debug(str(tt)+"闪电数据处理结束.");

数据库的点数据根据行政区shp来进行行政区处理,python定时器实现的更多相关文章

  1. [转载] SQL获取所有数据库名、表名、储存过程以及参数列表

    查询一个数据库中所有表字段属性的sql语句       1.获取所有用户名: SELECT name FROM Sysusers where status='2' and islogin='1' is ...

  2. SQL获取所有数据库名、表名、储存过程以及参数列表

    SQL获取所有数据库名.表名.储存过程以及参数列表 1.获取所有用户名:SELECT name FROM Sysusers where status='2' and islogin='1'islogi ...

  3. 读数据库所有表和表结构的sql语句

    SQL获取所有数据库名.表名.储存过程以及参数列表 1.获取所有用户名:SELECT name FROM Sysusers where status='2' and islogin='1'islogi ...

  4. Web中树形数据(层级关系数据)的实现—以行政区树为例

    在Web开发中常常遇到树形数据的操作,如菜单.组织机构.行政区(省.市.县)等具有层级关系的数据. 以下以行政区为例说明树形数据(层级关系数据)的存储以及实现,效果如图所看到的. 1 数据库表结构设计 ...

  5. Cesium之3D拉伸显示行政区

    转自原文 Cesium之3D拉伸显示行政区含GeoJSON数据生成过程GDAL的ogr2ogr Cesiumjs 是一套javascript库,用来渲染3D地球,2D区域地图,和多种GIS要素.不需要 ...

  6. Python操作Mysql数据库时SQL语句的格式问题

    一.概述 近日使用Python对Mysql数据库进行操作,遇到SQL语句死活出问题的情况.由于最初没有将异常打印出来,一直不知道原因.随后,将异常打印出来之后,通过异常信息,对代码进行修改.最终,成功 ...

  7. Python爬虫爬取豆瓣电影名称和链接,分别存入txt,excel和数据库

    前提条件是python操作excel和数据库的环境配置是完整的,这个需要在python中安装导入相关依赖包: 实现的具体代码如下: #!/usr/bin/python# -*- coding: utf ...

  8. AMap行政区查询服务

    AMap.DistrictSearch行政区查询服务插件,提供全国各省.市.县.区的中心点经纬度.行政区边界坐标组.下级行政区等信息.根据行政区边界坐标组可在地图上绘制行政区边界.(本文为原创,并在项 ...

  9. python3.4怎么连接mysql pymysql连接mysql数据库

    本文介绍了python3 4连接mysql数据库的方法,在python3 4中使用原来python2 7的mysqldb已不能连接mysql数据库了,可以使用pymysql.   在python3.4 ...

随机推荐

  1. [CareerCup] 18.11 Maximum Subsquare 最大子方形

    18.11 Imagine you have a square matrix, where each cell (pixel) is either black or white. Design an ...

  2. Hadoop.2.x_高级应用_二次排序及MapReduce端join

    一.对于二次排序案例部分理解 1. 分析需求(首先对第一个字段排序,然后在对第二个字段排序) 杂乱的原始数据 排序完成的数据 a,1 a,1 b,1 a,2 a,2 [排序] a,100 b,6 == ...

  3. 教你彻底解决css中设置z-index的值无效的问题

    在使用z-index这个属性之前,我们必须先了解使用z-index的必要条件: 1.要想给元素设置z-index样式,必须先让它变成定位元素,说的明白一点,就是要给元素设置一个postion:rela ...

  4. select的5中子句where,group by, havaing, order by, limit的使用顺序及实例

    -- 语法: SELECT select_list FROM table_name [ WHERE search_condition ] [ GROUP BY group_by_expression ...

  5. 20145337实验三实验报告——敏捷开发与XP实践

    20145337实验三实验报告--敏捷开发与XP实践 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 ** 实验步骤**### 敏捷开发与XP 软件工程包括下列领域:软件需求 ...

  6. el 表达式 和 ognl表达式

    el (expression language) el 基础操作符 el 能够隐含对象(就是可以直接访问的) el 的两种使用方式,第二种好像在jsp中没有什么用,主要用于jsf el能够访问的对象( ...

  7. 【iCore3 双核心板】例程三十三:SD_IAP_ARM实验——更新升级STM32

    实验指导书及代码包下载: http://pan.baidu.com/s/1jHmvQfk iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  8. MySQL 启动时禁用了 InnoDB 引擎的解决方法

    今天在从本地数据库复制表数据到虚拟机 CentOS 6.6 上的数据库时,得到提示: Unknown table engine 'InnoDB' 于是在服务器 MySQL 中查看了引擎: mysql& ...

  9. 给RecyclerView实现的GridView加上HeaderView和FooterView

    给RecyclerView设置布局管理器 GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); 写适配器,添加子项 ...

  10. phpqrcode不能输出二维码

    phpqrcode不能输出二维码  注意 权限.....  注意 扩展 header('Content-Type: image/png'); include_once 'phpqrcode/qrlib ...