Ejemplo n.º 1
0
 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") 
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def __init__(self, wksName, userName = None):
     '''
     构造器
     '''
     if not AIUtils.isEmpty(wksName):
         arcpy.env.workspace = self.__wksName = wksName.replace('\\', '/')
         self.__userName = userName
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
 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
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
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]
Ejemplo n.º 20
0
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]
Ejemplo n.º 21
0
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]
Ejemplo n.º 22
0
 def __init__(self, name = None, wkid = 4326):
     '''
     构造器
     '''
     self.__name = name
     self.__wkid = 4326 if AIUtils.isEmpty(wkid) else wkid
Ejemplo n.º 23
0
 def setMaxScale(self, maxScale):
     self.__maxScale = 0 if AIUtils.isEmpty(maxScale) else maxScale
Ejemplo n.º 24
0
 def setMinScale(self, minScale):
     self.__minScale = 0 if AIUtils.isEmpty(minScale) else minScale
Ejemplo n.º 25
0
 def setWkid(self, wkid):
     self.__wkid = 4326 if AIUtils.isEmpty(wkid) else wkid
Ejemplo n.º 26
0
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]
Ejemplo n.º 27
0
 def setTransparency(self, transparency):
     self.__transparency = 0 if AIUtils.isEmpty(transparency) else transparency
Ejemplo n.º 28
0
 def setVisible(self, visible):
     self.__visible = True if AIUtils.isEmpty(visible) else visible
Ejemplo n.º 29
0
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]
Ejemplo n.º 30
0
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]