arcpy将shp属性表导入到数据库,sqlserver

由于表记录太长,导出到txt会出现乱码,无法用工具导入,且记录会莫名其妙的减少,shp导入postgis也会出问题

因此写代码来导入吧...

# encoding: utf-8
import pymssql
import arcpy
import os
from arcpy import env
import numpy as np
import pandas as pd
server='localhost'
user='userb'
password='123456'
database='master'
print 'lianjie'
day=18
outGDB=r"E:\day11"+str(day)+".gdb"

conn = pymssql.connect(server, user, password, database)
cursor = conn.cursor()
day=30
while(day>23):
    ls=[]
    print day
    resultGDB = r'E:\result11' + str(day) + '.gdb'
    env.workspace =resultGDB
    count=0
    with arcpy.da.SearchCursor(resultGDB + "\\" + "merge", ["vehicleNum","ID"]) as cursor2:
        for inRow2 in cursor2:
            count+=1
            print count
            ls.append([inRow2[0],inRow2[1]])
            #break
    #ls=pd.DataFrame(ls)
    #ls=np.array(ls)
    #print "导入"
    count=0
    for item in ls:
        count+=1
        print "导入",count
        cursor.execute("insert into ppPeoAll30(vehicleNum,ID)  values(%s,%s)", (item[0],item[1]))
        conn.commit()

你可能感兴趣的:(arcpy)