@@ -1822,6 +1822,65 @@ def create_shp_datastore(
1822
1822
else :
1823
1823
raise GeoserverException (r .status_code , r .content )
1824
1824
1825
+ def create_gpkg_datastore (
1826
+ self ,
1827
+ path : str ,
1828
+ store_name : Optional [str ] = None ,
1829
+ workspace : Optional [str ] = None ,
1830
+ file_extension : str = "gpkg" ,
1831
+ ):
1832
+ """
1833
+ Create datastore for a geopackage.
1834
+
1835
+ Parameters
1836
+ ----------
1837
+ path : str
1838
+ Path to the geopackage file.
1839
+ store_name : str, optional
1840
+ Name of store to be created. If None, parses from the filename.
1841
+ workspace: str, optional
1842
+ Name of workspace to be used. Default: "default".
1843
+ file_extension : str
1844
+
1845
+ Notes
1846
+ -----
1847
+ The layer name will be assigned according to the layer name in the geopackage.
1848
+ If the layer already exist it will be updated.
1849
+ """
1850
+
1851
+ if path is None :
1852
+ raise Exception ("You must provide a full path to shapefile" )
1853
+
1854
+ if workspace is None :
1855
+ workspace = "default"
1856
+
1857
+ if store_name is None :
1858
+ store_name = os .path .basename (path )
1859
+ f = store_name .split ("." )
1860
+ if len (f ) > 0 :
1861
+ store_name = f [0 ]
1862
+
1863
+ headers = {
1864
+ "Content-type" : "application/x-sqlite3" ,
1865
+ "Accept" : "application/json" ,
1866
+ }
1867
+
1868
+ url = "{0}/rest/workspaces/{1}/datastores/{2}/file.{3}?filename={2}" .format (
1869
+ self .service_url , workspace , store_name , file_extension
1870
+ )
1871
+
1872
+ with open (path , "rb" ) as f :
1873
+ r = requests .put (
1874
+ url ,
1875
+ data = f .read (),
1876
+ auth = (self .username , self .password ),
1877
+ headers = headers ,
1878
+ )
1879
+ if r .status_code in [200 , 201 , 202 ]:
1880
+ return "The geopackage datastore created successfully!"
1881
+ else :
1882
+ raise GeoserverException (r .status_code , r .content )
1883
+
1825
1884
def publish_featurestore (
1826
1885
self ,
1827
1886
store_name : str ,
0 commit comments