コード例 #1
0
    def create_map(
            self,
            layers: List[Layer],
            epsgCode: int,
            map_title: str,
            center: tuple = None,
            extend: tuple = None,
            base_layer_type: OnlineBaseLayerType = OnlineBaseLayerType.DEFAULT,
            tags: List[str] = None):
        """
        创建地图

        Args:
            layers: 地图图层
            epsgCode: 投影编码
            map_title: 地图名称
            center: 地图中心点
            extend: 地图缩放范围
            base_layer_type: 默认底图类型
            tags: 地图标签

        Returns:
            地图的id
        """
        entity = PostMapsItem()
        if not center is None:
            entity.center = Point2D()
            entity.center.x = center[0]
            entity.center.y = center[1]
        if not extend is None:
            entity.extent = Rectangle2D()
            entity.extent.leftBottom = Point2D()
            entity.extent.leftBottom.x = extend[0]
            entity.extent.leftBottom.y = extend[1]
            entity.extent.rightTop = Point2D()
            entity.extent.rightTop.x = extend[2]
            entity.extent.rightTop.y = extend[3]
        entity.epsgCode = epsgCode
        entity.title = map_title
        entity.layers = self.__prepare_base_layer(base_layer_type) + layers
        entity.tags = tags
        return self._online.maps_service().post_maps(entity).newResourceID
コード例 #2
0
 def test_updatetilejob(self):
     entity = PostTilesetUpdateJobs()
     entity.sourceTileSourceInfo = SMTilesTileSourceInfo()
     entity.sourceTileSourceInfo.type = 'SMTiles'
     entity.sourceTileSourceInfo.outputPath = '/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12'
     entity.sourceTilesetIdentifier = '/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12/World_1179708792_256X256_PNG.smtiles'
     entity.targetTileSourceInfo = SMTilesTileSourceInfo()
     entity.targetTileSourceInfo.type = 'SMTiles'
     entity.targetTileSourceInfo.outputPath = '/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite13'
     entity.targetTilesetIdentifier = '/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite13/World_1318435482_256X256_PNG.smtiles'
     entity.scaleDenominators = [
         4000000.000014754, 8000000.000197801, 15999999.999974867,
         31999999.999949735, 63999999.99821653, 124999999.99967217,
         249999999.99934435
     ]
     entity.bounds = Rectangle2D()
     entity.bounds.leftBottom = Point2D()
     entity.bounds.leftBottom.x = -180
     entity.bounds.leftBottom.y = -90
     entity.bounds.rightTop = Point2D()
     entity.bounds.rightTop.x = 180
     entity.bounds.rightTop.y = 90
     post_body = '{"postResultType":"CreateChild","newResourceID":"f1341552-d09f-456d-8c06-0b04612b5762","succeed":true,"newResourceLocation":"http://192.168.20.158:8090/iserver/manager/tilesetupdatejobs/f1341552-d09f-456d-8c06-0b04612b5762.json"}'
     self.check_api('post_tilesetupdatejobs',
                    self.baseuri + '/manager/tilesetupdatejobs.json',
                    HttpMethod.POST,
                    httpretty.Response(body=post_body, status=200),
                    entity=entity)
     get_body = '[{"postResultType":"CreateChild","newResourceID":"f1341552-d09f-456d-8c06-0b04612b5762","succeed":true,"newResourceLocation":"http://192.168.20.158:8090/iserver/manager/tilesetupdatejobs/f1341552-d09f-456d-8c06-0b04612b5762.json"}]'
     self.check_api('get_tilesetupdatejobs',
                    self.baseuri + '/manager/tilesetupdatejobs.json',
                    HttpMethod.GET,
                    httpretty.Response(body=get_body, status=200))
     job_get_body = '{"id":"f1341552-d09f-456d-8c06-0b04612b5762","state":{"total":14654,"completedScales":[{"tileMatrix":{"novalueFlags":null,"columnCount":3,"rowCount":2,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":6,"scaleDenominator":2.4999999999934435E8,"completed":6,"resolution":0.59419813064}],"actualCompleted":12,"toExportScales":[{"tileMatrix":{"novalueFlags":null,"columnCount":10,"rowCount":5,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":50,"scaleDenominator":6.399999999821653E7,"completed":0,"resolution":0.15211472144},{"tileMatrix":{"novalueFlags":null,"columnCount":19,"rowCount":10,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":190,"scaleDenominator":3.1999999999949735E7,"completed":0,"resolution":0.076057360722},{"tileMatrix":{"novalueFlags":null,"columnCount":37,"rowCount":19,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":703,"scaleDenominator":1.5999999999974867E7,"completed":0,"resolution":0.038028680361},{"tileMatrix":{"novalueFlags":null,"columnCount":74,"rowCount":37,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":2738,"scaleDenominator":8000000.000197801,"completed":0,"resolution":0.019014340181},{"tileMatrix":{"novalueFlags":null,"columnCount":148,"rowCount":74,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":10952,"scaleDenominator":4000000.000014754,"completed":0,"resolution":0.0095071700903}],"exporttingScale":{"tileMatrix":{"novalueFlags":null,"columnCount":5,"rowCount":3,"startingIndex":{"columnIndex":0,"rowIndex":0}},"total":15,"scaleDenominator":1.2499999999967217E8,"nextIndex":{"columnIndex":2,"rowIndex":6},"completed":6,"resolution":0.29709906532},"startTime":1516238843458,"remainTime":334326,"completed":12,"runState":"RUNNING","elapsedTime":274,"speedPerSecond":57},"info":{"sourceTilesetInfo":{"metaData":{"scaleDenominators":[2.4999999999934435E8,1.2499999999967217E8,6.399999999821653E7,3.1999999999949735E7,1.5999999999974867E7,8000000.000197801,4000000.000014754],"originalPoint":{"x":-180,"y":90},"standardMBTiles":false,"resolutions":[0.59419813064,0.29709906532,0.15211472144,0.076057360722,0.038028680361,0.019014340181,0.0095071700903],"tileWidth":256,"mapStatusHashCode":"1318435482","transparent":false,"mapParameter":null,"tileType":"Image","tileFormat":"PNG","bounds":{"top":90,"left":-180,"bottom":-90,"leftBottom":{"x":-180,"y":-90},"right":180,"rightTop":{"x":180,"y":90}},"tileRuleVersion":"1.1","prjCoordSys":{"distanceUnit":"METER","projectionParam":null,"epsgCode":4326,"coordUnit":"DEGREE","name":"Longitude / Latitude Coordinate System---GCS_WGS_1984","projection":null,"type":"PCS_EARTH_LONGITUDE_LATITUDE","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"mapName":"World","tileHeight":256},"name":"smtiles_tileset_1596041633","tileVersions":null},"targetTileSourceInfo":{"outputPath":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12","type":"SMTiles"},"targetInfo":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12/World_1179708792_256X256_PNG.smtiles","scaleDenominators":[2.4999999999934435E8,1.2499999999967217E8,6.399999999821653E7,3.1999999999949735E7,1.5999999999974867E7,8000000.000197801,4000000.000014754],"relatedObject":null,"sourceTilesetDesc":{"filePath":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite13/World_1318435482_256X256_PNG.smtiles","name":"smtiles_tileset_1596041633"},"sourceTileSourceInfo":{"outputPath":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite13","type":"SMTiles"},"targetTilesetIdentifier":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12/World_1179708792_256X256_PNG.smtiles","bounds":{"top":90,"left":-180,"bottom":-90,"leftBottom":{"x":-180,"y":-90},"right":180,"rightTop":{"x":180,"y":90}},"tileVersions":null,"targetTilesetInfo":{"metaData":{"scaleDenominators":[2.4999999999934435E8,1.2499999999967217E8,6.399999999821653E7,3.1999999999949735E7,1.5999999999974867E7,8000000.000197801,4000000.000014754],"originalPoint":{"x":-180,"y":90},"standardMBTiles":false,"resolutions":[0.59419813064,0.29709906532,0.15211472144,0.076057360722,0.038028680361,0.019014340181,0.0095071700903],"tileWidth":256,"mapStatusHashCode":"1179708792","transparent":false,"mapParameter":null,"tileType":"Image","tileFormat":"PNG","bounds":{"top":90,"left":-180,"bottom":-90,"leftBottom":{"x":-180,"y":-90},"right":180,"rightTop":{"x":180,"y":90}},"tileRuleVersion":"1.1","prjCoordSys":{"distanceUnit":"METER","projectionParam":null,"epsgCode":4326,"coordUnit":"DEGREE","name":"Longitude / Latitude Coordinate System---GCS_WGS_1984","projection":null,"type":"PCS_EARTH_LONGITUDE_LATITUDE","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"mapName":"World","tileHeight":256},"name":"smtiles_tileset_1596041633","tileVersions":null},"targetTilesetDesc":{"filePath":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite12/World_1179708792_256X256_PNG.smtiles","name":"smtiles_tileset_1596041633"},"sourceTilesetIdentifier":"/etc/icloud/SuperMapiServer/webapps/iserver/output/sqlite13/World_1318435482_256X256_PNG.smtiles"}}'
     self.check_api(
         'get_tilesetupdatejob',
         self.baseuri +
         '/manager/tilesetupdatejobs/f1341552-d09f-456d-8c06-0b04612b5762.json',
         HttpMethod.GET,
         httpretty.Response(body=job_get_body, status=200),
         id='f1341552-d09f-456d-8c06-0b04612b5762')
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)