导入程序REST API示例

批量配置形状文件目录

为了启动导入 c:\data\tasmania 目录复制到现有的 tasmania 工作空间:

  1. 以下JSON将发布到Geoserver。

    import.json
      {
         "import": {
            "targetWorkspace": {
               "workspace": {
                  "name": "tasmania"
               }
            },
            "data": {
              "type": "directory",
              "location": "C:/data/tasmania"
            }
         }
      }
    
  2. 此cURL命令可用于以下目的:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
  -d @import.json \
  "http://localhost:8080/geoserver/rest/imports"

导入器将定位要导入的文件,并自动准备任务,返回以下响应:

{
  "import": {
    "id": 9,
    "href": "http://localhost:8080/geoserver/rest/imports/9",
    "state": "PENDING",
    "archive": false,
    "targetWorkspace": {
      "workspace": {
        "name": "tasmania"
      }
    },
    "data": {
      "type": "directory",
      "format": "Shapefile",
      "location": "C:\\data\\tasmania",
      "href": "http://localhost:8080/geoserver/rest/imports/9/data"
    },
    "tasks": [
      {
        "id": 0,
        "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/0",
        "state": "READY"
      },
      {
        "id": 1,
        "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/1",
        "state": "READY"
      },
      {
        "id": 2,
        "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/2",
        "state": "READY"
      },
      {
        "id": 3,
        "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/3",
        "state": "READY"
      }
    ]
  }
}
  1. 在检查每个任务都准备好后,可以通过在导入资源上执行POST来启动导入:

    curl -u admin:geoserver -XPOST \
       "http://localhost:8080/geoserver/rest/imports/9"
    
  2. 然后,可以监控资源的进度,并最终得出最终结果:

    curl -u admin:geoserver -XGET \
       "http://localhost:8080/geoserver/rest/imports/9"
    

    如果成功导入,则如下所示:

    {
      "import": {
        "id": 9,
        "href": "http://localhost:8080/geoserver/rest/imports/9",
        "state": "COMPLETE",
        "archive": false,
        "targetWorkspace": {
          "workspace": {
            "name": "tasmania"
          }
        },
        "data": {
          "type": "directory",
          "format": "Shapefile",
          "location": "C:\\data\\tasmania",
          "href": "http://localhost:8080/geoserver/rest/imports/9/data"
        },
        "tasks": [
          {
            "id": 0,
            "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/0",
            "state": "COMPLETE"
          },
          {
            "id": 1,
            "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/1",
            "state": "COMPLETE"
          },
          {
            "id": 2,
            "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/2",
            "state": "COMPLETE"
          },
          {
            "id": 3,
            "href": "http://localhost:8080/geoserver/rest/imports/9/tasks/3",
            "state": "COMPLETE"
          }
        ]
      }
    }
    

配置没有投影信息的形状文件

在本例中,让我们假设我们只有一个shapefile, tasmania_cities.shp ,那就没有了 :file:.prj` Sidecar文件(该示例同样适用于以下任何情况 prj 文件内容不能与官方EPSG代码匹配)。

  1. 我们将发布以下导入定义:

    import.json
    {
       "import": {
          "targetWorkspace": {
             "workspace": {
                "name": "tasmania"
             }
          },
          "data": {
            "type": "file",
            "file": "C:/data/tasmania/tasmania_cities.shp"
          }
       }
    }
    
  2. 使用curl post命令:

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
       -d @import.json \
       "http://localhost:8080/geoserver/rest/imports"
    

    如果CRS丢失,响应将为:

    {
      "import": {
        "id": 13,
        "href": "http://localhost:8080/geoserver/rest/imports/13",
        "state": "PENDING",
        "archive": false,
        "targetWorkspace": {
          "workspace": {
            "name": "tasmania"
          }
        },
        "data": {
          "type": "file",
          "format": "Shapefile",
          "file": "tasmania_cities.shp"
        },
        "tasks": [
          {
            "id": 0,
            "href": "http://localhost:8080/geoserver/rest/imports/13/tasks/0",
            "state": "NO_CRS"
          }
        ]
      }
    }
    
  3. 深入到任务层:

    curl -u admin:geoserver -XGET -H "Content-type: application/json" \
         http://localhost:8080/geoserver/rest/imports/13/tasks/0/layer
    

    我们可以看到缺少SRS信息:

    {
      "layer": {
        "name": "tasmania_cities",
        "href": "http://localhost:8080/geoserver/rest/imports/13/tasks/0/layer",
        "title": "tasmania_cities",
        "originalName": "tasmania_cities",
        "nativeName": "tasmania_cities",
        "bbox": {
          "minx": 146.2910004483,
          "miny": -43.85100181689,
          "maxx": 148.2910004483,
          "maxy": -41.85100181689
        },
        "attributes": [
          {
            "name": "the_geom",
            "binding": "org.locationtech.jts.geom.MultiPoint"
          },
          {
            "name": "CITY_NAME",
            "binding": "java.lang.String"
          },
          {
            "name": "ADMIN_NAME",
            "binding": "java.lang.String"
          },
          {
            "name": "CNTRY_NAME",
            "binding": "java.lang.String"
          },
          {
            "name": "STATUS",
            "binding": "java.lang.String"
          },
          {
            "name": "POP_CLASS",
            "binding": "java.lang.String"
          }
        ],
        "style": {
          "name": "tasmania_tasmania_cities2",
          "href": "http://localhost:8080/geoserver/rest/imports/13/tasks/0/layer/style"
        }
      }
    }
    
  4. 使用以下JSON代码段更新SRS:

    layerUpdate.json
     {
        layer : {
           srs: "EPSG:4326"
        }
     }
    

    使用cURL PUT命令:

    curl -u admin:geoserver -XPUT -H "Content-type: application/json" \
      -d @layerUpdate.json \
      "http://localhost:8080/geoserver/rest/imports/13/tasks/0/layer/"
    
  5. 再次获取导入定义:

    curl -u admin:geoserver -XGET -H "Content-type: application/json" \
         http://localhost:8080/geoserver/rest/imports/13/tasks/0
    

    导入现已准备好执行:

    {
      "import": {
        "id": 13,
        "href": "http://localhost:8080/geoserver/rest/imports/13",
        "state": "PENDING",
        "archive": false,
        "targetWorkspace": {
          "workspace": {
            "name": "tasmania"
          }
        },
        "data": {
          "type": "file",
          "format": "Shapefile",
          "file": "tasmania_cities.shp"
        },
        "tasks": [
          {
            "id": 0,
            "href": "http://localhost:8080/geoserver/rest/imports/13/tasks/0",
            "state": "READY"
          }
        ]
      }
    }
    
  6. POST请求将执行导入:

    curl -u admin:geoserver -XPOST \
      "http://localhost:8080/geoserver/rest/imports/13"
    

    如果成功导入,则将任务标记为 COMPLETE

    {
      "import": {
        "id": 13,
        "href": "http://localhost:8080/geoserver/rest/imports/13",
        "state": "COMPLETE",
        "archive": false,
        "targetWorkspace": {
          "workspace": {
            "name": "tasmania"
          }
        },
        "data": {
          "type": "file",
          "format": "Shapefile",
          "file": "tasmania_cities.shp"
        },
        "tasks": [
          {
            "id": 0,
            "href": "http://localhost:8080/geoserver/rest/imports/13/tasks/0",
            "state": "COMPLETE"
          }
        ]
      }
    }
    

将形状文件上载到Postgis

此示例显示将形状文件(在zip文件中)上载到现有PostGIS数据存储(引用:PostGIS)的过程。

  1. 布设 cite:postgis 数据存储区:

    postgis.json
    {
      "dataStore": {
        "name": "postgis",
        "type": "PostGIS",
        "workspace": {
          "name": "cite"
        },
        "connectionParameters": {
          "entry": [
            {"@key": "schema","$": "public"},
            {"@key": "database","$": "postgres"},
            {"@key": "host","$": "localhost"},
            {"@key": "port","$": "5432"},
            {"@key": "passwd","$": "postgres"},
            {"@key": "dbtype","$": "postgis"},
            {"@key": "user","$": "postgres"},
            {"@key": "Estimated extends","$": "true"},
            {"@key": "encode functions","$": "true"},
            {"@key": "Loose bbox","$": "true"},
            {"@key": "Method used to simplify geometries","$": "PRESERVETOPOLOGY"},
            {"@key": "Support on the fly geometry simplification","$": "true"},
            {"@key": "validate connections","$": "true"},
            {"@key": "Connection timeout","$": "20"},
            {"@key": "min connections","$": "1"},
            {"@key": "max connections","$": "10"},
            {"@key": "Evictor tests per run","$": "3"},
            {"@key": "Test while idle","$": "true"},
            {"@key": "Max connection idle time","$": "300"}
          ]
        },
        "_default": true
      }
    }
    

    使用卷曲贴纸:

    curl  -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @postgis.json \
      "http://localhost:8080/geoserver/rest/workspaces/cite/datastores.json"
    
  2. 创建导入定义:

    import.json
    {
       "import": {
          "targetWorkspace": {
             "workspace": {
                "name": "cite"
             }
          },
          "targetStore": {
             "dataStore": {
                "name": "postgis"
             }
          }
       }
    }
    

    将此定义发布到/Geoserver/rest/Imports:

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @import.json \
      "http://localhost:8080/geoserver/rest/imports"
    

    响应将包含导入ID。

  3. 我们现在有一个没有任务的空导入。要添加任务,请将shapefile发布到任务列表中:

    curl -u admin:geoserver \
      -F name=myshapefile.zip -F filedata=@myshapefile.zip \
      "http://localhost:8080/geoserver/rest/imports/14/tasks"
    
  4. 因为我们发送了一个shapefile,所以导入器假定目标将是一个shapefile商店。要导入到PostGIS,我们需要对其进行重置。

    创建以下JSON文件:

    target.json
    {
      "dataStore": {
        "name":"postgis"
      }
    }
    

    将此文件放到/Geoserver/rest/Imports/14/Tasks0/Target:

    curl -u admin:geoserver -XPUT -H "Content-type: application/json" \
      -d @target.json \
      "http://localhost:8080/geoserver/rest/imports/14/tasks/0/target"
    
  5. 最后,我们通过向/Geoserver/rest/Imports/14发送一个POST来执行导入:

    curl -u admin:geoserver -XPOST \
      "http://localhost:8080/geoserver/rest/imports/14"
    

在转换时将csv文件上载到postgis

一个遥感工具正在生成带有一些位置和测量的CSV文件,我们希望将这些文件作为新的空间表上传到PostGIS中。

  1. 首先,我们将创建一个空的导入,将现有的postgis存储作为目标:

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @import.json \
      "http://localhost:8080/geoserver/rest/imports"
    

    哪里 import.json 是:

    import.json
    {
       "import": {
          "targetWorkspace": {
             "workspace": {
                "name": "cite"
             }
          },
          "targetStore": {
             "dataStore": {
                "name": "postgis"
             }
          }
       }
    }
    
  2. 然后,我们将把CSV文件发布到任务列表。

    values.csv
    AssetID, SampleTime, Lat, Lon, Value
    1, 2015-01-01T10:00:00, 10.00, 62.00, 15.2
    1, 2015-01-01T11:00:00, 10.10, 62.11, 30.25
    1, 2015-01-01T12:00:00, 10.20, 62.22, 41.2
    1, 2015-01-01T13:00:00, 10.31, 62.33, 27.6
    1, 2015-01-01T14:00:00, 10.41, 62.45, 12
    

    要为其创建导入任务,请执行以下操作:

    curl -u admin:geoserver -F name=test -F filedata=@values.csv \
      "http://localhost:8080/geoserver/rest/imports/0/tasks"
    

    我们将返回一个新的任务定义,并通知CRS缺失:

    {
      "task": {
        "id": 0,
        "href": "http://localhost:8080/geoserver/rest/imports/0/tasks/0",
        "state": "NO_CRS",
        "updateMode": "CREATE",
        "data": {
          "type": "file",
          "format": "CSV",
          "file": "values.csv"
        },
        "target": {
          "href": "http://localhost:8080/geoserver/rest/imports/0/tasks/0/target",
          "dataStore": {
            "name": "postgis",
            "type": "PostGIS"
          }
        },
        "progress": "http://localhost:8080/geoserver/rest/imports/0/tasks/0/progress",
        "layer": {
          "name": "values",
          "href": "http://localhost:8080/geoserver/rest/imports/0/tasks/0/layer"
        },
        "transformChain": {
          "type": "vector",
          "transforms": []
        }
      }
    }
    
  3. 通过更新层来强制CRS:

    layerUpdate.json
    {
       "layer" : {
          "srs": "EPSG:4326"
       }
    }
    

    使用PUT更新任务层:

    curl -u admin:geoserver -XPUT -H "Content-type: application/json" \
      -d @layerUpdate.json \
      "http://localhost:8080/geoserver/rest/imports/0/tasks/0/layer/"
    

    更新SRS:

    {
      "layer": {
        "name": "values",
        "href": "http://localhost:8080/geoserver/rest/imports/0/tasks/0/layer",
        "title": "values",
        "originalName": "values",
        "nativeName": "values",
        "srs": "EPSG:4326",
        "bbox": {
          "minx": 0,
          "miny": 0,
          "maxx": -1,
          "maxy": -1
        },
        "attributes": [
          {
            "name": "AssetID",
            "binding": "java.lang.Integer"
          },
          {
            "name": "SampleTime",
            "binding": "java.lang.String"
          },
          {
            "name": "Lat",
            "binding": "java.lang.Double"
          },
          {
            "name": "Lon",
            "binding": "java.lang.Double"
          },
          {
            "name": "Value",
            "binding": "java.lang.Double"
          }
        ],
        "style": {
          "name": "point",
          "href": "http://localhost:8080/geoserver/rest/imports/0/tasks/0/layer/style"
        }
      }
    }
    
  4. 然后,我们将创建一个将经度/经度列映射到点的转换:

    toPoint.json
    {
      "type": "AttributesToPointGeometryTransform",
      "latField": "Lat",
      "lngField": "Lon"
    }
    

    以上将上传的任务转换为:

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @toPoint.json \
      "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
    
  5. 现在可以运行导入了,我们将使用以下命令执行它:

    curl -u admin:geoserver -XPOST \
      "http://localhost:8080/geoserver/rest/imports/0"
    
  6. 新图层在PostGIS中创建,并在Geoserver中注册为新图层。

    如果需要将CSV中的功能附加到现有层,则可能会对任务执行PUT请求,将其update模式从“Create”更改为“Append”。改为“替换”将保留该层,但会删除旧内容,并用新上传的内容替换它们。

使用CSV文件的内容替换PostGIS表

要更新 values 包含新内容的层:

  1. 在中创建新的导入 cite:postgis

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @import.json "http://localhost:8080/geoserver/rest/imports"
    

    使用:

    import.json
    {
       "import": {
          "targetWorkspace": {
             "workspace": {
                "name": "cite"
             }
          },
          "targetStore": {
             "dataStore": {
                "name": "postgis"
             }
          }
       }
    }
    
  2. 使用 replace.csv 要创建新任务,请执行以下操作:

    curl -u admin:geoserver -XPOST \
      -F filedata=@replace.csv \
      "http://localhost:8080/geoserver/rest/imports/1/tasks"
    

    CSV文件还有一列:

    replace.csv
    AssetID, SampleTime, Lat, Lon, Value, Status
    1, 2015-01-01T10:00:00, 10.00, 62.00, 15.2, ready
    1, 2015-01-01T11:00:00, 10.10, 62.11, 30.25, recording
    1, 2015-01-01T12:00:00, 10.20, 62.22, 41.2, recording
    1, 2015-01-01T13:00:00, 10.31, 62.33, 27.6, recording
    1, 2015-01-01T14:00:00, 10.41, 62.45, 12, complete
    
  3. 将任务更新为“替换”并提供SRS信息:

    curl -u admin:geoserver -XPUT -H "Content-type: application/json" \
      -d @taskUpdate.json \
      "http://localhost:8080/geoserver/rest/imports/1/tasks/0"
    

    使用:

    taskUpdate.json
    {
       "task": {
           "updateMode": "REPLACE",
           "layer" : {
              "name": "values",
              "title": "values",
              "nativeName": "values",
              "srs": "EPSG:4326"
           }
       }
    }
    
  4. 更新转换以提供几何列:

    curl -u admin:geoserver -XPOST -H "Content-type: application/json" \
      -d @toPoint.json \
      "http://localhost:8080/geoserver/rest/imports/1/tasks/0/transforms"
    

    使用:

    toPoint.json
    {
      "type": "AttributesToPointGeometryTransform",
      "latField": "Lat",
      "lngField": "Lon"
    }
    
  5. 仔细检查导入:

    curl -u admin:geoserver -XGET \
      http://localhost:8080/geoserver/rest/imports/1.json
    
    {
      "import": {
        "id": 2,
        "href": "http://localhost:8080/geoserver/rest/imports/1",
        "state": "PENDING",
        "archive": false,
        "targetWorkspace": {
          "workspace": {
            "name": "cite",
            "isolated": false
          }
        },
        "targetStore": {
          "dataStore": {
            "name": "postgis",
            "type": "PostGIS"
          }
        },
        "tasks": [
          {
            "id": 0,
            "href": "http://localhost:8080/geoserver/rest/imports/1/tasks/0",
            "state": "READY"
          }
        ]
      }
    }
    

    任务:

    curl -u admin:geoserver -XGET \
      http://localhost:8080/geoserver/rest/imports/1/tasks/0.json
    
    {
      "task": {
        "id": 0,
        "href": "http://localhost:8080/geoserver/rest/imports/2/tasks/0",
        "state": "READY",
        "updateMode": "REPLACE",
        "data": {
          "type": "file",
          "format": "CSV",
          "file": "replace.csv"
        },
        "target": {
          "href": "http://localhost:8080/geoserver/rest/imports/2/tasks/0/target",
          "dataStore": {
            "name": "postgis",
            "type": "PostGIS"
          }
        },
        "progress": "http://localhost:8080/geoserver/rest/imports/2/tasks/0/progress",
        "layer": {
          "name": "replace",
          "href": "http://localhost:8080/geoserver/rest/imports/2/tasks/0/layer"
        },
        "transformChain": {
          "type": "vector",
          "transforms": [
            {
              "type": "AttributesToPointGeometryTransform",
              "href": "http://localhost:8080/geoserver/rest/imports/2/tasks/0/transforms/0"
            }
          ]
        }
      }
    }
    

    检查层以确保 name 指示要替换的层,以及 nativeName 指示要替换的表内容:

    curl -u admin:geoserver -XGET \
      http://localhost:8080/geoserver/rest/imports/1/tasks/0/layer.json
    
    {
      "layer": {
        "name": "values",
        "href": "http://localhost:8080/geoserver/rest/imports/1/tasks/0/layer",
        "title": "values",
        "originalName": "replace",
        "nativeName": "replace",
        "srs": "EPSG:4326",
        "bbox": {
          "minx": 0,
          "miny": 0,
          "maxx": -1,
          "maxy": -1
        },
        "attributes": [
          {
            "name": "AssetID",
            "binding": "java.lang.Integer"
          },
          {
            "name": "SampleTime",
            "binding": "java.lang.String"
          },
          {
            "name": "Lat",
            "binding": "java.lang.Double"
          },
          {
            "name": "Lon",
            "binding": "java.lang.Double"
          },
          {
            "name": "Value",
            "binding": "java.lang.Integer"
          }
        ],
        "style": {
          "name": "point",
          "href": "http://localhost:8080/geoserver/rest/imports/1/tasks/0/layer/style"
        }
      }
    }
    

    转型:

    curl -u admin:geoserver -XGET \
      http://localhost:8080/geoserver/rest/imports/1/tasks/0/transforms/0.json
    
  6. 要运行导入,请执行以下操作:

    curl -u admin:geoserver -XPOST \
      "http://localhost:8080/geoserver/rest/imports/1"
    

上传并优化带有地面控制点的geotiff

数据供应商定期提供我们需要在geoserver中配置的geotiff。geotiff通过地面控制点引用,由条纹组织,没有概述。其目的是通过进口商对其进行纠正、优化和发布。

首先,我们将创建一个没有存储区作为目标的空导入:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports"

其中import.json为:

{
   "import": {
      "targetWorkspace": {
         "workspace": {
            "name": "sf"
         }
      }
   }
}

然后,我们将把geotiff文件发布到任务列表,以便为其创建导入任务:

curl -u admin:geoserver -F name=test -F filedata=@box_gcp_fixed.tif "http://localhost:8080/geoserver/rest/imports/0/tasks"

然后,我们将附加转换来校正(gdalwarp)、重新定位(gdal_translate)并将概述(gdaladdo)添加到其中:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @warp.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gtx.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gad.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"

warp.json 是::

{
  "type": "GdalWarpTransform",
  "options": [ "-t_srs", "EPSG:4326"]
}

gtx.json 是::

{
  "type": "GdalTranslateTransform",
  "options": [ "-co", "TILED=YES", "-co", "BLOCKXSIZE=512", "-co", "BLOCKYSIZE=512"]
}

gad.json 是::

{
  "type": "GdalAddoTransform",
  "options": [ "-r", "average"],
  "levels" : [2, 4, 8, 16]
}

现在导入已准备好运行,我们将使用以下命令执行它:

curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0"

新的一层 box_gcp_fixed 层将出现在GeoServer中,其中一个底层GeoTiff文件已准备好用于web服务。

在现有马赛克中添加新颗粒

数据供应商定期提供新的基于时间的图像,我们需要将其添加到现有的地理服务器马赛克中。图像采用geotiff格式,缺乏良好的内部结构,需要将其与其他图像对齐。

首先,我们将创建一个指示颗粒所在位置的导入,以及目标存储:

curl-u admin:geoserver-xpost-h“内容类型:application/json”-d@import.json“http://localhost:8080/geoserver/rest/imports”

其中import.json为:

{
   "import": {
      "targetWorkspace": {
         "workspace": {
            "name": "topp"
         }
      },
      "data": {
        "type": "file",
        "file": "/home/aaime/devel/gisData/ndimensional/data/world/world.200407.3x5400x2700.tiff"
      },
      "targetStore": {
         "dataStore": {
            "name": "bluemarble"
         }
      }
   }
}

然后,我们将附加转换以使文件与马赛克的其余部分协调起来:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gtx.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gad.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"

gtx.json 是::

{
  "type": "GdalTranslateTransform",
  "options": [ "-co", "TILED=YES"]
}

gad.json 是::

{
  "type": "GdalAddoTransform",
  "options": [ "-r", "average"],
  "levels" : [2, 4, 8, 16, 32, 64, 128]
}

现在导入已准备好运行,我们将使用以下命令执行它:

curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0"

新的颗粒将被摄取到马赛克中,因此将可用于基于时间的请求。

从远程服务器异步获取和导入数据

我们假设一个远程的ftp服务器包含多个shapefile,我们需要将它们作为新的层导入Geoserver中。文件很大,而且服务器的带宽比客户端好得多,所以最好是Geoserver自己执行数据获取。

在这种情况下,异步请求使用 remote 数据最适合:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports?async=true"

其中import.json为:

{
   "import": {
      "targetWorkspace": {
         "workspace": {
            "name": "topp"
         }
      },
      "data": {
        "type": "remote",
        "location": "ftp://myserver/data/bc_shapefiles",
        "username": "dan",
        "password": "secret"
      }
   }
}

请求将立即返回“in it”状态的导入上下文,并且在获取数据和创建任务之前,它将保持这种状态。一旦状态切换到“挂起”,导入将准备好执行。由于要处理的形状文件很多,因此导入运行也将在异步模式下完成::

curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0?async=true"

在这种情况下,响应也将立即返回,并且进度可以作为处于导入切换状态的任务来跟踪。

通过单个请求导入和优化大型图像

一个大的映像不时出现在已安装的磁盘共享上,需要对该映像进行优化,并作为新的层导入到geoserver中。由于源很大,我们需要将其复制到data dir所在的本地磁盘上,“远程”数据是该作业的正确工具,因此建议异步执行以避免等待可能较大的命令。在这种情况下,请求还将包含“exec=true”参数,以强制导入程序立即执行命令。

然后请求将如下所示:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports?async=true&exec=true"

其中import.json为:

{
  "import": {
    "targetWorkspace": {
      "workspace": {
        "name": "topp"
      }
    },
    "data": {
      "type": "remote",
      "location": "\/mnt\/remoteDisk\/bluemarble.tiff"
    },
    "transforms": [
      {
        "type": "GdalTranslateTransform",
        "options": [
          "-co", "TILED=YES",
          "-co", "COMPRESS=JPEG",
          "-co", "JPEG_QUALITY=85",
          "-co", "PHOTOMETRIC=YCBCR"
        ]
      },
      {
        "type": "GdalAddoTransform",
        "options": [
          "-r",
          "average",
          "--config", "COMPRESS_OVERVIEW", "JPEG",
          "--config", "PHOTOMETRIC_OVERVIEW", "YCBCR"
        ],
        "levels": [ 2, 4, 8, 16, 32, 64 ]
      }
    ]
  }
}

如果请求是异步的,客户端将不得不轮询服务器,以检查初始化和执行是否成功。

Previous: 休息API
Next: INSPIRE