예제 #1
0
def recache_tileset(address: str, username: str, password: str, component_name: str, map_name: str,
                    storageid: str = None, tileset_name: str = None, token: str = None):
    api = APIFactory(address, username, password, token)
    mng = api.management()
    storage_info = mng.get_datastore(storageid)
    tilesetinfos = [info for info in storage_info.tilesetInfos if info.metaData.mapName == map_name]
    if len(tilesetinfos) != 1 and tileset_name is None:
        raise Exception("存在多个地图名称相同的缓存")
    tilesetinfo = None
    if len(tilesetinfos) == 1:
        tilesetinfo = tilesetinfos[0]
    else:
        for info in tilesetinfos:
            if info.name == tileset_name:
                tilesetinfo = info

    storage_config = storage_info.tileSourceInfo
    post_tile_jobs_param = PostTileJobsItem()
    post_tile_jobs_param.dataConnectionString = component_name
    post_tile_jobs_param.mapName = map_name
    post_tile_jobs_param.scaleDenominators = tilesetinfo.metaData.scaleDenominators
    if tilesetinfo.metaData.tileHeight == 512:
        post_tile_jobs_param.tileSize = TileSize.SIZE_512
    elif tilesetinfo.metaData.tileHeight == 1024:
        post_tile_jobs_param.tileSize = TileSize.SIZE_1024
    else:
        post_tile_jobs_param.tileSize = TileSize.SIZE_256
    post_tile_jobs_param.tileType = tilesetinfo.metaData.tileType
    post_tile_jobs_param.format = tilesetinfo.metaData.tileFormat
    post_tile_jobs_param.epsgCode = tilesetinfo.metaData.prjCoordSys.epsgCode
    post_tile_jobs_param.storeConfig = storage_config
    post_tile_jobs_param.originalPoint = tilesetinfo.metaData.originalPoint
    post_tile_jobs_param.cacheBounds = tilesetinfo.metaData.bounds
    post_tile_jobs_param.tileVersionDescription = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    post_tile_jobs_param.createNewTileVersion = True
    ptjr = mng.post_tilejobs(post_tile_jobs_param)
    jobstate = mng.get_tilejob(ptjr.newResourceID).state

    bar = _process_bar('切图', _PercentageCounter(), jobstate.total)
    while (jobstate.runState is BuildState.BUILDING):
        time.sleep(5)
        jobstate = mng.get_tilejob(ptjr.newResourceID).state
        bar.update(jobstate.completed)

    gjr = mng.get_tilejob(ptjr.newResourceID)
    if (gjr.state.runState is not BuildState.COMPLETED):
        raise Exception('切图失败')
예제 #2
0
 def init_apifactory(self):
     if not hasattr(self, 'factory'):
         loginuri = self.loginuri if hasattr(
             self,
             'loginuri') else self.baseuri + '/services/security/login.json'
         httpretty.register_uri(
             httpretty.POST,
             loginuri,
             status=201,
             set_cookie='JSESSIONID=958322873908FF9CA99B5CB443ADDD5C')
         self.factory = APIFactory(self.baseuri, self.username,
                                   self.password)
예제 #3
0
def create_apifactory_from_profile(profile: Profile, **kwargs):
    if profile.authentication.type == AuthenticationType.Password:
        authentication = profile.authentication  #type: UsernamePasswdAuthentication
        kwargs.update({
            'username': authentication.username,
            'passwd': authentication.passwd
        })
    else:
        authentication = profile.authentication  # type: TokenAuthentication
        kwargs.update({'token': authentication.token})
    kwargs['base_url'] = profile.url
    return APIFactory(**kwargs)
예제 #4
0
def cache_service(address: str,
                  username: str,
                  password: str,
                  component_name: str,
                  map_name: str,
                  original_point: tuple,
                  cache_bounds: tuple,
                  scale: List[float] = None,
                  tile_size: TileSize = TileSize.SIZE_256,
                  tile_type: TileType = TileType.Image,
                  format: OutputFormat = OutputFormat.PNG,
                  epsg_code: int = -1,
                  storageid: str = None,
                  storageconfig: TileSourceInfo = None,
                  token: str = None,
                  quiet: bool = False,
                  job_tile_source_type: str = 'SMTiles',
                  output: str = None):
    if len(original_point) is not 2:
        raise Exception("切图原点坐标长度错误")
    tem_original_point = Point2D()
    tem_original_point.x = original_point[0]
    tem_original_point.y = original_point[1]
    if len(cache_bounds) is not 4:
        raise Exception("切图范围长度错误")
    tem_cache_Bounds = Rectangle2D()
    tem_cache_Bounds.leftBottom = Point2D()
    tem_cache_Bounds.leftBottom.x = cache_bounds[0]
    tem_cache_Bounds.leftBottom.y = cache_bounds[1]
    tem_cache_Bounds.rightTop = Point2D()
    tem_cache_Bounds.rightTop.x = cache_bounds[2]
    tem_cache_Bounds.rightTop.y = cache_bounds[3]
    api = APIFactory(address, username, password, token)
    mng = api.management()
    if scale is None or len(scale) is 0:
        raise Exception('未指定比例尺')
    if storageid is not None:
        storage_info = mng.get_datastore(storageid)
        for info in storage_info.tilesetInfos:
            if info.metaData.mapName == map_name:
                storageconfig = storage_info.tileSourceInfo

    if storageconfig is None:
        storageconfig = SMTilesTileSourceInfo()
        storageconfig.type = job_tile_source_type
        storageconfig.outputPath = output if output is not None else '../webapps/iserver/output/icpy_' + uuid.uuid1(
        ).__str__()

    if not quiet:
        confirmResult = confirm(address=address,
                                username=username,
                                password=password,
                                component_name=component_name,
                                map_name=map_name,
                                original_point=original_point,
                                cache_bounds=cache_bounds,
                                scale=scale,
                                tile_size=tile_size,
                                tile_type=tile_type,
                                format=format,
                                epsg_code=epsg_code,
                                storageid=storageid,
                                token=token)
        if confirmResult.lower() == 'n':
            return

    post_tile_jobs_param = PostTileJobsItem()
    post_tile_jobs_param.dataConnectionString = component_name
    post_tile_jobs_param.mapName = map_name
    post_tile_jobs_param.scaleDenominators = scale
    post_tile_jobs_param.tileSize = tile_size
    post_tile_jobs_param.tileType = tile_type
    post_tile_jobs_param.format = format
    post_tile_jobs_param.epsgCode = epsg_code
    post_tile_jobs_param.storeConfig = storageconfig
    post_tile_jobs_param.originalPoint = tem_original_point
    post_tile_jobs_param.cacheBounds = tem_cache_Bounds
    ptjr = mng.post_tilejobs(post_tile_jobs_param)
    jobstate = mng.get_tilejob(ptjr.newResourceID).state

    bar = _process_bar('切图', _PercentageCounter(), jobstate.total)
    while (jobstate.runState is BuildState.BUILDING):
        time.sleep(5)
        jobstate = mng.get_tilejob(ptjr.newResourceID).state
        bar.update(jobstate.completed)

    gjr = mng.get_tilejob(ptjr.newResourceID)
    if (gjr.state.runState is not BuildState.COMPLETED):
        raise Exception('切图失败')
    if output is not None:
        print("切图结果存储路径为:" + output)
예제 #5
0
def cache_workspace(address: str,
                    username: str,
                    password: str,
                    w_loc: str,
                    map_name: str,
                    original_point: tuple,
                    cache_bounds: tuple,
                    scale: List[float] = None,
                    w_servicetypes: List[ServiceType] = [ServiceType.RESTMAP],
                    tile_size: TileSize = TileSize.SIZE_256,
                    tile_type: TileType = TileType.Image,
                    format: OutputFormat = OutputFormat.PNG,
                    epsg_code: int = -1,
                    storageid: str = None,
                    storageconfig: TileSourceInfo = None,
                    token: str = None,
                    quiet: bool = False,
                    job_tile_source_type: str = 'SMTiles',
                    output: str = None,
                    remote_workspace: bool = False):
    if len(original_point) is not 2:
        raise Exception("切图原点坐标长度错误")
    tem_original_point = Point2D()
    tem_original_point.x = original_point[0]
    tem_original_point.y = original_point[1]
    if len(cache_bounds) is not 4:
        raise Exception("切图范围长度错误")
    tem_cache_Bounds = Rectangle2D()
    tem_cache_Bounds.leftBottom = Point2D()
    tem_cache_Bounds.leftBottom.x = cache_bounds[0]
    tem_cache_Bounds.leftBottom.y = cache_bounds[1]
    tem_cache_Bounds.rightTop = Point2D()
    tem_cache_Bounds.rightTop.x = cache_bounds[2]
    tem_cache_Bounds.rightTop.y = cache_bounds[3]
    api = APIFactory(address, username, password, token)
    mng = api.management()
    if scale is None or len(scale) is 0:
        raise Exception('未指定比例尺')

    if not quiet:
        confirmResult = confirm(address=address,
                                username=username,
                                password=password,
                                w_loc=w_loc,
                                map_name=map_name,
                                original_point=original_point,
                                cache_bounds=cache_bounds,
                                scale=scale,
                                w_servicetype=w_servicetypes,
                                tile_size=tile_size,
                                tile_type=tile_type,
                                format=format,
                                epsg_code=epsg_code,
                                storageid=storageid,
                                token=token,
                                output=output)
        if confirmResult.lower() == 'n':
            return
    if remote_workspace:
        remote_workspace_file_full_path = w_loc
    else:
        param = PostFileUploadTasksParam()
        pfutsr = mng.post_fileuploadtasks(param)
        remote_workspace_file_full_path = _upload_workspace_file(
            mng, w_loc, pfutsr.newResourceID)
        gfutr = mng.get_fileuploadtask(pfutsr.newResourceID)
        if gfutr.state is not FileUploadState.COMPLETED:
            raise Exception('文件上传失败')
        print("工作空间上传路径为:" + remote_workspace_file_full_path)

    post_param = PostWorkspaceParameter()
    post_param.workspaceConnectionInfo = remote_workspace_file_full_path
    post_param.servicesTypes = w_servicetypes
    pwr = mng.post_workspaces(post_param)
    wkn = re.findall('services/[^/]*',
                     pwr[0].serviceAddress)[0].lstrip('services/')

    cache_service(address=address,
                  username=username,
                  password=password,
                  component_name=wkn,
                  map_name=map_name,
                  original_point=original_point,
                  cache_bounds=cache_bounds,
                  scale=scale,
                  tile_size=tile_size,
                  tile_type=tile_type,
                  format=format,
                  epsg_code=epsg_code,
                  storageid=storageid,
                  storageconfig=storageconfig,
                  token=token,
                  quiet=True,
                  job_tile_source_type=job_tile_source_type,
                  output=output)
예제 #6
0
 def __init__(self, api_factory: APIFactory):
     self._management = api_factory.management()
     self._api_factory = api_factory
예제 #7
0
def update_smtilestileset(address: str, username: str, password: str, component_name: str, w_loc: str, map_name: str,
                          original_point: tuple, cache_bounds: tuple, scale: List[float] = None,
                          w_servicetypes: List[ServiceType] = [ServiceType.RESTMAP],
                          tile_size: TileSize = TileSize.SIZE_256, tile_type: TileType = TileType.Image,
                          format: OutputFormat = OutputFormat.PNG, epsgcode: int = -1, storageid: str = None,
                          storageconfig: TileSourceInfo = None, remote_workspace: bool = False,
                          quiet: bool = False, source_component_name: str = '', update: bool = False,
                          tile_version: str = None, token: str = None):
    if len(original_point) is not 2:
        raise Exception("切图原点坐标长度错误")
    tem_original_point = Point2D()
    tem_original_point.x = original_point[0]
    tem_original_point.y = original_point[1]
    if len(cache_bounds) is not 4:
        raise Exception("切图范围长度错误")
    tem_cache_Bounds = Rectangle2D()
    tem_cache_Bounds.leftBottom = Point2D()
    tem_cache_Bounds.leftBottom.x = cache_bounds[0]
    tem_cache_Bounds.leftBottom.y = cache_bounds[1]
    tem_cache_Bounds.rightTop = Point2D()
    tem_cache_Bounds.rightTop.x = cache_bounds[2]
    tem_cache_Bounds.rightTop.y = cache_bounds[3]
    api = APIFactory(address, username, password, token)
    mng = api.management()
    if scale is None:
        map_service = api.map_service(component_name + '/rest')
        mr = map_service.get_map(map_name)
        scale = [1 / x for x in mr.visibleScales]
    if scale is None or len(scale) is 0:
        raise Exception('无法获取目标地图比例尺且未指定比例尺')
    if storageid is not None:
        storage_info = mng.get_datastore(storageid)
        for info in storage_info.tilesetInfos:
            if info.metaData.mapName == map_name:
                storageconfig = storage_info.tileSourceInfo

    if storageconfig is None:
        storageconfig = SMTilesTileSourceInfo()
        storageconfig.type = 'SMTiles'
        storageconfig.outputPath = '../webapps/iserver/output/sqlite_' + uuid.uuid1().__str__()

    if not quiet:
        confirmResult = confirm(address=address, username=username, password=password, component_name=component_name,
                                w_loc=w_loc, map_name=map_name, original_point=original_point,
                                cache_bounds=cache_bounds, scale=scale, w_servicetype=w_servicetypes,
                                tile_size=tile_size, tile_type=tile_type, format=format, epsg_code=epsgcode,
                                storageid=storageid, remote_workspace=remote_workspace,
                                source_component_name=source_component_name, update=update, token=token)
        if confirmResult.lower() == 'n':
            return

    wkn = source_component_name
    if not update:
        param = PostFileUploadTasksParam()
        if remote_workspace:
            remote_workspace_file_full_path = w_loc
        else:
            pfutsr = mng.post_fileuploadtasks(param)
            remote_workspace_file_full_path = _upload_workspace_file(mng, w_loc, pfutsr.newResourceID)
            gfutr = mng.get_fileuploadtask(pfutsr.newResourceID)
            if gfutr.state is not FileUploadState.COMPLETED:
                raise Exception('文件上传失败')
        post_param = PostWorkspaceParameter()
        post_param.workspaceConnectionInfo = remote_workspace_file_full_path
        post_param.servicesTypes = w_servicetypes
        pwr = mng.post_workspaces(post_param)
        wkn = re.findall('services/[^/]*', pwr[0].serviceAddress)[0].lstrip('services/')

    post_tile_jobs_param = PostTileJobsItem()
    post_tile_jobs_param.dataConnectionString = wkn
    post_tile_jobs_param.mapName = map_name
    post_tile_jobs_param.scaleDenominators = scale
    post_tile_jobs_param.tileSize = tile_size
    post_tile_jobs_param.tileType = tile_type
    post_tile_jobs_param.format = format
    post_tile_jobs_param.epsgCode = epsgcode
    post_tile_jobs_param.storeConfig = storageconfig
    post_tile_jobs_param.originalPoint = tem_original_point
    post_tile_jobs_param.cacheBounds = tem_cache_Bounds
    post_tile_jobs_param.tileVersionDescription = tile_version
    ptjr = mng.post_tilejobs(post_tile_jobs_param)
    jobstate = mng.get_tilejob(ptjr.newResourceID).state

    bar = _process_bar('切图', _PercentageCounter(), jobstate.total)
    while (jobstate.runState is BuildState.BUILDING):
        time.sleep(5)
        jobstate = mng.get_tilejob(ptjr.newResourceID).state
        bar.update(jobstate.completed)

    gjr = mng.get_tilejob(ptjr.newResourceID)
    if (gjr.state.runState is not BuildState.COMPLETED):
        raise Exception('切图失败')

    if isinstance(storageconfig, SMTilesTileSourceInfo):
        post_tile_update_param = PostTilesetUpdateJobs()
        post_tile_update_param.scaleDenominators = scale
        post_tile_update_param.bounds = tem_cache_Bounds
        post_tile_update_param.targetTilesetIdentifier = None
        post_tile_update_param.targetTileSourceInfo = _get_tile_source_info_from_service(mng, component_name)
        post_tile_update_param.sourceTilesetIdentifier = gjr.targetTilesetInfo.filePath
        post_tile_update_param.sourceTileSourceInfo = SMTilesTileSourceInfo()
        post_tile_update_param.sourceTileSourceInfo.type = 'SMTiles'
        post_tile_update_param.sourceTileSourceInfo.outputPath = post_tile_jobs_param.storeConfig.outputPath
        ptur = mng.post_tilesetupdatejobs(post_tile_update_param)
        gtur = mng.get_tilesetupdatejob(ptur.newResourceID)
        bar = _process_bar('更新', _PercentageCounter(), gtur.state.total)
        while (not hasattr(gtur.state, 'runState') or gtur.state.runState is TilesetExportJobRunState.RUNNING):
            time.sleep(5)
            gtur = mng.get_tilesetupdatejob(ptur.newResourceID)
            bar.update(gtur.state.actualCompleted)
        if (gtur.state.runState is not TilesetExportJobRunState.COMPLETED):
            raise Exception('更新切片失败')
    if not update:
        mng.delete_mapcomponent(name=wkn)