-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDB.py
71 lines (62 loc) · 2.41 KB
/
createDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!C:/Python27/ArcGIS10.2/python.exe
#-*- coding:utf-8 -*-
"""
#============================================
#
# Project: mmanagecelery
# Name: The file name is createDB
# Purpose:
# Auther: Administrator
# Tel: 17372796660
#
#============================================
#
"""
import arcpy
import os
import sys
import datetime
reload(sys)
sys.setdefaultencoding('utf8')
def createDB(gdbpath,datatype,ymdhms):
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
authorization_file=os.path.join(SCRIPT_DIR,u"server10.2.ecp")
database_name=datatype+ymdhms
arcpy.AddMessage(database_name)
arcpy.CreateEnterpriseGeodatabase_management(database_platform=u"PostgreSQL", instance_name=u"localhost",
database_name=database_name, account_authentication=u"DATABASE_AUTH",
database_admin=u"postgres", database_admin_password=u"postgres123",
sde_schema=u"SDE_SCHEMA", gdb_admin_name=u"sde",
gdb_admin_password=u"sde", tablespace_name=u"#",
authorization_file=authorization_file)
connsdepath=SCRIPT_DIR
connsde=datatype+ymdhms+u".sde"
arcpy.AddMessage(connsde)
conn = {}
conn[u"out_folder_path"] = connsdepath
conn[u"out_name"] = connsde
conn[u"database_platform"] = u"PostgreSQL"
conn[u"instance"] = u"localhost"
conn[u"account_authentication"] = u"DATABASE_AUTH"
conn[u"database"] = database_name
conn[u"username"] = u"sde"
conn[u"password"] = u"sde"
conn[u"save_user_pass"] = u"SAVE_USERNAME"
arcpy.CreateDatabaseConnection_management(**conn)
arcpy.env.workspace = gdbpath
sdepath=os.path.join(SCRIPT_DIR, connsde)
for ds in arcpy.ListDatasets(feature_type=u'feature') + [u'']:
if ds != u'':
dspath=os.path.join(gdbpath,ds)
sdedspath=os.path.join(sdepath,ds)
arcpy.Copy_management(dspath,sdedspath)
arcpy.AddMessage(dspath)
else:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
fcpath = os.path.join(gdbpath, ds, fc)
sdedspath = os.path.join(sdepath, ds,fc)
arcpy.Copy_management(fcpath, sdedspath)
arcpy.AddMessage(fcpath)
return True
if __name__ == "__main__":
createDB()