GeoServer REST发布地图服务

GeoServer REST API支持通过REST接口将shapefile、raster的(image)、数据库中的空间表(如sqlserver spatial、oracle、mysql、postgresql等)发布成服务,本文以C#中调用GeoServer REST API发布一个image(PNG)格式的地图数据(上篇文章有如何使用 C#调用Geoserver REST )

 XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Application.StartupPath + "\\Layer.xml");
                string xml = xmlDoc.InnerXml;

                string url_coveragestores = ConfigObject.Server + "rest/workspaces/QPE/coveragestores/" + name + "/coverages";
                string contentXml_coveragestores = xml;

                contentXml_coveragestores = contentXml_coveragestores.Replace("{gisos_coverage_name}", name);

               

                var response_coveragestores = "";
                try
                {
                    response_coveragestores = _http.CreatePost(url_coveragestores, contentXml_coveragestores, null);
                }
                catch (Exception ex)
                {
                    response_coveragestores = "错误";
                    writeLog("创建Layer " + name + " 出错" + ex.ToString());
                }
                if (response_coveragestores.Length > 0)
                {
                    writeLog("创建Layer " + name + " 出错");
                    return;
                }

                writeLog("创建Layer成功 " + " " + name);
                Thread.Sleep(2000);

Layer.xml是什么? 您看了GeoServer的REST API就会明白需要这个配置,示例如下:

<coverage>
  <name>{gisos_coverage_name}</name>
  <namespace>
    <name>aaa</name>
  </namespace>
  <title>{gisos_coverage_name}</title>
  <description>Generated from WorldImage</description>
  <keywords>
    <string>WCS</string>
    <string>WorldImage</string>
    <string>{gisos_coverage_name}</string>
  </keywords>
  <nativeCRS>
    GEOGCS[&quot;WGS 84&quot;,
    DATUM[&quot;World Geodetic System 1984&quot;,
    SPHEROID[&quot;WGS 84&quot;, 6378137.0, 298.257223563, AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],
    AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],
    PRIMEM[&quot;Greenwich&quot;, 0.0, AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],
    UNIT[&quot;degree&quot;, 0.017453292519943295],
    AXIS[&quot;Geodetic longitude&quot;, EAST],
    AXIS[&quot;Geodetic latitude&quot;, NORTH],
    AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]
  </nativeCRS>
  <srs>EPSG:4326</srs>
  <nativeBoundingBox>
    <minx>102.49954955</minx>
    <maxx>105.20224955</maxx>
    <miny>34.66095045</miny>
    <maxy>37.36365045</maxy>
    <crs>EPSG:4326</crs>
  </nativeBoundingBox>
  <latLonBoundingBox>
    <minx>102.49954955</minx>
    <maxx>105.20224955</maxx>
    <miny>34.66095045</miny>
    <maxy>37.36365045</maxy>
    <crs>EPSG:4326</crs>
  </latLonBoundingBox>
  <projectionPolicy>REPROJECT_TO_DECLARED</projectionPolicy>
  <enabled>true</enabled>
  <metadata>
    <entry key="cachingEnabled">false</entry>
    <entry key="dirName">chn-landsat_Chn-landsat1</entry>
  </metadata>
  <store class="coverageStore">
    <name>{gisos_coverage_name}</name>
  </store>
  <nativeFormat>WorldImage</nativeFormat>
  <grid dimension="2">
    <range>
      <low>0 0</low>
      <high>2030 1695</high>
    </range>
    <transform>
      <scaleX>0.033966</scaleX>
      <scaleY>-0.033966</scaleY>
      <shearX>0.0</shearX>
      <shearX>0.0</shearX>
      <translateX>68.8883054563</translateX>
      <translateY>59.7692991445</translateY>
    </transform>
    <crs>EPSG:4326</crs>
  </grid>
  <supportedFormats>
    <string>GEOTIFF</string>
    <string>GIF</string>
    <string>PNG</string>
    <string>JPEG</string>
    <string>TIFF</string>
  </supportedFormats>
  <interpolationMethods>
    <string>bilinear</string>
    <string>bicubic</string>
  </interpolationMethods>
  <dimensions>
    <coverageDimension>
      <name>RED_BAND</name>
      <description>GridSampleDimension[-Infinity,Infinity]</description>
    </coverageDimension>
    <coverageDimension>
      <name>GREEN_BAND</name>
      <description>GridSampleDimension[-Infinity,Infinity]</description>
    </coverageDimension>
    <coverageDimension>
      <name>BLUE_BAND</name>
      <description>GridSampleDimension[-Infinity,Infinity]</description>
    </coverageDimension>
  </dimensions>
  <requestSRS>
    <string>EPSG:4326</string>
  </requestSRS>
  <responseSRS>
    <string>EPSG:4326</string>
  </responseSRS>
</coverage>

 

 

 

发布之后访问

 

posted @ 2016-08-04 00:11  GISMaster  阅读(2904)  评论(0)    收藏  举报