OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
853 stars 311 forks source link

[Bug] v.out.ogr: ERROR: Unable to create OGR spatial reference with Shapefile export #2187

Open fredfox1 opened 2 years ago

fredfox1 commented 2 years ago

Describe the bug v.out.ogr input=world_borders@world_borders output=/home/fredfox/Downloads/temp/world_borders format=ESRI_Shapefile ERROR 10: Pointer 'hSRS' is NULL in 'OSRImportFromWkt'. ERROR: Unable to create OGR spatial reference

To Reproduce Steps to reproduce the behavior:

  1. import an existing ESRI shapefile
  2. Attempt to export the resultant vector vector map to a new shape file using v.out.ogr

Expected behavior I expected the process to create a new shape file

Screenshots Output displayed in the bug description.

System description (please complete the following information):

Additional context Add any other context about the problem here.

neteler commented 2 years ago

Can you please post the output of g.proj -w in that mapset you want to export data from?

HuidaeCho commented 2 years ago

Related reports

fredfox1 commented 2 years ago

I opened the mapset "world_borders" and ran:

GRASS 7.8.6 (WGS84):~ > g.proj -w
BOUNDCRS[
    SOURCECRS[
        GEOGCRS["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]],
            CS[ellipsoidal,2],
                AXIS["longitude",east,
                    ORDER[1],
                    ANGLEUNIT["degree",0.0174532925199433,
                        ID["EPSG",9122]]],
                AXIS["latitude",north,
                    ORDER[2],
                    ANGLEUNIT["degree",0.0174532925199433,
                        ID["EPSG",9122]]]]],
    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]]]]
i-m-amit commented 2 years ago

I also faced a similar situation with the module. Here are some information that cloud help understanding the bug:

The error:

v.out.ogr input=moz_admbnda_adm1_ine_20190607@PERMANENT output=/home/amit/tmp/moz_adm.gpkg format=GPKG
ERROR 10: Pointer 'hSRS' is NULL in 'OSRImportFromWkt'.
ERROR: Unable to create OGR spatial reference

My GRASS environment:

version=8.0.1
date=2022
revision=exported
build_date=2022-02-24
build_platform=x86_64-redhat-linux-gnu
build_off_t_size=8
libgis_revision=2022-02-24T22:29:01+00:00
libgis_date=2022-02-24T22:29:01+00:00
proj=8.2.1
gdal=3.4.1
geos=3.10.2
sqlite=3.36.0

Workflow

I created the location using the following proj string

+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs

g.proj -p and g.proj -w return the following information

g.proj -p                                                                       
-PROJ_INFO-------------------------------------------------
name       : unknown
datum      : wgs84
ellps      : wgs84
proj       : aea
lat_0      : 0
lon_0      : 25
lat_1      : 20
lat_2      : -23
x_0        : 0
y_0        : 0
no_defs    : defined
towgs84    : 0.000,0.000,0.000
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1
g.proj -w                                                                       
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["Albers Equal Area",
                    ID["EPSG",9822]],
                PARAMETER["Latitude of false origin",0,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8821]],
                PARAMETER["Longitude of false origin",25,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8822]],
                PARAMETER["Latitude of 1st standard parallel",20,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8823]],
                PARAMETER["Latitude of 2nd standard parallel",-23,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8824]],
                PARAMETER["Easting at false origin",0,
                    LENGTHUNIT["metre",1],
                    ID["EPSG",8826]],
                PARAMETER["Northing at false origin",0,
                    LENGTHUNIT["metre",1],
                    ID["EPSG",8827]]],
            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]]]]

I updated the projection using the WKT from www.epsg.io to solve the issue:

g.proj -c wkt="/home/amit/tmp/102022_epsg_io.txt"
Projection information updated
cat /home/amit/tmp/102022_epsg_io.txt

PROJCS["Africa_Albers_Equal_Area_Conic",GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["longitude_of_center",25],PARAMETER["Standard_Parallel_1",20],PARAMETER["Standard_Parallel_2",-23],PARAMETER["latitude_of_center",0],UNIT["Meter",1],AUTHORITY["EPSG","102022"]]

and tried to export the data again: It worked but without any projection info!

v.out.ogr input=moz_admbnda_adm1_ine_20190607@PERMANENT output=/home/amit/tmp/moz_adm.gpkg format=GPKG
proj_create: crs not found
Exporting 89 areas (may take some time)...
v.out.ogr complete. 89 features (Polygon type) written to <moz_admbnda_adm1_ine_20190607> (GPKG format).

Surprisingly, g.proj -p prints the projection info but g.proj -w cannot print the WKT text!

g.proj -p                                                                       
-PROJ_INFO-------------------------------------------------
name       : Africa_Albers_Equal_Area_Conic
datum      : wgs84
ellps      : wgs84
proj       : aea
lat_0      : 0
lon_0      : 25
lat_1      : 20
lat_2      : -23
x_0        : 0
y_0        : 0
no_defs    : defined
-PROJ_SRID-------------------------------------------------
SRID       : EPSG:102022
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1 
g.proj -w                                                                       
proj_create: crs not found
ERROR: Unable to create PROJ definition from srid <EPSG:102022>

I created another location with EPSG:4326. It does not report the error and I can export the data. Therefore I though it must be related to the projection.

I tried to create a location with the same projection using the EPSG ID 102022, but I could not find the EPSG ID in the database. Then I created the location using the WKT from epsg.io, this time I changed the ID FROM EPSG:102022 to ESRI:102022. and It worked!

g.proj -p                                                                       
-PROJ_INFO-------------------------------------------------
name       : Africa_Albers_Equal_Area_Conic
datum      : wgs84
ellps      : wgs84
proj       : aea
lat_0      : 0
lon_0      : 25
lat_1      : 20
lat_2      : -23
x_0        : 0
y_0        : 0
no_defs    : defined
-PROJ_SRID-------------------------------------------------
SRID       : ESRI:102022
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1
g.proj -w                                                                       
PROJCRS["Africa_Albers_Equal_Area_Conic",
    BASEGEOGCRS["WGS 84",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["Degree",0.0174532925199433]]],
    CONVERSION["Africa_Albers_Equal_Area_Conic",
        METHOD["Albers Equal Area",
            ID["EPSG",9822]],
        PARAMETER["Latitude of false origin",0,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8821]],
        PARAMETER["Longitude of false origin",25,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8822]],
        PARAMETER["Latitude of 1st standard parallel",20,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8823]],
        PARAMETER["Latitude of 2nd standard parallel",-23,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8824]],
        PARAMETER["Easting at false origin",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8826]],
        PARAMETER["Northing at false origin",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8827]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Not known."],
        AREA["Africa"],
        BBOX[-35,-25,39,55]],
    ID["ESRI",102022]]

v.out.ogr input=moz_admbnda_adm1_ine_20190607@PERMANENT output=/home/amit/tmp/moz_adm_esri.gpkg format=GPKG
Exporting 89 areas (may take some time)...
v.out.ogr complete. 89 features (Polygon type) written to <moz_admbnda_adm1_ine_20190607> (GPKG format).
cmbarton commented 1 year ago

I'm having exactly the same problem in an ETRS89 Zone 30 location for eastern Spain. I think I created this with an EPSG code but don't remember after 7 years. Not sure how to solve it. Make a new location and reproject into it? What projection to use?

Here is the current projection info:

-PROJ_INFO-------------------------------------------------
name       : Universal Transverse Mercator
proj       : utm
datum      : etrs89
ellps      : grs80
zone       : 30
no_defs    : defined
towgs84    : 0.000,0.000,0.000
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1
cmbarton commented 1 year ago

I created a new location using EPSG 25830 with exactly the same projection settings as my previous one, reprojected a vector file into this new location and successfully exported the file to a shape file. While this works, it is a clunky workaround.

This is some kind of a weird bug that needs to be investigated, since exporting to a shapefile is a very common activity.

I am using the new GRASS 8.3.0 for Mac ARM and MacOS 13.4.1

However, this was first reported with GRASS 7.8.6 on Ubuntu. So this is very generic. It may be in OGR of course, but we need to look into it.

ericrpatton commented 1 year ago

I'm also ran into the same bug today, on Linux Mint 20.3 with the following installation:

uname -a
Linux epatton 5.15.0-79-generic #86~20.04.2-Ubuntu SMP Mon Jul 17 23:27:17 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
g.version -gre
version=8.3.dev
date=2023
revision=b3ba6c290d
build_date=2023-08-14
build_platform=x86_64-pc-linux-gnu
build_off_t_size=8
libgis_revision=a82501dc85
libgis_date=2023-02-27T12:45:25+00:00
proj=8.2.0
gdal=3.7.1
geos=3.12.0
sqlite=3.31.1

Projection info:

g.proj -p
-PROJ_INFO-------------------------------------------------
name       : unnamed
proj       : lcc
lat_1      : 48
lat_2      : 52
lat_0      : 46
lon_0      : -60
x_0        : 0
y_0        : 0
no_defs    : defined
datum      : wgs84
ellps      : wgs84
towgs84    : 0.000,0.000,0.000
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1
g.proj -w 

g.proj -w
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["Lambert Conic Conformal (2SP)",
                    ID["EPSG",9802]],
                PARAMETER["Latitude of false origin",46,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8821]],
                PARAMETER["Longitude of false origin",-60,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8822]],
                PARAMETER["Latitude of 1st standard parallel",48,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8823]],
                PARAMETER["Latitude of 2nd standard parallel",52,
                    ANGLEUNIT["degree",0.0174532925199433],
                    ID["EPSG",8824]],
                PARAMETER["Easting at false origin",0,
                    LENGTHUNIT["metre",1],
                    ID["EPSG",8826]],
                PARAMETER["Northing at false origin",0,
                    LENGTHUNIT["metre",1],
                    ID["EPSG",8827]]],
            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]]]]
ldesousa commented 6 months ago

I just bumped into this issue. This is an old location but a recent mapset. I was able to export vectors from this location in the past. One aspect I don't understand is why is this CRS reported as "unnamed", this is a well known map projection and datum, recorded with the identifier ESRI:54052 by both GDAL and PostGis.

GRASS local_igh/vectors:local_igh > uname -a
Linux luis-notebook 6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr  4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

> g.version -gre
version=8.3.2
date=2024
revision=exported
build_date=2024-03-08
build_platform=x86_64-pc-linux-gnu
build_off_t_size=8
libgis_revision=8.3.2
libgis_date=2024-03-08T09:26:59+00:00
proj=9.3.1
gdal=3.8.4
geos=3.12.1
sqlite=3.37.2

> g.proj -p
-PROJ_INFO-------------------------------------------------
name       : unnamed
datum      : wgs84
ellps      : wgs84
proj       : igh
no_defs    : defined
towgs84    : 0.000,0.000,0.000
-PROJ_UNITS------------------------------------------------
unit       : meter
units      : meters
meters     : 1