diff --git a/vector/v.out.ogr/main.c b/vector/v.out.ogr/main.c index 788d27a3665..6a961c37a10 100644 --- a/vector/v.out.ogr/main.c +++ b/vector/v.out.ogr/main.c @@ -324,7 +324,6 @@ int main(int argc, char *argv[]) inwkt = NULL; } proj_destroy(source_crs); - Ogr_projection = NULL; if (inwkt) { char *inwkttmp = inwkt; diff --git a/vector/v.out.ogr/testsuite/data/ESRI54052.wkt b/vector/v.out.ogr/testsuite/data/ESRI54052.wkt new file mode 100644 index 00000000000..9bfdc68b945 --- /dev/null +++ b/vector/v.out.ogr/testsuite/data/ESRI54052.wkt @@ -0,0 +1,63 @@ +BOUNDCRS[ + SOURCECRS[ + PROJCRS["unknown", + BASEGEOGCRS["wgs84", + DATUM["World Geodetic System 1984", + ELLIPSOID["WGS_1984",6378137,298.257223563, + LENGTHUNIT["metre",1, + ID["EPSG",9001]]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8901]]], + CONVERSION["unnamed", + METHOD["Interrupted Goode Homolosine"], + PARAMETER["Longitude of natural origin",0, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8802]], + PARAMETER["False easting",0, + LENGTHUNIT["metre",1], + ID["EPSG",8806]], + PARAMETER["False northing",0, + LENGTHUNIT["metre",1], + ID["EPSG",8807]]], + CS[Cartesian,2], + AXIS["easting",east, + ORDER[1], + LENGTHUNIT["metre",1, + ID["EPSG",9001]]], + AXIS["northing",north, + ORDER[2], + LENGTHUNIT["metre",1, + ID["EPSG",9001]]]]], + TARGETCRS[ + GEOGCRS["WGS 84", + DATUM["World Geodetic System 1984", + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + CS[ellipsoidal,2], + AXIS["latitude",north, + ORDER[1], + ANGLEUNIT["degree",0.0174532925199433]], + AXIS["longitude",east, + ORDER[2], + ANGLEUNIT["degree",0.0174532925199433]], + ID["EPSG",4326]]], + ABRIDGEDTRANSFORMATION["Transformation from wgs84 to WGS84", + METHOD["Position Vector transformation (geog2D domain)", + ID["EPSG",9606]], + PARAMETER["X-axis translation",0, + ID["EPSG",8605]], + PARAMETER["Y-axis translation",0, + ID["EPSG",8606]], + PARAMETER["Z-axis translation",0, + ID["EPSG",8607]], + PARAMETER["X-axis rotation",0, + ID["EPSG",8608]], + PARAMETER["Y-axis rotation",0, + ID["EPSG",8609]], + PARAMETER["Z-axis rotation",0, + ID["EPSG",8610]], + PARAMETER["Scale difference",1, + ID["EPSG",8611]]]] diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index d269ccff606..53ac0270a74 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -4,6 +4,8 @@ """ from pathlib import Path +from shutil import rmtree +import grass.script as gs from grass.gunittest.case import TestCase @@ -15,6 +17,15 @@ class TestOgrExport(TestCase): # Result of import tests temp_import = "test_ogr_import_map" + # Temporary location + temp_location = "temp_location" + + # Temporary Homolosine map + temp_54052 = "temp_rand.gpkg" + + # Temporary environment file + session_file = "" + # Column on which to test v.univar univar_col = "PERIMETER" @@ -48,11 +59,24 @@ def tearDownClass(cls): cls.del_temp_region() def tearDown(self): + + # Remove maps in temp mapset self.runModule( "g.remove", type="vector", flags="f", pattern=f"{self.temp_import}*" ) + # Remove temporary files for p in Path().glob(f"{self.test_map}*"): p.unlink() + for p in Path().glob(f"{self.temp_54052}*"): + p.unlink() + if len(self.session_file) > 0: + Path(self.session_file).unlink() + + # Remove temporary location + env = gs.parse_command("g.gisenv") + # Quotes and separator in environment variable string must be removed + dbase = env["GISDBASE"].replace("'", "").replace(";", "") + rmtree(f"{dbase}/{self.temp_location}", ignore_errors=True) def test_gpkg_format(self): """Tests output to GeoPackage format""" @@ -108,6 +132,38 @@ def test_shp_format(self): precision=1e-8, ) + def test_no_epsg_crs(self): + """Tests output from a location/project lacking an EPSG code""" + + # Record original location to use corect GISDBASE + env_orig = gs.parse_command("g.gisenv") + + # Create new location with CRS without EPSG code + gs.run_command( + "g.proj", wkt="data/ESRI54052.wkt", project=self.temp_location, flags="c" + ) + + # Create new session to avoid temporary region + # Quotes and separator in environment variable string must be removed + self.session_file, env_new = gs.core.create_environment( + env_orig["GISDBASE"].replace("'", "").replace(";", ""), + self.temp_location, + "PERMANENT", + ) + + # Creates a random layer to test output + gs.run_command("v.random", output="temp_rand", npoints=3, env=env_new) + + # Test output of a vector with non-EPSG CRS + gs.run_command( + "v.out.ogr", + input="temp_rand", + output=self.temp_54052, + format="GPKG", + dsco="a_srs=ESRI:54052", + env=env_new, + ) + if __name__ == "__main__": from grass.gunittest.main import test