1

我正在使用 Maps Engine API 批量加载栅格。我有将栅格作为数据源上传的代码,但我看不出如何将该数据源添加到现有图层中。

如果我创建一个新层,我可以指定要包含的数据源列表。我要添加很多栅格,所以我需要能够添加到已经存在的图层。

这是我到目前为止的一段代码:

fileupload = {
"projectId": id,
"name": "Test API Upload - Name",
"description": "Test API Upload - Description",
"files": filenames,

"draftAccessList": "Map Editors",
"attribution": "Copyright My Copyright",
"tags": ["testAPIUpload"],
"maskType": "autoMask",
"rasterType": "image"
}

rasters = service.rasters()
request = rasters.upload(body=fileupload)
response = request.execute()

try:
    rasterUploadId = str(response['id'])


    for name in raster_files:
        print "Waiting for 2 seconds"
        time.sleep(2)

        try:
            freq = rasters.files().insert(id=rasterUploadId,
                                          filename=name,
                                          media_body=name)
            print "Calling insert request"
            freq.execute()
            print "Finished uploading %s" % name
        except Exception:
            print "Unable to insert '%s'" % name

except KeyError:
    print "Error uploading raster files"
    print response

现在我已经上传了栅格,如何将它们添加到已经存在的图层中?

谢谢,

4

1 回答 1

0

如果您有一个现有层并希望在发布它们时使用数据源对其进行更新,那么您可以使用层补丁方法。

您需要确保包含现有数据源,因为发送带有提供的数据源的补丁请求会将图层设置为使用这些数据源,删除未包含的任何内容。

于 2014-08-28T04:45:06.027 回答