Example #1
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
Example #2
0
    字符串转小写
    '''
    @staticmethod 
    def toLower(v):
        return None if not AIUtils.isStr(v) else v.lower()
    
    '''
    字符串首字母转大写
    '''
    @staticmethod 
    def toUpperF(v):
        return None if not AIUtils.isStr(v) else (v[0].upper() + v[1:])
    
    '''
    字符串首字母转小写
    '''
    @staticmethod 
    def toLowerF(v):
        return None if not AIUtils.isStr(v) else (v[0].lower() + v[1:])
    
    '''
    字符串去除首尾空格
    '''
    @staticmethod 
    def trim(v):
        return None if not AIUtils.isStr(v) else v.strip()
    
if __name__ == '__main__':
    print AIUtils.dict2str({'a':1, 'b':'333', 'c': 'aaaa'})
    
    
Example #3
0
            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', '\'\'')
            param2 = param2.replace('true', 'True')
            param2 = param2.replace('false', 'False')
            strlList = AIUtils.str2list(param2)
            try:
                mxd = AIMxd(os.path.join(rootPath, 'resources', 'mxd'), os.path.join(rootPath, 'resources', 'mxd', 'Blank.mxd'))
                lyrs = []
                for strl in strlList:
                    layer = AILayer()
                    layer = layer.fromStr(AIUtils.dict2str(strl))
                    lyrs.append(AILayer(layer.getName(), layer.getMinScale(), layer.getMaxScale(), layer.getTransparency(), layer.getVisible()))
                mxd.addLayers(lyrs)
                msdName = mxd.convert2Msd()
            except Exception as e:            
                logger.info(unicode(e.message).encode("utf-8"))
                logger.info('MXD文件创建失败') 

    print msdName