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) sde.connect() except Exception as e: logger.info(unicode(e.message).encode("utf-8")) logger.info('数据库服务器' + sdeServer + '上空间数据库' + sdeInstance + '实例连接失败') logger.info('数据库服务器' + sdeServer + '上空间数据库' + sdeInstance + '实例连接成功') wks = AIWks(sde.getSdeOutFullName(), sde.getSdeUserName()) logger.info('工作空间' + sde.getSdeOutFullName() + '初始化成功') # 查询要素集 param2 = sys.argv[2] param2 = param2.replace('null', '\'\'') # fdsDict = AIUtils.str2dict(param2) # name = fdsDict['name'] fds = AIFds() fds = fds.fromStr(param2) try:
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, ) sde.connect() except Exception as e: logger.info(unicode(e.message).encode("utf-8")) logger.info("数据库服务器" + sdeServer + "上空间数据库" + sdeInstance + "实例连接失败") logger.info("数据库服务器" + sdeServer + "上空间数据库" + sdeInstance + "实例连接成功") wks = AIWks(sde.getSdeOutFullName(), sde.getSdeUserName()) logger.info("工作空间" + sde.getSdeOutFullName() + "初始化成功") # 查询要素集 param2 = sys.argv[2] param2 = param2.replace("null", "''") fds = AIFds() fds = fds.fromStr(param2)
fld = AIFld(AIUtils.unicode2utf8(field.name), AIUtils.unicode2utf8(field.aliasName), \ AIUtils.unicode2utf8(field.type), field.scale, \ field.length, field.isNullable) flds.append(fld) qrs.append(AIFc(AIUtils.unicode2utf8(desc.name), AIUtils.unicode2utf8(desc.aliasName), \ AIUtils.unicode2utf8(desc.shapeType), None if AIUtils.isEmpty(desc.spatialReference) else desc.spatialReference.factoryCode, \ fds, flds)) else: raise Exception('input parameter type not correct!') return qrs if __name__ == '__main__': try: sde = AISde('D:\\tmp\\sde', 'orcl21', '192.168.0.21/arcgis', 'gis', 'gis123') sdeOutFullName = sde.connect() print sdeOutFullName if not AIUtils.isEmpty(sdeOutFullName): wks = AIWks(sdeOutFullName, 'gis') # # query fds # qr = wks.queryFds(AIFds('gis.test')) # print qr # # add fds # flag = wks.addFds(AIFds('test334', 3857)) # print flag # # delete fds # flag = wks.removeFds(AIFds('test334', 3857)) # print flag