数据库的点数据根据行政区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 ...
随机推荐
- Java中的super与this解析
好了,现在开始讨论this&super这两个关键字的意义和用法. 在Java中,this通常指当前对象,super则指父类的.当你想要引用当前对象的某种东西,比如当前对象的某个方法,或当前对象 ...
- java 反取字符串
public class demo2 { /** * 2 : 将字符串反取出来 新中国好 好国中新 */ public static void main(String[] args) { String ...
- ThinkPHP的URL优化
在刚刚安装好tp框架时,我们的路径一般是这样的: http://localhost/index.php/Home/Index/index?name=cly 我们可以通过下面一步步的步骤来优化这个路径 ...
- SQL server while语句、存储过程
1.循环语句 2.存储过程 存储过程(stored procedure)有时也称为sproc.存储过程存储于数据库中而不是在单独的文件中,有输入参数.输出参数以及返回值等. 3.四种存储过程类型(类似 ...
- C# 截取字符串
1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...
- centos MariaDB10.1.X galera cluster
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1.12/centos6-amd64 gpgkey=https://yum.m ...
- WS调用的时候报错
报错内容javax.xml.ws.WebServiceException: Method recognizeIdentityCardByFilePath is exposed as WebMethod ...
- Web前端开发基础 第二天(各类标签)
认识标签(第二部分): <ul> <li>信息</li> <li>信息</li> ...... </ul> <ol> ...
- Jquery的命名冲突
$是Jquery的别名,为了编码方便,我们可以使用$符号来调用Jquery的函数.然而,当我们引入多个JS库的时候,如果另外一个库中也引用了$符号作为别名的话,那么我们在使用$符号的时候,由于同一个作 ...
- unity assert server 与 cache server
Asset server 其实就是unity提供的版本控制工具,不过我们都转到P4V了,上午尝试了一下,如果小团队使用还是不错的,使用过程大致如下,具体的还是要大伙去官网看喽 服务器安装文件下载: h ...