-
-
Notifications
You must be signed in to change notification settings - Fork 412
v.out.ogr: Fix exporting vector layers from a location whose CRS has no EPSG code #3869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5cffa26
47d256b
8da3982
88464da
36caea6
1cb6632
0b95ec4
08f7492
5a73b5f
35ba769
6bdc3c9
ebf444c
9b293b3
93f5429
280997f
a2ae200
fc2c253
1c83ffa
3235dfc
1c14af9
f98aead
3e80eca
d05b093
77fc48b
a076bbc
d1f70b7
6844064
16d61e0
b46fb05
1c96ce0
6fd87bc
f59f324
0bfb2ab
a30964a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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]]]] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(";", ""), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use a comment or two about why these two replace calls are needed. Are the characters an issue? Why are the characters there? How is the original GISDBASE working with them? (Same for line 77.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those characters are included in the variable string, e.g.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry to keep this hanging, but I find it both puzzling and concerning that GISDBASE retrieved by g.gisenv has quotes and a semicolon. Are you sure that's what you have there? Can you please directly run GRASS nc_basic_spm_grass7/user1:script > g.gisenv
GISDBASE=/home/vpetras/grassdata
LOCATION_NAME=nc_basic_spm_grass7
MAPSET=user1
GUI=text
PID=1094462
GRASS nc_basic_spm_grass7/user1:script > python -c "import grass.script as gs; print(gs.gisenv())"
{'GISDBASE': '/home/vpetras/grassdata', 'LOCATION_NAME': 'nc_basic_spm_grass7', 'MAPSET': 'user1', 'GUI': 'text', 'PID': '1094462'}And can you print from the test? (You may need to fail the test to get a print.) self.assertFalse(env_orig) |
||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.