Przeglądaj źródła

t.vect.export: GPKG support added (#129)

Markus Neteler 5 lat temu
rodzic
commit
04b2790df6

+ 33 - 1
lib/python/temporal/stds_export.py

@@ -17,7 +17,7 @@ Usage:
     tgis.export_stds(input, output, compression, directory, where, format_, type_)
 
 
-(C) 2012-2013 by the GRASS Development Team
+(C) 2012-2019 by the GRASS Development Team
 This program is free software under the GNU General Public
 License (>=v2). Read the file COPYING that comes with GRASS
 for details.
@@ -174,6 +174,34 @@ def _export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs):
 ############################################################################
 
 
+def _export_vector_maps_as_gpkg(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        layer = row["layer"]
+        if not layer:
+            layer = 1
+        if not end:
+            end = start
+        string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string)
+        # Export the vector map with v.out.ogr
+        try:
+            gscript.run_command("v.out.ogr", input=name, output=(name + ".gpkg"),
+                                layer=layer, format="GPKG")
+        except CalledModuleError:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            gscript.fatal(_("Unable to export vector map <%s> as "
+                            "GPKG with v.out.ogr" % name))
+
+        tar.add(name + ".gpkg")
+
+############################################################################
+
+
 def _export_vector_maps(rows, tar, list_file, new_cwd, fs):
     for row in rows:
         name = row["name"]
@@ -259,6 +287,8 @@ def export_stds(input, output, compression, directory, where, format_="pack",
                        this is the default setting
               - "GML" GML file export format, only for vector maps,
                       v.out.ogr export option
+              - "GPKG" GPKG file export format, only for vector maps,
+                      v.out.ogr export option
 
         :param type_: The space time dataset type
 
@@ -309,6 +339,8 @@ def export_stds(input, output, compression, directory, where, format_="pack",
         elif type_ == "stvds":
             if format_ == "GML":
                 _export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs)
+            elif format_ == "GPKG":
+                _export_vector_maps_as_gpkg(rows, tar, list_file, new_cwd, fs)
             else:
                 _export_vector_maps(rows, tar, list_file, new_cwd, fs)
         elif type_ == "str3ds":

+ 3 - 3
temporal/t.vect.export/t.vect.export.py

@@ -56,10 +56,10 @@
 #% key: format
 #% type: string
 #% label: The export format of a single vector map
-#% description: Supported are GML via v.out.ogr and the GRASS package format of v.pack
+#% description: Supported are GML and GPKG via v.out.ogr and the GRASS package format of v.pack
 #% required: no
 #% multiple: no
-#% options: GML,pack
+#% options: GML,GPKG,pack
 #% answer: GML
 #%end
 
@@ -84,7 +84,7 @@ def main():
 
     # Make sure the temporal database exists
     tgis.init()
-    # Export the space time raster dataset
+    # Export the space time vector dataset
     tgis.export_stds(
         _input, output, compression, directory, where, _format, "stvds")
 

+ 18 - 7
temporal/t.vect.export/test.t.vect.export.sh

@@ -6,7 +6,7 @@
 # The region setting should work for UTM and LL test locations
 g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
 
-v.random --o -z output=soil_1 n=100 zmin=0 zmax=100 column=height  seed=1
+v.random --o -z output=soil_1 n=100 zmin=0 zmax=100 column=height seed=1
 v.random --o -z output=soil_2 n=100 zmin=0 zmax=100 column=height seed=2
 v.random --o -z output=soil_3 n=100 zmin=0 zmax=100 column=height seed=3
 
@@ -22,19 +22,30 @@ t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" de
 t.register -i type=vector input=soil_abs1 file="${n1}" start='2001-01-01' increment="1 months"
 
 # The first @test
+g.message message="Export test to GML vector format (test 1/3):"
 t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.bz2 compression=bzip2 directory=/tmp
 t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.gz compression=gzip directory=/tmp
 t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar compression=no directory=/tmp
 
+g.message message="Export test to pack vector format (test 2/3):"
 t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.bz2 compression=bzip2 directory=/tmp
 t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.gz compression=gzip directory=/tmp
 t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar compression=no directory=/tmp
 
+g.message message="Export test to GPKG vector format (test 3/3):"
+t.vect.export format=GPKG input=soil_abs1 output=stvds_export_gpkg.tar.bz2 compression=bzip2 directory=/tmp
+t.vect.export format=GPKG input=soil_abs1 output=stvds_export_gpkg.tar.gz compression=gzip directory=/tmp
+t.vect.export format=GPKG input=soil_abs1 output=stvds_export_gpkg.tar compression=no directory=/tmp
+
 t.unregister type=vector file="${n1}"
 t.remove type=stvds input=soil_abs1
-rm stvds_export_gml.tar.bz2
-rm stvds_export_gml.tar.gz
-rm stvds_export_gml.tar
-rm stvds_export_pack.tar.bz2
-rm stvds_export_pack.tar.gz
-rm stvds_export_pack.tar
+
+rm -f stvds_export_gml.tar.bz2
+rm -f stvds_export_gml.tar.gz
+rm -f stvds_export_gml.tar
+rm -f stvds_export_pack.tar.bz2
+rm -f stvds_export_pack.tar.gz
+rm -f stvds_export_pack.tar
+rm -f stvds_export_gpkg.tar.bz2
+rm -f stvds_export_gpkg.tar.gz
+rm -f stvds_export_gpkg.tar