@@ -10934,6 +10934,57 @@ def index():
10934
10934
10935
10935
10936
10936
def vector_to_mbtiles (
10937
+ source_path : str , target_path : str , max_zoom : int = 5 , name : str = None , ** kwargs
10938
+ ) -> None :
10939
+ """
10940
+ Convert a vector dataset to MBTiles format using the ogr2ogr command-line tool.
10941
+
10942
+ Args:
10943
+ source_path (str): The path to the source vector dataset (GeoPackage, Shapefile, etc.).
10944
+ target_path (str): The path to the target MBTiles file to be created.
10945
+ max_zoom (int, optional): The maximum zoom level for the MBTiles dataset. Defaults to 5.
10946
+ name (str, optional): The name of the MBTiles dataset. Defaults to None.
10947
+ **kwargs: Additional options to be passed as keyword arguments. These options will be used as -dsco options
10948
+ when calling ogr2ogr. See https://gdal.org/drivers/raster/mbtiles.html for a list of options.
10949
+
10950
+ Returns:
10951
+ None
10952
+
10953
+ Raises:
10954
+ subprocess.CalledProcessError: If the ogr2ogr command fails to execute.
10955
+
10956
+ Example:
10957
+ source_path = "countries.gpkg"
10958
+ target_path = "target.mbtiles"
10959
+ name = "My MBTiles"
10960
+ max_zoom = 5
10961
+ vector_to_mbtiles(source_path, target_path, name=name, max_zoom=max_zoom)
10962
+ """
10963
+ import subprocess
10964
+
10965
+ command = [
10966
+ "ogr2ogr" ,
10967
+ "-f" ,
10968
+ "MBTILES" ,
10969
+ target_path ,
10970
+ source_path ,
10971
+ "-dsco" ,
10972
+ f"MAXZOOM={ max_zoom } " ,
10973
+ ]
10974
+
10975
+ if name :
10976
+ command .extend (["-dsco" , f"NAME={ name } " ])
10977
+
10978
+ for key , value in kwargs .items ():
10979
+ command .extend (["-dsco" , f"{ key .upper ()} ={ value } " ])
10980
+
10981
+ try :
10982
+ subprocess .run (command , check = True )
10983
+ except subprocess .CalledProcessError as e :
10984
+ raise e
10985
+
10986
+
10987
+ def geojson_to_mbtiles (
10937
10988
input_file : str ,
10938
10989
output_file : str ,
10939
10990
layer_name : Optional [str ] = None ,
@@ -11028,7 +11079,7 @@ def mbtiles_to_pmtiles(
11028
11079
convert .mbtiles_to_pmtiles (input_file , output_file , maxzoom = max_zoom )
11029
11080
11030
11081
11031
- def vector_to_pmtiles (
11082
+ def geojson_to_pmtiles (
11032
11083
input_file : str ,
11033
11084
output_file : Optional [str ] = None ,
11034
11085
layer_name : Optional [str ] = None ,
0 commit comments