如何通过REST API在GeoServer中创建WMS图层?

时间:2019-12-04 19:50:59

标签: postgresql rest geoserver

PostgreSQL中,有一个名为geo的方案。在该方案内部,我有一个表,该表的列的数据类型为geometry

我是GeoServer的新手,想知道如何通过WMS用该远程PostgreSQL数据库的数据创建REST API层吗?根据{{​​3}},我需要先创建工作区和数据存储,对吗?我有点困惑。应该采取什么行动顺序?我将不胜感激!

卷曲请求的结果: documentation

2 个答案:

答案 0 :(得分:1)

REST API的工作方式与GUI完全相同,因此该过程是您可以选择创建新的工作区或使用现有的工作区,然后创建商店< / strong>在工作区中,然后从商店中创建图层。任何图层都将自动成为WMS图层。

  1. Create a new PostGIS store,生成包含连接详细信息的文件:
      <dataStore>
        <name>nyc</name>
        <connectionParameters>
          <host>localhost</host>
          <port>5432</port>
          <database>nyc</database>
          <user>bob</user>
          <passwd>postgres</passwd>
          <dbtype>postgis</dbtype>
        </connectionParameters>
      </dataStore>

并将其发布到REST端点

curl -v -u admin:geoserver -XPOST -T <file.xml> -H "Content-type: text/xml"
    http://localhost:8080/geoserver/rest/workspaces/<WORKSPACENAME>/datastores
  1. 然后publish the table as a layer
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>buildings</name></featureType>" http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes

答案 1 :(得分:1)

可选。 从现有的PostGIS存储中发布表。 在php curl上。

function curl_post($url,$params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD,"user:password");//--> on geoserver.
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


$response = curl_exec($ch);

curl_close ($ch);
return $response;
}

 //- table_name      : xxx 
 //- work_space_name : your_workspace 
 //- store_name    : dbtest


$layer_name = "xxx";

$params ="
    <featureType>
      <name>".$layer_name."</name>
      
      <nativeName>".$layer_name."</nativeName>
      
      <title>".$layer_name."</title>
      
      <keywords>
        <string>".$layer_name."</string>
        <string>features</string>
      </keywords>
      
      <srs>EPSG:3857</srs>
      
      <nativeBoundingBox>
        <minx>1.0836244E7</minx>
        <maxx>1.1759454E7</maxx>
        <miny>625842.375</miny>
        <maxy>2328151.75</maxy>
      </nativeBoundingBox>
      
      <latLonBoundingBox>
        <minx>97.34363607648459</minx>
        <maxx>105.63697261100442</maxx>
        <miny>5.613037739416236</miny>
        <maxy>20.464604971116074</maxy>
        
      </latLonBoundingBox>
      
      <projectionPolicy>FORCE_DECLARED</projectionPolicy>
      <enabled>true</enabled>
      <metadata>
        <entry key=\"cachingEnabled\">false</entry>
      </metadata>
      <maxFeatures>0</maxFeatures>
      <numDecimals>0</numDecimals>
    </featureType>
";

$str_url = "http://xxx.co.uk/geoserver/rest/workspaces/**your_workspace**/datastores/**your_data_store**/featuretypes";

$rs = curl_post($str_url, $params);