drought/geoserver_rest_api.py

53 lines
1.8 KiB
Python

import requests
if __name__ == '__main__':
print('let us go')
# r = requests.get('http://210.77.68.250:8080/geoserver/rest/layergroups.json',
# auth=('admin', 'geoserver'))
# print(r.json())
headers = {'content-type': 'application/json'}
payload = {
'coverageStore': {
'name': 'bj_sample_tiff',
'workspace': 'baoji',
'type': 'GeoTIFF',
'enabled': 'true',
'url': 'file:baoji/sample/Baojishi_Cotton_2016_1KM.tif'
}
}
r = requests.post('http://210.77.68.250:8080/geoserver/rest/workspaces/baoji/coveragestores',
json=payload,
auth=('admin', 'geoserver'))
print(r.status_code)
print(r.text)
r.raise_for_status()
coverage_payload = {
'coverage': {
'title': 'bj_sample_tiff',
'name': 'bj_sample_tiff',
'nativeName':'Baojishi_Cotton_2016_1KM',
"srs": "EPSG:4326",
},
}
r = requests.post(
'http://210.77.68.250:8080/geoserver/rest/workspaces/baoji/coveragestores/bj_sample_tiff/coverages',
json=coverage_payload,
headers=headers,
auth=('admin', 'geoserver'))
print(r.status_code)
print(r.text)
# payload = {'recalculate': 'nativebbox,latlonbbox'}
# r = requests.get('http://210.77.68.250:8080/geoserver/rest/workspaces/drought/coveragestores/197902/coverages/197902.json', auth=('admin', 'geoserver'))
# print(r.json())
# r = requests.get('http://210.77.68.250:8080/geoserver/rest/workspaces/drought/styles/temperature.json',
# auth=('admin', 'geoserver'))
# print(r.json())
# result = r.json()
# for s in result['styles']['style']:
# print(s['name'])