Geoserver REST API功能解析

Geoserver REST API功能解析

1.使用Rest创建工作区

  • 创建工作区
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<workspace><name>YYYYYYYY</name></workspace>" http://localhost:8888/geoserver/rest/workspaces
  • 加上url对其进行规范化(推荐)
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<namespace><prefix>PostGis_pro</prefix><uri>http://localhost:8888/pro</uri></namespace>" http://localhost:8888/geoserver/rest/namespaces

删除工作区

curl -v -u admin:geoserver -XDELETE -H "Content-type: text/xml" http://localhost:8888/geoserver/rest/workspaces/YYYYYYYY

2.使用Rest展示工作区列表

curl -u admin:geoserver -v -XGET -H 'Accept: text/xml' http://localhost:8888/geoserver/rest/workspaces

解析Curl

curl -u admin:geoserver -v -XGET -H 'Accept: text/xml' http://localhost:8888/geoserver/rest/workspaces //直接解析rest下的workspaces

返回的数据是json(返回展示在控制台中,后期使用需将其整理)

{"workspaces":{"workspace":[ {"name":"newWorkspace","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/newWorkspace.json"}, {"name":"NNUC","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/NNUC.json"}, {"name":"cite","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/cite.json"}, {"name":"tiger","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/tiger.json"}, {"name":"nurc","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/nurc.json"}, {"name":"sde","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/sde.json"}, {"name":"it.geosolutions","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/it.geosolutions.json"}, {"name":"topp","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/topp.json"}, {"name":"sf","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/sf.json"}, {"name":"POST","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/POST.json"}, {"name":"dsss","href":"http:\/\/localhost:8888\/geoserver\/rest\/workspaces\/dsss.json"} ]}}* Connection #1 to host localhost left intact

3.使用Rest返回图层列表(对应工作区)

curl -u admin:geoserver -XGET http://localhost:8888/geoserver/rest/layers.json

返回的依旧是json对象(我们需对name进行获取)

 

{"name":"NNUC:the_whole_world","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/NNUC%3Athe_whole_world.json"}, {"name":"cite:SX_SJXZQ","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/cite%3ASX_SJXZQ.json"}, {"name":"cite:ne_10m_admin_0_countries","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/cite%3Ane_10m_admin_0_countries.json"}, {"name":"tiger:giant_polygon","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/tiger%3Agiant_polygon.json"}, {"name":"tiger:poi","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/tiger%3Apoi.json"}, {"name":"tiger:poly_landmarks","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/tiger%3Apoly_landmarks.json"}, {"name":"tiger:tiger_roads","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/tiger%3Atiger_roads.json"}, {"name":"nurc:Arc_Sample","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/nurc%3AArc_Sample.json"}, {"name":"nurc:Img_Sample","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/nurc%3AImg_Sample.json"}, {"name":"nurc:Pk50095","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/nurc%3APk50095.json"}, {"name":"nurc:mosaic","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/nurc%3Amosaic.json"}, {"name":"topp:states","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/topp%3Astates.json"}, {"name":"topp:tasmania_cities","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/topp%3Atasmania_cities.json"}, {"name":"topp:tasmania_roads","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/topp%3Atasmania_roads.json"}, {"name":"topp:tasmania_state_boundaries","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/topp%3Atasmania_state_boundaries.json"}, {"name":"topp:tasmania_water_bodies","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/topp%3Atasmania_water_bodies.json"}, {"name":"sf:archsites","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Aarchsites.json"}, {"name":"sf:bugsites","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Abugsites.json"}, {"name":"sf:restricted","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Arestricted.json"}, {"name":"sf:roads","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Aroads.json"}, {"name":"sf:sfdem","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Asfdem.json"}, {"name":"sf:streams","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/sf%3Astreams.json"}, {"name":"POST:gis_osm_buildings_a_free_1","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/POST%3Agis_osm_buildings_a_free_1.json"}, {"name":"POST:ne_10m_admin_0_countries","href":"http:\/\/localhost:8888\/geoserver\/rest\/layers\/POST%3Ane_10m_admin_0_countries.json"}] }}* Connection #1 to host localhost left intact

4.使用Rest创建图层组

curl指令

curl -v -u admin:geoserver -XPOST -d @C:\Users\111111\Desktop\shapefile_test\layers.xml -H "Content-type: text/xml" http://localhost:8888/geoserver/rest/layergroups

Xml(XML可进行细化,内部参数可以增加,未仔细研究。)

<layerGroup> <name>HHHHHHHHH</name> //创建图层组的name <layers> //图层组包括的图层 <layer>VGEs_CJHH</layer> <layer>the_whole_world</layer> </layers> <styles> //对应的图层类型 <style>line</style> <style>polygon</style> </styles> </layerGroup>

结果

5.使用Rest删除图层组

curl -v -u admin:geoserver -XDELETE -H "Content-type: text/xml" http://localhost:8888/geoserver/rest/layergroups/HAHA

6.在已有图层组新增/删除图层

暂未实现。

如果重复在已有图层上传,则会覆盖内容。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值