Stores¶
Note:
You can find the official example at https://docs.geoserver.org/2.25.x/en/user/rest/stores.html
from pathlib import Path
from geoserver import GeoServer
from geoserver.exceptions import GeoServerError
GeoServer Connection¶
Connect to the running GeoServer instance and create a workspace and a store.
# Setup the geoserver instance
geoserver = GeoServer(
service_url="http://localhost:8080/geoserver",
username="admin",
password="geoserver",
)
Clean up the workspace and store after running the examples.
if geoserver.workspace_exists("demo"):
geoserver.delete_workspace("demo", recurse=True)
geoserver.create_workspace_from_name("demo")
'Created'
Config¶
We'll set up the configuration for the notebook:
# Directory containing sample data
DATA_DIR = Path("../tests/data")
assert DATA_DIR.exists(), f"The directory {DATA_DIR} does not exist."
Uploading a shapefile¶
Create a new store buildings by uploading a shapefile buildings.zip.
file_path = DATA_DIR / "vectors" / "buildings.zip"
assert file_path.exists(), f"The file {file_path.as_posix()!r} does not exist."
geoserver.upload_data_store(file=file_path, workspace="demo")
'Created'
Retrieving a store¶
Retrieve information about a specific store. You can specify the response format as JSON or XML using the format parameter.
geoserver.get_data_store(name="buildings", workspace="demo")
{'dataStore': {'name': 'buildings',
'type': 'Shapefile',
'enabled': True,
'workspace': {'name': 'demo',
'href': 'http://localhost:8080/geoserver/rest/workspaces/demo.json'},
'connectionParameters': {'entry': [{'@key': 'namespace', '$': 'http://demo'},
{'@key': 'url',
'$': 'file:/opt/geoserver/data_dir/data/demo/buildings/'}]},
'_default': False,
'dateCreated': '2024-06-12 22:36:06.144 UTC',
'disableOnConnFailure': False,
'featureTypes': 'http://localhost:8080/geoserver/rest/workspaces/demo/datastores/buildings/featuretypes.json'}}
xml = geoserver.get_data_store(name="buildings", workspace="demo", format="xml")
print(xml)
<dataStore>
<name>buildings</name>
<type>Shapefile</type>
<enabled>true</enabled>
<workspace>
<name>demo</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/demo.xml" type="application/xml"/>
</workspace>
<connectionParameters>
<entry key="namespace">http://demo</entry>
<entry key="url">file:/opt/geoserver/data_dir/data/demo/buildings/</entry>
</connectionParameters>
<__default>false</__default>
<dateCreated>2024-06-12 22:36:06.144 UTC</dateCreated>
<disableOnConnFailure>false</disableOnConnFailure>
<featureTypes>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/demo/datastores/buildings/featuretypes.xml" type="application/xml"/>
</featureTypes>
</dataStore>
Listing feature type details¶
By default when a shapefile is uploaded, a feature type is automatically created. This is true only if you use the upload_data_store method. If you use the create_data_store method, you will have to create the feature type manually.
geoserver.get_feature_type(name="buildings", workspace="demo")
{'featureType': {'name': 'buildings',
'nativeName': 'buildings',
'namespace': {'name': 'demo',
'href': 'http://localhost:8080/geoserver/rest/namespaces/demo.json'},
'title': 'buildings',
'keywords': {'string': ['features', 'buildings']},
'nativeCRS': 'GEOGCS["GCS_WGS_1984", \n DATUM["D_WGS_1984", \n SPHEROID["WGS_1984", 6378137.0, 298.257223563]], \n PRIMEM["Greenwich", 0.0], \n UNIT["degree", 0.017453292519943295], \n AXIS["Longitude", EAST], \n AXIS["Latitude", NORTH]]',
'srs': 'EPSG:4326',
'nativeBoundingBox': {'minx': -1.5132908,
'maxx': -1.5094796,
'miny': 48.6349371,
'maxy': 48.636897,
'crs': 'EPSG:4326'},
'latLonBoundingBox': {'minx': -1.5132908,
'maxx': -1.5094796,
'miny': 48.6349371,
'maxy': 48.636897,
'crs': 'EPSG:4326'},
'projectionPolicy': 'FORCE_DECLARED',
'enabled': True,
'store': {'@class': 'dataStore',
'name': 'demo:buildings',
'href': 'http://localhost:8080/geoserver/rest/workspaces/demo/datastores/buildings.json'},
'serviceConfiguration': False,
'simpleConversionEnabled': False,
'maxFeatures': 0,
'numDecimals': 0,
'padWithZeros': False,
'forcedDecimal': False,
'overridingServiceSRS': False,
'skipNumberMatched': False,
'circularArcPresent': False,
'attributes': {'attribute': [{'name': 'the_geom',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'org.locationtech.jts.geom.MultiPolygon'},
{'name': 'id',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': '@id',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'access',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'addr_city',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'addr_postc',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'addr_stree',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'alt_name',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'amenity',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'area',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'barrier',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'building',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'building_l',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'building_m',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'building_p',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'check_date',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.util.Date',
'length': 8},
{'name': 'contact_em',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'contact_fa',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'contact_ph',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'contact_we',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'content',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'cuisine',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'denominati',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'descriptio',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'email',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'entrance',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'fax',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'fee',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'fire_stati',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'fixme',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'heritage',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'heritage_o',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'highway',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'historic',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'image',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'indoor',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'internet_a',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'internet_1',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'layer',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'level',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'location',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'man_made',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'mhs_inscri',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.util.Date',
'length': 8},
{'name': 'name',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'name_cs',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'name_en',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'name_fr',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'note',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'official_n',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'opening_ho',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'operator',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'payment_ap',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'payment_co',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'payment_cr',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'phone',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'ref_FR_CEF',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'ref_FR_SDI',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'ref_mhs',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'religion',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'room',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'rooms',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'service_ti',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'short_name',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'source',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': '@relations',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'source_her',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'stars',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'start_date',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'tourism',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'tower_cons',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'tower_type',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'type',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'was_amenit',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'was_name',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'website',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'wheelchair',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'wikidata',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254},
{'name': 'wikipedia',
'minOccurs': 0,
'maxOccurs': 1,
'nillable': True,
'binding': 'java.lang.String',
'length': 254}]}}}
Adding an existing shapefile¶
Publish a shapefile that already exists on the server without needing to be uploaded. We will use the roads store that we created earlier.
geoserver.upload_data_store(
file="file:/opt/geoserver/data_dir/data/demo/buildings/buildings.shp",
workspace="demo",
store="buildings_v2",
filename="buildings_v2.shp",
)
Adding a directory of existing shapefiles¶
Create a store containing a directory of shapefiles that already exists on the server without needing to be uploaded.
geoserver.upload_data_store(
file="file:/opt/geoserver/data_dir/data/demo",
name="buildings_v2",
workspace="demo",
configure="all"
)
Adding a PostGIS database store¶
Add an existing PostGIS database as a new store. The connection parameters available from the docker-compose.yml file are:
- host:
postgis - port:
5432 - database:
db - user:
admin - password:
postgres - dbtype:
postgis
Note:
This example assumes that a PostGIS database nameddbis present on the local system and is accessible by the useradmin.
# Using JSON format
body = {
"dataStore": {
"name": "db",
"description": "PostGIS connection",
"connectionParameters": {
"host": "postgis",
"port": "5432",
"database": "db",
"user": "admin",
"passwd": "postgres",
"dbtype": "postgis",
"schema": "public",
"Expose primary keys": "true",
"Loose bbox": "true",
"Estimated extends": "true",
"fetch size": "1000",
"Max open prepared statements": "50",
"preparedStatements": "false",
"validate connections": "true",
"validate connections on borrow": "true",
"validate connections on return": "true",
"Connection timeout": "20",
"Eviction run periodicity": "3600",
"Min evictable idle time": "300",
"Max active": "50",
"Max idle": "10",
"Max wait": "10000",
"Test on borrow": "true",
"Test while idle": "true",
"Time between eviction runs": "60000",
}
}
}
# Using XML format
body = """
<dataStore>
<name>db</name>
<description>PostGIS database</description>
<connectionParameters>
<entry key="host">postgis</entry>
<entry key="port">5432</entry>
<entry key="database">db</entry>
<entry key="user">admin</entry>
<entry key="passwd">postgres</entry>
<entry key="dbtype">postgis</entry>
<entry key="schema">public</entry>
<entry key="Expose primary keys">true</entry>
<entry key="Loose bbox">true</entry>
<entry key="Estimated extends">true</entry>
<entry key="fetch size">1000</entry>
<entry key="Max open prepared statements">50</entry>
<entry key="preparedStatements">false</entry>
<entry key="validate connections">true</entry>
<entry key="validate connections on borrow">true</entry>
<entry key="validate connections on return">true</entry>
<entry key="Connection timeout">20</entry>
<entry key="Eviction run periodicity">3600</entry>
<entry key="Min evictable idle time">300</entry>
<entry key="Max active">50</entry>
<entry key="Max idle">10</entry>
<entry key="Max wait">10000</entry>
<entry key="Test on borrow">true</entry>
<entry key="Test while idle">true</entry>
<entry key="Time between eviction runs">60000</entry>
</connectionParameters>
</dataStore>
"""
geoserver.create_data_store(body=body, workspace="demo")
'Created'
Listing a PostGIS database store details¶
Retrieve information about a PostGIS store.
xml = geoserver.get_data_store(name="db", workspace="demo", format="xml")
print(xml)
<dataStore>
<name>db</name>
<description>PostGIS database</description>
<type>PostGIS</type>
<enabled>true</enabled>
<workspace>
<name>demo</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/demo.xml" type="application/xml"/>
</workspace>
<connectionParameters>
<entry key="schema">public</entry>
<entry key="Max idle">10</entry>
<entry key="Max open prepared statements">50</entry>
<entry key="preparedStatements">false</entry>
<entry key="database">db</entry>
<entry key="validate connections on borrow">true</entry>
<entry key="host">postgis</entry>
<entry key="Loose bbox">true</entry>
<entry key="Min evictable idle time">300</entry>
<entry key="Estimated extends">true</entry>
<entry key="fetch size">1000</entry>
<entry key="Eviction run periodicity">3600</entry>
<entry key="Expose primary keys">true</entry>
<entry key="validate connections">true</entry>
<entry key="Max wait">10000</entry>
<entry key="Connection timeout">20</entry>
<entry key="Time between eviction runs">60000</entry>
<entry key="validate connections on return">true</entry>
<entry key="Max active">50</entry>
<entry key="port">5432</entry>
<entry key="passwd">crypt2:lxZ7pgVY09l9utgaQLLpL1einM41hhp3CAkpZoU7alc=</entry>
<entry key="dbtype">postgis</entry>
<entry key="namespace">http://demo</entry>
<entry key="Test while idle">true</entry>
<entry key="user">admin</entry>
<entry key="Test on borrow">true</entry>
</connectionParameters>
<__default>false</__default>
<dateCreated>2024-06-12 22:36:06.227 UTC</dateCreated>
<disableOnConnFailure>false</disableOnConnFailure>
<featureTypes>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/demo/datastores/db/featuretypes.xml" type="application/xml"/>
</featureTypes>
</dataStore>
Publishing a table from an existing PostGIS store¶
Publish a new featuretype from a PostGIS store table buildings.
Note:
This example assumes the table has already been created. You can create the table using the following command:ogr2ogr -f PostgreSQL PG:"host=localhost port=5432 user=admin dbname=db password=postgres" ../data/vectors/landuse.shp -nlt PROMOTE_TO_MULTI -lco OVERWRITE=YES
!ogr2ogr -f PostgreSQL PG:"host=localhost port=5432 user=admin dbname=db password=postgres" ../tests/data/vectors/landuse.shp -nlt PROMOTE_TO_MULTI -lco OVERWRITE=YES
Warning 1: Layer creation options ignored since an existing layer is
being appended to.
# Using JSON format
body = {
"featureType": {
"name": "landuse",
"title": "landuse",
"advertised": "true",
}
}
# Using XML format
body = """
<featureType>
<name>landuse</name>
<title>landuse</title>
<advertised>true</advertised>
</featureType>
"""
geoserver.create_feature_type(body=body, workspace="demo", store="db")
'Created'
Note:
This layer can viewed with a WMS GetMap request at the following URL:http://localhost:8080/geoserver/wms/reflect?layers=demo:landuse
Creating a PostGIS table¶
Create a new featuretype in GeoServer and simultaneously create a table in PostGIS.
Note:
Thedbstore must be a PostGIS store for this to succeed.
# Using XML format
body = """
<featureType>
<name>annotations</name>
<nativeName>annotations</nativeName>
<title>Annotations</title>
<srs>EPSG:4326</srs>
<attributes>
<attribute>
<name>the_geom</name>
<binding>org.locationtech.jts.geom.Point</binding>
</attribute>
<attribute>
<name>description</name>
<binding>java.lang.String</binding>
</attribute>
<attribute>
<name>timestamp</name>
<binding>java.util.Date</binding>
</attribute>
</attributes>
</featureType>
"""
try:
geoserver.create_feature_type(body=body, workspace="demo", store="db")
except GeoServerError as e:
if e.status_code == 500:
print(f"[WARNING] Could not add feature_type: {e}")
print("[WARNING] It is possible that the feature_type already exists in the database.")
[WARNING] Could not add feature_type: Error 500: [WARNING] It is possible that the feature_type already exists in the database.
A new and empty table named annotations in the db database will be created as well.
Adding an external WMTS Store¶
Create a new WMTS store Basemap-Nat-Geo-Datastore.
# Using JSON format
body = {
"wmtsStore": {
"name": "basemap-nat-geo-datastore",
"description": "esri-street-map",
"capabilitiesURL": "https://services.arcgisonline.com/arcgis/rest/services/NatGeo_World_Map/MapServer/WMTS/1.0.0/WMTSCapabilities.xml",
"type": "WMTS",
}
}
# Using XML format
body = """
<wmtsStore>
<name>basemap-nat-geo-datastore</name>
<description>esri-street-map</description>
<capabilitiesURL>https://services.arcgisonline.com/arcgis/rest/services/NatGeo_World_Map/MapServer/WMTS/1.0.0/WMTSCapabilities.xml</capabilitiesURL>
<type>WMTS</type>
</wmtsStore>
"""
geoserver.create_wmts_store(body=body, workspace="demo")
'Created'
geoserver.get_wmts_layers(workspace="demo")
{'layers': {'layer': [{'name': 'buildings',
'href': 'http://localhost:8080/geoserver/rest/workspaces/demo/layers/buildings.json'},
{'name': 'landuse',
'href': 'http://localhost:8080/geoserver/rest/workspaces/demo/layers/landuse.json'}]}}
Adding an external WMTS Layer¶
Publish a new WMTS Layer NatGeo_World_Map from the WMTS store Basemap-Nat-Geo-Datastore.
# Using JSON format
body = {
"wmtsLayer": {
"name": "NatGeo_World_Map",
}
}
# Using XML format
body = """
<wmtsLayer>
<name>NatGeo_World_Map</name>
</wmtsLayer>
"""
geoserver.create_wmts_layer(body=body, workspace="demo", store="basemap-nat-geo-datastore")
'Created'