首页 > 其他分享 >GeoServer API设置WMS服务图层的缓存信息

GeoServer API设置WMS服务图层的缓存信息

时间:2023-11-28 22:46:01浏览次数:32  
标签:name WMS GeoServer rest json API geoserver import path

import requests
import json

 # 设置缓存时间
data = json.dumps({
    "coverage": {
        "metadata": {
            "entry": [
                {
                    "@key": "cacheAgeMax",
                    "$": "1800"
                },
                {
                    "@key": "cachingEnabled",
                    "$": "true"
                }
            ]
        }
    }
})
resp = requests.put(
    f"http://localhost:1231/geoserver/rest/workspaces/seaice/coveragestores/{name}/coverages/{name}.json",
    data, headers={'Content-Type': 'application/json'}, auth=('admin', 'geoserver'))
print(resp)

点击查看全部代码
from geoserver.catalog import Catalog
import os
import glob
import requests
import json


def AutoPublicWMSLayer():
  """
  Python批量发布WMS服务
  """
  for tifFile in glob.glob(f'{tif_out_dir}/*.tif'):
      # 示例  ./data/date/Tif/ice_thickness_1020.tif
      name = os.path.splitext(os.path.basename(tifFile))[0]
      # 我提前在geoserver设置了ice_thickness等样式,这里是根据图层名称取对于样式
      style = '_'.join(name.split('_')[:-1])
      print(name)
      absolute_path = os.path.abspath(tifFile)
      cat = Catalog("http://localhost:1231/geoserver/rest/", username="admin", password="geoserver")
      cat.create_coveragestore_external_geotiff(name, absolute_path, workspace=cat.get_workspace("seaice"),
                                                overwrite=True)
      # 设置默认样式
      response = requests.put(f'http://localhost:1231/geoserver/rest/layers/seaice:{name}',
                              headers={'Content-Type': 'application/xml'},
                              data=f"<layer><defaultStyle><name>seaice:{style}</name></defaultStyle><queryable>false"
                                   f"</queryable></layer>",
                              auth=('admin', 'geoserver'))
      print(response)
      # 设置缓存时间
      data = json.dumps({
          "coverage": {
              "metadata": {
                  "entry": [
                      {
                          "@key": "cacheAgeMax",
                          "$": "1800"
                      },
                      {
                          "@key": "cachingEnabled",
                          "$": "true"
                      }
                  ]
              }
          }
      })
      resp = requests.put(
          f"http://localhost:1231/geoserver/rest/workspaces/seaice/coveragestores/{name}/coverages/{name}.json",
          data, headers={'Content-Type': 'application/json'}, auth=('admin', 'geoserver'))
      print(resp)

def AutoDeleteWMSLayer():
    """
    Python批量删除WMS服务
    """
    for tifFile in glob.glob(f'{tif_out_dir}/*.tif'):
        name = os.path.splitext(os.path.basename(tifFile))[0]
        try:
            url = f"http://localhost:1231/geoserver/rest/workspaces/seaice/coveragestores/{name}.xml?recurse=true"
            response = requests.delete(url, auth=('admin', 'geoserver'))
            if response.status_code != requests.codes.ok:
                raise Exception(response.status_code)
        except Exception as e:
            print(f"ERROR:{name}>>{e}")

if __name__ == '__main__':
    tif_out_dir = '../data/date/Tif'
    AutoPublicWMSLayer()
    # AutoDeleteWMSLayer()

https://www.osgeo.cn/geoserver-user-manual/rest/index.html#rest

标签:name,WMS,GeoServer,rest,json,API,geoserver,import,path
From: https://www.cnblogs.com/echohye/p/17863303.html

相关文章

  • ElasticSearch之cat nodes API
    命令样例如下:curl-XGET"https://localhost:9200/_cat/nodes?v=true&pretty"--cacert$ES_HOME/config/certs/http_ca.crt-u"elastic:ohCxPH=QBE+s5=*lo7F9"执行结果输出如下:ipheap.percentram.percentcpuload_1mload_5mload_15mnode.role......
  • 新特性之Date API
    ClockClock类提供了访问当前日期和时间的方法,Clock是时区敏感的,可以用来取代System.currentTimeMillis()来获取当前的微秒数。某个特定的时间点也可以使用Instant类来表示,Instant类也可以用来创建老的java.util.Date对象 publicclassTest{publicstaticvoidmain(Stri......
  • ElasticSearch之cat nodeattrs API
    命令样例如下:curl-XGET"https://localhost:9200/_cat/nodeattrs?v=true&pretty"--cacert$ES_HOME/config/certs/http_ca.crt-u"elastic:ohCxPH=QBE+s5=*lo7F9"执行结果输出如下:nodehostipattrvalu......
  • ElasticSearch之cat master API
    命令样例如下:curl-XGET"https://localhost:9200/_cat/master?v=true&pretty"--cacert$ES_HOME/config/certs/http_ca.crt-u"elastic:ohCxPH=QBE+s5=*lo7F9"执行结果输出如下:idhostipnodeaKgBu7LgS9a6iPYH8n2JPw1......
  • ElasticSearch之cat indices API
    命令样例如下:curl-XGET"https://localhost:9200/_cat/indices?v=true&pretty"--cacert$ES_HOME/config/certs/http_ca.crt-u"elastic:ohCxPH=QBE+s5=*lo7F9"执行结果输出如下:healthstatusindexuuidprirepdocs.coun......
  • Apipost也出IDEA插件了?Apipost-Helper!
    IDEA是一款功能强大的集成开发环境(IDE),它可以帮助开发人员更加高效地编写、调试和部署软件应用程序。我们在编写完接口代码后需要进行接口调试等操作,一般需要打开额外的调试工具。今天给大家介绍一款IDEA插件:Apipost-Helper-2.0。代码写完直接编辑器内调试、还支持生成接口文档、接......
  • Apipost也出IDEA插件了?Apipost-Helper!
    IDEA是一款功能强大的集成开发环境(IDE),它可以帮助开发人员更加高效地编写、调试和部署软件应用程序。我们在编写完接口代码后需要进行接口调试等操作,一般需要打开额外的调试工具。今天给大家介绍一款IDEA插件:Apipost-Helper-2.0。代码写完直接编辑器内调试、还支持生成接口文档、......
  • Vue中process.env关键字,process.env.VUE_APP_BASE_API
    Vue中process.env关键字,process.env.VUE_APP_BASE_API:https://blog.csdn.net/coinisi_li/article/details/128547778 vue分环境配置变量及打包:https://blog.csdn.net/weixin_44794123/article/details/121682978?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.......
  • 查询表记录API
    <1>all():查询所有结果<2>filter(**kwargs):它包含了与所给筛选条件相匹配的对象<3>get(**kwargs):返回与所给筛选条件相匹配的对象,返回结果有且只有一个,如果符合筛选条件的对象超过一个或者没有都会抛出错误。<4>exclude(**kwargs):它包含了与所给筛......
  • API 接口主流协议有哪些?及WebService和Restful之间的区别和联系?
    API接口主流协议有哪些?如何创建HTTP/HTTPS、WebSocket/WebSockets、TCP/UDP、gRPC、SOAP、Dubbo/HSF等不同协议?RESTFUL:简单来说就是对HTTP请求的方式和路径的一种约束规则,一种思想。只要是符合这种思想的HTTP接口都可以叫做RESTFUL接口即同一个路径,相同的参数,请求方式的不同......