def __init__(self, agsOutFolder, agsOutName, tmpOutFolder, \ serverName, serverPort, username, password): ''' 构造器 ''' if not AIUtils.isEmpty(agsOutFolder) and not AIUtils.isEmpty(agsOutName) and not AIUtils.isEmpty(tmpOutFolder): self.__agsOutFolder = agsOutFolder self.__agsOutName = agsOutName self.__tmpOutFolder = tmpOutFolder if not self.__agsOutName.endswith('.ags'): self.__agsOutName += '.ags' server_url_part = self.__serverUrlPre = 'http://' + serverName + ':' + serverPort + '/arcgis' server_url = server_url_part + '/admin' use_arcgis_desktop_staging_folder = False staging_folder_path = self.__agsOutFolder self.__agsOutFolder = self.__agsOutFolder.replace('\\', '/') self.__agsOutFullName = os.path.join(self.__agsOutFolder, self.__agsOutName).replace('\\', '/') if not os.path.exists(self.__agsOutFullName): arcpy.mapping.CreateGISServerConnectionFile("PUBLISH_GIS_SERVICES", self.__agsOutFolder, self.__agsOutName, server_url, "ARCGIS_SERVER", use_arcgis_desktop_staging_folder, staging_folder_path, username, password, "SAVE_USERNAME")
def __init__(self, name=None, minScale=0, maxScale=0, transparency=0, visible=True): """ 构造器 """ self.__name = name self.__minScale = 0 if AIUtils.isEmpty(minScale) else minScale self.__maxScale = 0 if AIUtils.isEmpty(maxScale) else maxScale self.__transparency = 0 if AIUtils.isEmpty(transparency) else transparency self.__visible = True if AIUtils.isEmpty(visible) else visible
def __init__(self, name = None, alias = None, ftype = None, wkid = 4326, fds = None, fields = []): ''' 构造器 ''' self.__name = name self.__alias = alias self.__ftype = ftype self.__wkid = 4326 if AIUtils.isEmpty(wkid) else wkid self.__fds = None if AIUtils.isEmpty(fds) else fds self.__fields = [] if AIUtils.isEmpty(fields) else fields
def __init__(self, name = None, alias = None, ftype = None, scale = 0, length = 0, isNullable = True): ''' 构造器 ''' self.__name = name self.__alias = alias self.__ftype = ftype self.__scale = 0 if AIUtils.isEmpty(scale) else scale self.__length = 0 if AIUtils.isEmpty(length) else length self.__isNullable = True if AIUtils.isEmpty(isNullable) else isNullable
def setFields(self, fields): nflds = [] if not AIUtils.isEmpty(fields) and AIUtils.isList(fields): for fld in fields: nfld = AIFld() for key in fld: func = getattr(nfld, 'set' + AIStrUtils.toUpperF(key)) if AIUtils.isFunc(func): apply(func, [fld[key]]) nflds.append(nfld) self.__fields = nflds
def fromStr(self, attrs): obj = None if AIUtils.isStr(attrs): attrs = AIUtils.str2dict(attrs) obj = self if AIUtils.isDict(attrs): for key in attrs: func = getattr(obj, 'set' + AIStrUtils.toUpperF(key)) if AIUtils.isFunc(func): apply(func, [attrs[key]]) else: raise Exception('input parameter type not correct!') return obj
def __init__(self, wksName, userName = None): ''' 构造器 ''' if not AIUtils.isEmpty(wksName): arcpy.env.workspace = self.__wksName = wksName.replace('\\', '/') self.__userName = userName
def setFds(self, fds): nfds = AIFds() for key in fds: func = getattr(nfds, 'set' + AIStrUtils.toUpperF(key)) if AIUtils.isFunc(func): apply(func, [fds[key]]) self.__fds = nfds
def queryFdsList(self, fds): ''' 查询要素集列表 ''' qrs = [] if isinstance(fds, AIFds): name = fds.getName() datasets = arcpy.ListDatasets(None if AIUtils.isEmpty(name) else ('*'+ name + '*'), \ 'Feature') for dataset in datasets: desc = arcpy.Describe(dataset) sr = desc.spatialReference qrs.append(AIFds(AIUtils.unicode2utf8(desc.name), None if AIUtils.isEmpty(sr) else sr.factoryCode)) else: raise Exception('input parameter type not correct!') return qrs
def execute(self, sql): ''' 执行sql语句 ''' sde_conn = None sde_return = None try: sde_conn = None if AIUtils.isEmpty(self.__sdeOutFullName) else arcpy.ArcSDESQLExecute(self.__sdeOutFullName) if not AIUtils.isEmpty(sde_conn): try: sde_return = sde_conn.execute(sql) except: raise except: raise finally: del sde_conn return sde_return
def publish(self, svc): ''' 发布服务 ''' if not AIUtils.isEmpty(self.__agsOutFullName) and isinstance(svc, AISvc): mxdFullName = svc.getMxdFullName() serviceName = svc.getServiceName() serviceFolder = svc.getServiceFolder() description = svc.getDescription() serviceItems = svc.getServiceItems() try: # 生成服务草稿文件 sddraftFullName = os.path.join(self.__tmpOutFolder, serviceName + '.sddraft') sdFullName = os.path.join(self.__tmpOutFolder, serviceName + '.sd') mapDoc = arcpy.mapping.MapDocument(mxdFullName) arcpy.mapping.CreateMapSDDraft(mapDoc, sddraftFullName, serviceName, 'ARCGIS_SERVER', self.__agsFullName, False, serviceFolder) sDDraftEditor = AISEdit(sddraftFullName) # 添加服务描述 sDDraftEditor.setItemInfo({'description' : description}) # 添加额外服务能力 for item in serviceItems: if item.getEnabled(): sDDraftEditor.setSvcExtension(item.getTypeName(), 'true') analysis = arcpy.mapping.AnalyzeForSD(sddraftFullName) if analysis['errors'] == {}: # 过度服务草稿文件到SD文件 arcpy.StageService_server(sddraftFullName, sdFullName) # 上传SD文件到GIS服务器 arcpy.UploadServiceDefinition_server(sdFullName, self.__agsServer) # 发布成功存入服务地址 for item in serviceItems: if item.getEnabled(): typeName = item.getTypeName() if AIStrUtils.isEqual(typeName, 'MapServer'): svc.setUrl(self.__serverUrlPre + sDDraftEditor.getMapServerPartRestUrl()) elif AIStrUtils.isEqual(typeName, 'KmlServer'): svc.setUrl(self.__serverUrlPre + sDDraftEditor.getKmlRestUrl()) elif AIStrUtils.isEqual(typeName, 'FeatureServer'): svc.setUrl(self.__serverUrlPre + sDDraftEditor.getFeatureRestUrl()) elif AIStrUtils.isEqual(typeName, 'WFSServer'): svc.setUrl(self.__serverUrlPre + sDDraftEditor.getWMSRestUrl()) else: svc.setUrl(self.__serverUrlPre + sDDraftEditor.getWFSRestUrl()) else: raise except: raise return svc
def queryFds(self, fds): ''' 查询要素集 ''' qr = None if isinstance(fds, AIFds): name = fds.getName() if not AIUtils.isEmpty(name): name = name if ('.' in name) else name if AIUtils.isEmpty(self.__userName) else (self.__userName + '.') + name datasets = arcpy.ListDatasets(name, 'Feature') if len(datasets) > 0 and not AIUtils.isEmpty(datasets[0]): dataset = datasets[0] desc = arcpy.Describe(dataset) sr = desc.spatialReference qr = AIFds(AIUtils.unicode2utf8(desc.name), None if AIUtils.isEmpty(sr) else sr.factoryCode) else: raise Exception('dataset name cannot be empty!') else: raise Exception('input parameter type not correct!') return qr
def __init__(self, sdeOutFolder, sdeOutName, instance, username, password, \ databasePlatform = 'ORACLE', accountAuthentication='DATABASE_AUTH'): ''' 构造器 ''' if not AIUtils.isEmpty(sdeOutFolder) and not AIUtils.isEmpty(sdeOutName): self.__sdeOutFolder = sdeOutFolder self.__sdeOutName = sdeOutName if not self.__sdeOutName.endswith('.sde'): self.__sdeOutName += '.sde' self.__sdeOutFolder = self.__sdeOutFolder.replace('\\', '/') self.__sdeOutFullName = os.path.join(self.__sdeOutFolder, self.__sdeOutName).replace('\\', '/') self.__sdeUserName = username if not os.path.exists(self.__sdeOutFullName): arcpy.CreateDatabaseConnection_management(self.__sdeOutFolder, self.__sdeOutName, databasePlatform, instance, accountAuthentication, username, password)
def addFds(self, fds): ''' 保存要素集 ''' flag = False if isinstance(fds, AIFds): name = fds.getName() if not AIUtils.isEmpty(name): if not arcpy.Exists(name): wkid = fds.getWkid() sr = 4326 if not AIUtils.isInt(wkid) else arcpy.SpatialReference(wkid) try: arcpy.CreateFeatureDataset_management(self.__wksName, name, sr) flag = True except: raise else: raise Exception('dataset name cannot be duplicated!') else: raise Exception('dataset name cannot be empty!') else: raise Exception('input parameter type not correct!') return flag
def connect(self): ''' 尝试连接数据库, 成功返回sde全路径 ''' connResult = None if not AIUtils.isEmpty(self.__sdeOutFullName): try: # sde_return = self.execute('select 1 from dual') # if not AIUtils.isEmpty(sde_return): # connResult = self.__sdeOutFullName connResult = self.__sdeOutFullName except: raise # except Exception as e: # print 'failure, connect error' # print unicode(e.message).encode("utf-8") return connResult
def toStr(self, obj): result = None if not AIUtils.isEmpty(obj): attrs = dir(obj) result = [] for attr in attrs: if attr.startswith('get'): prop = AIStrUtils.toLowerF(attr[3:]) func = getattr(obj, attr) value = apply(func, []) # 判断类型,不同的字符串转换方式 propValue = AIUtils.list2str(value) if AIUtils.isList(value) \ else AIUtils.dict2str(value) if AIUtils.isDict(value) \ else ('\'' + AIUtils.toStr(value) + '\'') if AIUtils.isStr(value) \ else AIUtils.toStr(value) result.append('\'' + prop + '\':' + propValue + '') result = '{' + ','.join(result) + '}' else: raise Exception('input parameter type not correct!') return result
def removeFc(self, fc): ''' 删除要素类 ''' flag = False if isinstance(fc, AIFc): name = fc.getName() if not AIUtils.isEmpty(name): if arcpy.Exists(name): try: arcpy.Delete_management(name) flag = True except: raise else: raise Exception('featureclass not exist!') else: raise Exception('featureclass name cannot be empty!') else: raise Exception('input parameter type not correct!') return flag
def removeFds(self, fds): ''' 删除要素集 ''' flag = False if isinstance(fds, AIFds): name = fds.getName() if not AIUtils.isEmpty(name): if arcpy.Exists(name): try: arcpy.Delete_management(name) flag = True except: raise else: raise Exception('dataset not exist!') else: raise Exception('dataset name cannot be empty!') else: raise Exception('input parameter type not correct!') return flag
if __name__ == "__main__": flag = "false" # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, "resources", "conf", "logging.conf")) logger = logging.getLogger("app.scripts.addFds") logger.info("读取Python服务端日志配置成功") # 获取参数 param1 = sys.argv[1] param1 = param1.replace("null", "''") wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict["id"] wksType = wksDict["type"] if AIStrUtils.isEqual(wksType, "sde"): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, "resources", "conf", "config.conf")) # 获取sde连接文件 sdeIds = cf.options("sde") if wksId in sdeIds: sdeInfo = cf.get("sde", wksId) sdeInfos = sdeInfo.split("/") sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]
from arccore.store.AIWks import AIWks if __name__ == '__main__': qr = '' # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, 'resources', 'conf', 'logging.conf')) logger = logging.getLogger('app.scripts.queryFds') logger.info('读取Python服务端日志配置成功') # 获取参数 param1 = sys.argv[1] param1 = param1.replace('null', '\'\'') wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict['id'] wksType = wksDict['type'] if AIStrUtils.isEqual(wksType, 'sde'): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, 'resources', 'conf', 'config.conf')) # 获取sde连接文件 sdeIds = cf.options('sde') if wksId in sdeIds: sdeInfo = cf.get('sde', wksId) sdeInfos = sdeInfo.split('/') sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]
from arccore.utils.AIStrUtils import AIStrUtils if __name__ == '__main__': flag = 'false' # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, 'resources', 'conf', 'logging.conf')) logger = logging.getLogger('app.scripts.removeFds') logger.info('读取Python服务端日志配置成功') # 获取参数 param1 = sys.argv[1] param1 = param1.replace('null', '\'\'') wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict['id'] wksType = wksDict['type'] if AIStrUtils.isEqual(wksType, 'sde'): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, 'resources', 'conf', 'config.conf')) # 获取sde连接文件 sdeIds = cf.options('sde') if wksId in sdeIds: sdeInfo = cf.get('sde', wksId) sdeInfos = sdeInfo.split('/') sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]
def __init__(self, name = None, wkid = 4326): ''' 构造器 ''' self.__name = name self.__wkid = 4326 if AIUtils.isEmpty(wkid) else wkid
def setMaxScale(self, maxScale): self.__maxScale = 0 if AIUtils.isEmpty(maxScale) else maxScale
def setMinScale(self, minScale): self.__minScale = 0 if AIUtils.isEmpty(minScale) else minScale
def setWkid(self, wkid): self.__wkid = 4326 if AIUtils.isEmpty(wkid) else wkid
if __name__ == "__main__": qr = "" # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, "resources", "conf", "logging.conf")) logger = logging.getLogger("app.scripts.queryFdsList") logger.info("读取Python服务端日志配置成功") # 获取参数 param1 = sys.argv[1] param1 = param1.replace("null", "''") wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict["id"] wksType = wksDict["type"] if AIStrUtils.isEqual(wksType, "sde"): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, "resources", "conf", "config.conf")) # 获取sde连接文件 sdeIds = cf.options("sde") if wksId in sdeIds: sdeInfo = cf.get("sde", wksId) sdeInfos = sdeInfo.split("/") sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]
def setTransparency(self, transparency): self.__transparency = 0 if AIUtils.isEmpty(transparency) else transparency
def setVisible(self, visible): self.__visible = True if AIUtils.isEmpty(visible) else visible
from arccore.store.AIWks import AIWks if __name__ == '__main__': flag = 'false' # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, 'resources', 'conf', 'logging.conf')) logger = logging.getLogger('app.scripts.removeFc') logger.info('读取Python服务端日志配置成功') # 获取参数 param1 = sys.argv[1] param1 = param1.replace('null', '\'\'') wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict['id'] wksType = wksDict['type'] if AIStrUtils.isEqual(wksType, 'sde'): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, 'resources', 'conf', 'config.conf')) # 获取sde连接文件 sdeIds = cf.options('sde') if wksId in sdeIds: sdeInfo = cf.get('sde', wksId) sdeInfos = sdeInfo.split('/') sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]
from arccore.utils.AIStrUtils import AIStrUtils if __name__ == '__main__': qr = '' # 获取python服务端根目录 path = sys.argv[0] if os.path.isfile(path): path = os.path.dirname(path) rootPath = os.path.abspath(os.path.join(path, os.pardir)) # 读取日志配置 logging.config.fileConfig(os.path.join(rootPath, 'resources', 'conf', 'logging.conf')) logger = logging.getLogger('app.scripts.queryFc') logger.info('读取Python服务端日志配置成功') # 获取参数 param1 = sys.argv[1] param1 = param1.replace('null', '\'\'') wksDict = AIUtils.str2dict(param1) # 设置工作空间 wksId = wksDict['id'] wksType = wksDict['type'] if AIStrUtils.isEqual(wksType, 'sde'): # 建立相关连接 cf = ConfigParser.ConfigParser() cf.read(os.path.join(rootPath, 'resources', 'conf', 'config.conf')) # 获取sde连接文件 sdeIds = cf.options('sde') if wksId in sdeIds: sdeInfo = cf.get('sde', wksId) sdeInfos = sdeInfo.split('/') sdeServer = sdeInfos[0] sdeInstance = sdeInfos[1] sdeUsername = sdeInfos[2]