数据库的点数据根据行政区shp来进行行政区处理,python定时器实现
# -*- 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定时器实现的更多相关文章
- [转载] SQL获取所有数据库名、表名、储存过程以及参数列表
查询一个数据库中所有表字段属性的sql语句 1.获取所有用户名: SELECT name FROM Sysusers where status='2' and islogin='1' is ...
- SQL获取所有数据库名、表名、储存过程以及参数列表
SQL获取所有数据库名.表名.储存过程以及参数列表 1.获取所有用户名:SELECT name FROM Sysusers where status='2' and islogin='1'islogi ...
- 读数据库所有表和表结构的sql语句
SQL获取所有数据库名.表名.储存过程以及参数列表 1.获取所有用户名:SELECT name FROM Sysusers where status='2' and islogin='1'islogi ...
- Web中树形数据(层级关系数据)的实现—以行政区树为例
在Web开发中常常遇到树形数据的操作,如菜单.组织机构.行政区(省.市.县)等具有层级关系的数据. 以下以行政区为例说明树形数据(层级关系数据)的存储以及实现,效果如图所看到的. 1 数据库表结构设计 ...
- Cesium之3D拉伸显示行政区
转自原文 Cesium之3D拉伸显示行政区含GeoJSON数据生成过程GDAL的ogr2ogr Cesiumjs 是一套javascript库,用来渲染3D地球,2D区域地图,和多种GIS要素.不需要 ...
- Python操作Mysql数据库时SQL语句的格式问题
一.概述 近日使用Python对Mysql数据库进行操作,遇到SQL语句死活出问题的情况.由于最初没有将异常打印出来,一直不知道原因.随后,将异常打印出来之后,通过异常信息,对代码进行修改.最终,成功 ...
- Python爬虫爬取豆瓣电影名称和链接,分别存入txt,excel和数据库
前提条件是python操作excel和数据库的环境配置是完整的,这个需要在python中安装导入相关依赖包: 实现的具体代码如下: #!/usr/bin/python# -*- coding: utf ...
- AMap行政区查询服务
AMap.DistrictSearch行政区查询服务插件,提供全国各省.市.县.区的中心点经纬度.行政区边界坐标组.下级行政区等信息.根据行政区边界坐标组可在地图上绘制行政区边界.(本文为原创,并在项 ...
- python3.4怎么连接mysql pymysql连接mysql数据库
本文介绍了python3 4连接mysql数据库的方法,在python3 4中使用原来python2 7的mysqldb已不能连接mysql数据库了,可以使用pymysql. 在python3.4 ...
随机推荐
- android开发期间使用真机调试但系统无法识别出真机
前言 前些天重装了系统,好不容易把所有的软件装好,结果发现打开android studio真机调试却出了问题. 一.症状: 1.手机端设置完全没问题(打开了调试模式......) 2.电脑端右下角不出 ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...
- C# @符号的作用, 可定义关键字为变量名
一 字符串中的用法字符@表示,其后的字符串是个“逐字字符串”(verbatim string).@只能对字符串常量作用.1.用于文件路径以下是引用片段:string s_FilePath =" ...
- CCLabelAtlas
1.CCLabelAtlas 的具体用法 CCLabelAtlas *pLabel = new CCLabelAtlas;pLabel ->initWithString("0123&q ...
- 20145337《JAVA程序设计》第七周学习总结
20145337 <Java程序设计>第七周学习总结 教材学习内容总结 时间的度量 格林威治时间GMT,世界时UT,国际原子时TAI,世界协调时间UTC 就目前来说,即使标注为GMT,实际 ...
- Xcode 添加类前缀
按照如下图所示操作后,接下来创建的类就会带有MN的前缀;如果想更换前缀,则替换MN即可!
- js官网判断是否手机跳转到手机页面
<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="te ...
- 使用JAXP对XML文档进行DOM解析
import java.io.FileOutputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers. ...
- Oracle-01033错误处理
今天电脑非常卡,强制重启后,发现oracle 11g启动不了了,提示错误: ERROR - ORA-01033 oracle initialization or shutdown in progres ...
- cucumber learning : http://www.cnblogs.com/puresoul/category/340832.html
link Generate cucumber report by json website Sample as json file for cucumber report: [ { "key ...