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 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 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 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
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] sdePassword = sdeInfos[3] try: sde = AISde(
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] sdePassword = sdeInfos[3] try: sde = AISde(os.path.join(rootPath, 'resources', 'sde'), wksId, sdeServer + '/' + sdeInstance, sdeUsername, sdePassword)
def updateFc(self, fc): ''' 更新要素类 ''' flag = False if isinstance(fc, AIFc): name = fc.getName() nalias = fc.getAlias() #新字段别名集合 nFields = fc.getFields() #新字段集合 nFieldNames = [nfld.getName() for nfld in nFields] #新字段名集合 if not AIUtils.isEmpty(name): if arcpy.Exists(name): ofc = self.queryFc(fc) oalias = ofc.getAlias() # 旧字段别名集合 oFields = ofc.getFields() # 旧字段集合 oFieldNames = [ofld.getName() for ofld in oFields] #旧字段名集合 try: # 更改别名 if not AIUtils.isEmpty(nalias) and not AIStrUtils.isEqual(oalias, nalias): arcpy.AlterAliasName(name, nalias) # 比对字段 # 删除字段(排除保留字段) for ofn in oFieldNames: if ofn not in nFieldNames and \ not AIStrUtils.isEqual(ofn, 'OBJECTID') and \ not AIStrUtils.isEqual(ofn, 'NAME') and \ not AIStrUtils.isEqual(ofn, 'SHAPE') and \ not 'AREA' in ofn and \ not 'LEN' in ofn: arcpy.DeleteField_management(name, ofn) # 添加字段(排除保留字段) for nfn in nFieldNames: if nfn not in oFieldNames: fldName = AIStrUtils.toUpper(nfn) if not AIStrUtils.isEqual(fldName, 'OBJECTID') and \ not AIStrUtils.isEqual(fldName, 'NAME') and \ not AIStrUtils.isEqual(fldName, 'SHAPE') and \ not 'AREA' in fldName and \ not 'LEN' in fldName: # 需要添加的字段 field = None # 查找需要添加的字段 for nfld in nFields: if AIStrUtils.isEqual(nfld.getName(), nfn): field = nfld break # 字段名 fldName = arcpy.ValidateFieldName(fldName, self.__wksName) # 字段别名 fldAlias = field.getAlias() # 字段类型 Integer--LONG Double--DOUBLE String--TEXT Date--DATE fldType = AIStrUtils.toUpper(AIStrUtils.trim(field.getFtype())) fldType = 'LONG' if AIStrUtils.isEqual(fldType, 'INTEGER') else \ 'TEXT' if AIStrUtils.isEqual(fldType, 'STRING') else fldType # 字段小数点位数(浮点型) fldScale = field.getScale() # 字段长度(文本型) fldLength = field.getLength() # 字段是否允许为空 fldIsNullable = field.getIsNullable() arcpy.AddField_management(name, fldName, fldType, None, fldScale, \ fldLength, fldAlias, fldIsNullable, False) 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 addFc(self, fc): ''' 保存要素类 ''' flag = False if isinstance(fc, AIFc): name = fc.getName() ftype = fc.getFtype() alias = fc.getAlias() wkid = fc.getWkid() fds = fc.getFds() if not AIUtils.isEmpty(name) and not AIUtils.isEmpty(ftype): if not arcpy.Exists(name): # 要素集名称 fdsName = None if not AIUtils.isEmpty(fds) and isinstance(fds, AIFds) and not AIUtils.isEmpty(fds.getName()): fdsName = fds.getName() fdsName = fdsName if ('.' in fdsName) else fdsName if AIUtils.isEmpty(self.__userName) else (self.__userName + '.') + fdsName wksName = self.__wksName if AIUtils.isEmpty(fdsName) else os.path.join(self.__wksName, fdsName).replace('\\', '/') fields = fc.getFields() sr = arcpy.SpatialReference(4326) if not AIUtils.isInt(wkid) else arcpy.SpatialReference(wkid) try: # 创建要素类 arcpy.CreateFeatureclass_management(wksName, name, ftype, None, "DISABLED", "DISABLED", sr) # 更改别名 if not AIUtils.isEmpty(alias): arcpy.AlterAliasName(name, alias) # 添加字段(排除保留字段) for field in fields: fldName = AIStrUtils.toUpper(field.getName()) if not AIStrUtils.isEqual(fldName, 'OBJECTID') and \ not AIStrUtils.isEqual(fldName, 'NAME') and \ not AIStrUtils.isEqual(fldName, 'SHAPE') and \ not 'AREA' in fldName and \ not 'LEN' in fldName: # 字段名 fldName = arcpy.ValidateFieldName(fldName, self.__wksName) # 字段别名 fldAlias = field.getAlias() # 字段类型 Integer--LONG Double--DOUBLE String--TEXT Date--DATE fldType = 'TEXT' if AIStrUtils.isEqual(AIStrUtils.toUpper(field.getFtype()), 'STRING') else field.getFtype() # 字段小数点位数(浮点型) fldScale = field.getScale() # 字段长度(文本型) fldLength = field.getLength() # 字段是否允许为空 fldIsNullable = field.getIsNullable() arcpy.AddField_management(name, fldName, fldType, None, fldScale, \ fldLength, fldAlias, fldIsNullable, False) flag = True except: raise else: raise Exception('featureclass name cannot be duplicated!') else: raise Exception('featureclass name and geometry type cannot be empty!') else: raise Exception('input parameter type not correct!') return flag
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.addFc') 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] sdePassword = sdeInfos[3] # 默认文件已经存在 sdeOutFullName = os.path.join(rootPath, 'resources', 'sde', wksId + ".sde").replace('\\', '/')
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.updateFc') 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] sdePassword = sdeInfos[3] # 默认文件已经存在 sdeOutFullName = os.path.join(rootPath, 'resources', 'sde', wksId + ".sde").replace('\\', '/')