Skip to content

Commit 8fd01b3

Browse files
committed
restored notes and other comments
1 parent 57d9035 commit 8fd01b3

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

geo/Geoserver.py

+152
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ def _requests(self,
174174
elif method.lower() == "delete":
175175
return requests.delete(url, auth=(self.username, self.password), **kwargs, **self.request_options)
176176

177+
# _______________________________________________________________________________________________
178+
#
179+
# GEOSERVER AND SERVER SPECIFIC METHODS
180+
# _______________________________________________________________________________________________
181+
#
182+
177183
def get_manifest(self):
178184
"""
179185
Returns the manifest of the GeoServer. The manifest is a JSON of all the loaded JARs on the GeoServer server.
@@ -272,6 +278,12 @@ def reset(self):
272278
else:
273279
raise GeoserverException(r.status_code, r.content)
274280

281+
# _______________________________________________________________________________________________
282+
#
283+
# WORKSPACES
284+
# _______________________________________________________________________________________________
285+
#
286+
275287
def get_default_workspace(self):
276288
"""
277289
Returns the default workspace.
@@ -407,6 +419,12 @@ def delete_workspace(self, workspace: str):
407419
else:
408420
raise GeoserverException(r.status_code, r.content)
409421

422+
# _______________________________________________________________________________________________
423+
#
424+
# DATASTORES
425+
# _______________________________________________________________________________________________
426+
#
427+
410428
def get_datastore(self, store_name: str, workspace: Optional[str] = None):
411429
"""
412430
Return the data store in a given workspace. If workspace is not provided, it will take the default workspace.
@@ -463,6 +481,12 @@ def get_datastores(self, workspace: Optional[str] = None):
463481
else:
464482
raise GeoserverException(r.status_code, r.content)
465483

484+
# _______________________________________________________________________________________________
485+
#
486+
# COVERAGE STORES
487+
# _______________________________________________________________________________________________
488+
#
489+
466490
def get_coveragestore(
467491
self, coveragestore_name: str, workspace: Optional[str] = None
468492
):
@@ -546,6 +570,10 @@ def create_coveragestore(
546570
-------
547571
dict
548572
The response from the server.
573+
574+
Notes
575+
-----
576+
the path to the file and file_type indicating it is a geotiff, arcgrid or other raster type
549577
"""
550578
if path is None:
551579
raise Exception("You must provide the full path to the raster")
@@ -607,6 +635,11 @@ def publish_time_dimension_to_coveragestore(
607635
-------
608636
dict
609637
The response from the server.
638+
639+
Notes
640+
-----
641+
More about time support in geoserver WMS you can read here:
642+
https://docs.geoserver.org/master/en/user/services/wms/time.html
610643
"""
611644
url = "{0}/rest/workspaces/{1}/coveragestores/{2}/coverages/{2}".format(
612645
self.service_url, workspace, store_name
@@ -640,6 +673,12 @@ def publish_time_dimension_to_coveragestore(
640673
else:
641674
raise GeoserverException(r.status_code, r.content)
642675

676+
# _______________________________________________________________________________________________
677+
#
678+
# LAYERS
679+
# _______________________________________________________________________________________________
680+
#
681+
643682
def get_layer(self, layer_name: str, workspace: Optional[str] = None):
644683
"""
645684
Returns the layer by layer name.
@@ -721,6 +760,12 @@ def delete_layer(self, layer_name: str, workspace: Optional[str] = None):
721760
else:
722761
raise GeoserverException(r.status_code, r.content)
723762

763+
# _______________________________________________________________________________________________
764+
#
765+
# LAYER GROUPS
766+
# _______________________________________________________________________________________________
767+
#
768+
724769
def get_layergroups(self, workspace: Optional[str] = None):
725770
"""
726771
Returns all the layer groups from GeoServer. If workspace is None, it will list all the layer groups from GeoServer.
@@ -734,6 +779,10 @@ def get_layergroups(self, workspace: Optional[str] = None):
734779
-------
735780
dict
736781
The list of layer groups.
782+
783+
Notes
784+
-----
785+
If workspace is None, it will list all the layer groups from geoserver.
737786
"""
738787
url = "{}/rest/layergroups".format(self.service_url)
739788

@@ -814,6 +863,12 @@ def create_layergroup(
814863
-------
815864
str
816865
The URL of the created layer group.
866+
867+
Notes
868+
-----
869+
title is a human readable text for the layergroup
870+
abstract_text is a long text, like a brief info about the layergroup
871+
workspace is Optional(Global Layergroups don't need workspace).A layergroup can exist without a workspace.
817872
"""
818873
assert isinstance(name, str), "Name must be of type String:''"
819874
assert isinstance(mode, str), "Mode must be of type String:''"
@@ -1354,6 +1409,12 @@ def _layergroup_definition_from_layers_and_styles(
13541409

13551410
return data
13561411

1412+
# _______________________________________________________________________________________________
1413+
#
1414+
# STYLES
1415+
# _______________________________________________________________________________________________
1416+
#
1417+
13571418
def get_style(self, style_name, workspace: Optional[str] = None):
13581419
"""
13591420
Returns the style by style name.
@@ -1449,6 +1510,13 @@ def upload_style(
14491510
------
14501511
GeoserverException
14511512
If there is an issue uploading the style.
1513+
1514+
Notes
1515+
-----
1516+
The name of the style file will be, sld_name:workspace
1517+
This function will create the style file in a specified workspace.
1518+
`path` can either be the path to the SLD file itself, or a string containing valid XML to be used for the style
1519+
Inputs: path to the sld_file or the contents of an SLD file itself, workspace,
14521520
"""
14531521
if name is None:
14541522
name = os.path.basename(path)
@@ -1541,6 +1609,12 @@ def create_coveragestyle(
15411609
------
15421610
GeoserverException
15431611
If there is an issue creating the style.
1612+
1613+
Notes
1614+
-----
1615+
The name of the style file will be, rasterName:workspace
1616+
This function will dynamically create the style file for raster.
1617+
Inputs: name of file, workspace, cmap_type (two options: values, range), ncolors: determines the number of class, min for minimum value of the raster, max for the max value of raster
15441618
"""
15451619
raster = raster_value(raster_path)
15461620
min_value = raster["min"]
@@ -1633,6 +1707,13 @@ def create_catagorized_featurestyle(
16331707
------
16341708
GeoserverException
16351709
If there is an issue creating the style.
1710+
1711+
Notes
1712+
-----
1713+
1714+
The data type must be point, line or polygon
1715+
Inputs: column_name (based on which column style should be generated), workspace,
1716+
color_or_ramp (color should be provided in hex code or the color ramp name, geom_type(point, line, polygon), outline_color(hex_color))
16361717
"""
16371718
catagorize_xml(column_name, column_distinct_values, color_ramp, geom_type)
16381719

@@ -1702,6 +1783,11 @@ def create_outline_featurestyle(
17021783
------
17031784
GeoserverException
17041785
If there is an issue creating the style.
1786+
1787+
Notes
1788+
-----
1789+
The geometry type must be point, line or polygon
1790+
Inputs: style_name (name of the style file in geoserver), workspace, color (style color)
17051791
"""
17061792
outline_only_xml(color, width, geom_type)
17071793

@@ -1777,6 +1863,12 @@ def create_classified_featurestyle(
17771863
------
17781864
GeoserverException
17791865
If there is an issue creating the style.
1866+
1867+
Notes
1868+
-----
1869+
The data type must be point, line or polygon
1870+
Inputs: column_name (based on which column style should be generated), workspace,
1871+
color_or_ramp (color should be provided in hex code or the color ramp name, geom_type(point, line, polygon), outline_color(hex_color))
17801872
"""
17811873
classified_xml(
17821874
style_name,
@@ -1848,6 +1940,12 @@ def publish_style(
18481940
------
18491941
GeoserverException
18501942
If there is an issue publishing the style.
1943+
1944+
Notes
1945+
-----
1946+
The coverage store will be created automatically as the same name as the raster layer name.
1947+
input parameters: the parameters connecting geoserver (user,password, url and workspace name),
1948+
the path to the file and file_type indicating it is a geotiff, arcgrid or other raster type.
18511949
"""
18521950
headers = {"content-type": "text/xml"}
18531951
url = "{}/rest/layers/{}:{}".format(self.service_url, workspace, layer_name)
@@ -1903,6 +2001,12 @@ def delete_style(self, style_name: str, workspace: Optional[str] = None):
19032001
else:
19042002
raise GeoserverException(r.status_code, r.content)
19052003

2004+
# _______________________________________________________________________________________________
2005+
#
2006+
# FEATURES AND DATASTORES
2007+
# _______________________________________________________________________________________________
2008+
#
2009+
19062010
def create_featurestore(
19072011
self,
19082012
store_name: str,
@@ -2008,6 +2112,10 @@ def create_featurestore(
20082112
------
20092113
GeoserverException
20102114
If there is an issue creating/updating the feature store.
2115+
2116+
Notes
2117+
-----
2118+
After creating feature store, you need to publish it. See the layer publish guidline here: https://geoserver-rest.readthedocs.io/en/latest/how_to_use.html#creating-and-publishing-featurestores-and-featurestore-layers
20112119
"""
20122120
url = "{}/rest/workspaces/{}/datastores".format(self.service_url, workspace)
20132121

@@ -2131,6 +2239,10 @@ def create_datastore(
21312239
------
21322240
GeoserverException
21332241
If there is an issue creating/updating the datastore.
2242+
2243+
Notes
2244+
-----
2245+
If you have PostGIS datastore, please use create_featurestore function
21342246
"""
21352247
if workspace is None:
21362248
workspace = "default"
@@ -2195,6 +2307,10 @@ def create_shp_datastore(
21952307
------
21962308
GeoserverException
21972309
If there is an issue creating the shapefile datastore.
2310+
2311+
Notes
2312+
-----
2313+
The layer name will be assigned according to the shp name
21982314
"""
21992315
if path is None:
22002316
raise Exception("You must provide a full path to shapefile")
@@ -2262,6 +2378,11 @@ def create_gpkg_datastore(
22622378
------
22632379
GeoserverException
22642380
If there is an issue creating the geopackage datastore.
2381+
2382+
Notes
2383+
-----
2384+
The layer name will be assigned according to the layer name in the geopackage.
2385+
If the layer already exist it will be updated.
22652386
"""
22662387
if path is None:
22672388
raise Exception("You must provide a full path to shapefile")
@@ -2338,6 +2459,11 @@ def publish_featurestore(
23382459
------
23392460
GeoserverException
23402461
If there is an issue publishing the featurestore.
2462+
2463+
Notes
2464+
-----
2465+
Only user for postgis vector data
2466+
input parameters: specify the name of the table in the postgis database to be published, specify the store,workspace name, and the Geoserver user name, password and URL
23412467
"""
23422468
if workspace is None:
23432469
workspace = "default"
@@ -2502,6 +2628,26 @@ def publish_featurestore_sqlview(
25022628
------
25032629
GeoserverException
25042630
If there is an issue publishing the SQL view.
2631+
2632+
Notes
2633+
-----
2634+
With regards to SQL view parameters, it is advised to read the relevant section from the geoserver docs:
2635+
https://docs.geoserver.org/main/en/user/data/database/sqlview.html#parameterizing-sql-views
2636+
2637+
An integer-based parameter must have a default value
2638+
2639+
You should be VERY careful with the `regexp_validator`, as it can open you to SQL injection attacks. If you do
2640+
not supply one for a parameter, it will use the geoserver default `^[\w\d\s]+$`.
2641+
2642+
The `parameters` iterable must contain dictionaries with this structure:
2643+
2644+
```
2645+
{
2646+
"name": "<name of parameter (required)>"
2647+
"rexegpValidator": "<string containing regex validator> (optional)"
2648+
"defaultValue" : "<default value of parameter if not specified (required only for non-string parameters)>"
2649+
}
2650+
```
25052651
"""
25062652
if workspace is None:
25072653
workspace = "default"
@@ -2759,6 +2905,12 @@ def delete_coveragestore(
27592905
else:
27602906
raise GeoserverException(r.status_code, r.content)
27612907

2908+
# _______________________________________________________________________________________________
2909+
#
2910+
# USERS AND USERGROUPS
2911+
# _______________________________________________________________________________________________
2912+
#
2913+
27622914
def get_all_users(self, service=None) -> dict:
27632915
"""
27642916
Query all users in the provided user/group service, else default user/group service is queried.

0 commit comments

Comments
 (0)