Ticket #1656 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

ogr2ogr segfault with LCC target projection in ESRI style

Reported by: neteler Assigned to: mloskot
Priority: normal Milestone: 1.4.2
Component: OGR_SRS Version: svn-trunk
Severity: normal Keywords:
Cc: warmerdam

Description

Frank,

reprojecting a SHAPE file from LatLong?/WGS84 to North Carolina LCC leads to a segfault when the target .prj file is in ESRI style, otherwise it works:

When .prj looks like this, it fails:

g.proj -wef
PROJCS["Lambert Conformal Conic",GEOGCS["grs80",DATUM["D_North_American_1983",SPHEROID["Geodetic_Reference_System_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",34.33333333333334],PARAMETER["standard_parallel_2",36.16666666666666],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["Meter",1]]

ogr2ogr -s_srs epsg:4326 -t_srs "`g.proj -wef`" tiger_landmark_points_NCSPM.shp tgr37183lpt.shp
OGR: Auto register /usr/local/lib/gdalplugins/ogr_GRASS.so using RegisterOGRGRASS.
OGR: OGROpen(tgr37183lpt.shp/0x8052b08) succeeded as ESRI Shapefile.
OGRCT: Source: +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
ERROR 6: Failed to initialize PROJ.4 with `+ellps=GRS80 +units=m +no_defs '.
OGRCT: Target: +ellps=GRS80 +units=m +no_defs
Failed to create coordinate transformation between the
following coordinate systems.  This may be because they
are not transformable, or because projection services
(PROJ.4 DLL/.so) could not be loaded.
Segmentation fault

while it works like this:

# no ESRI style
g.proj -wf
PROJCS["Lambert Conformal Conic",GEOGCS["grs80",DATUM["North_American_Datum_1983",SPHEROID["Geodetic_Reference_System_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",34.33333333333334],PARAMETER["standard_parallel_2",36.16666666666666],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["Meter",1]]

ogr2ogr -s_srs epsg:4326 -t_srs "`g.proj -wf`" tiger_landmark_points_NCSPM.shp tgr37183lpt.shp
OGR: Auto register /usr/local/lib/gdalplugins/ogr_GRASS.so using RegisterOGRGRASS.
OGR: OGROpen(tgr37183lpt.shp/0x8052b58) succeeded as ESRI Shapefile.
OGRCT: Source: +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
OGRCT: Target: +proj=lcc +lat_1=34.33333333333334 +lat_2=36.16666666666666 +lat_0=33.75 +lon_0=-79 +x_0=609601.22 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs
Shape: 131 features read on layer 'tgr37183lpt'.

Apparently the ESRI morph fails in this case.

The source SHAPE is attached.

Best, Markus

Attachments

tiger_landmark_points37183.zip (3.9 kB) - added by neteler on 06/02/07 18:33:17.
TIGER extracted points in LatLong?
llc_esri_without_prefix.prj (500 bytes) - added by mloskot on 06/10/07 02:52:22.
Markus' WKT definition in ESRI style without the prefix
llc_esri_with_prefix.prj (506 bytes) - added by mloskot on 06/10/07 02:52:42.
Markus' WKT definition in ESRI style with the mandatory prefix
test_esri_to_proj_from_string.cpp (1.1 kB) - added by mloskot on 06/10/07 02:54:06.
Simple test of processing WKT in ESRI-style from string with the prefix to PROJ.4 definition
test_esri_to_proj_from_file.cpp (0.9 kB) - added by mloskot on 06/10/07 02:54:51.
Simple test of processing WKT in ESRI-style read directly from file, with the ESRI:: prefix, to PROJ.4 definition

Change History

06/02/07 18:33:17 changed by neteler

  • attachment tiger_landmark_points37183.zip added.

TIGER extracted points in LatLong?

06/02/07 18:34:08 changed by neteler

Note: Hobu mentioned

http://trac.osgeo.org/gdal/changeset/10845, at , by warmerdam: added LCC 2SP morph test per bug 187

in an IRC chat.

06/07/07 13:06:50 changed by warmerdam

  • owner changed from warmerdam to mloskot.
  • cc set to warmerdam.
  • component changed from default to OGR_SRS.

Mateusz,

Could you please try and reproduce this and if so fix it?

06/08/07 05:05:51 changed by mloskot

  • status changed from new to assigned.

06/10/07 02:06:23 changed by mloskot

The segmentation fault was caused by dereferencing of null pointer in ogr2ogr.cpp and is not directly related to this problem with ESRI style of projection def.

I applied the fix in r11636.

06/10/07 02:34:50 changed by mloskot

I applied one more improvement for handling ESRI style of WKT from file (r11638).

The OGRSpatialReference::SetFromUserInput?() function also accepts name of file in which projection definition is stored. There was missing test of ESRI:: prefix in WKT string read from given file.

NOTE: According to the manual, the ESRI:: prefix is required in order to trigger morphToESRI() on WKT string given in ESRI style. Otherwise, the projection definition may be imported incorrectly, incompletely or an error can be thrown.

Markus,

As I see, g.proj -wef command returns ESRI WKT string without the prefix mentioned above, and that's why the transformation failes (note, the segfault was caused by yet another issue, already fixed). The WKT in ESRI style should be passed to OGR as follows:

ESRI::PROJCS["Lambert Conformal Conic",GEOGCS["grs80",DATUM["D_North_American_1983",SPHEROID["Geodetic_Reference_System_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",34.33333333333334],PARAMETER["standard_parallel_2",36.16666666666666],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["Meter",1]]

and your command should read as:

ogr2ogr -s_srs epsg:4326 -t_srs "ESRI::`g.proj -wef`" tiger_landmark_points_NCSPM.shp tgr37183lpt.shp

Could you check if this command works for you?

I tested this approach (with the prefix) and it works well for me. I'm going to attach a few files with my tests.

06/10/07 02:41:59 changed by mloskot

One additional note to my analysis above. If I create OGRSpatialReference instance and import the ESRI-style WKT without the ESRI:: prefix (using SetFromUserInput?() function):

PROJCS["Lambert Conformal Conic",GEOGCS["grs80",DATUM["D_North_American_1983",SPHEROID["Geodetic_Reference_System_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",34.33333333333334],PARAMETER["standard_parallel_2",36.16666666666666],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["Meter",1]]

and next I will export the SRS definition to PROJ.4 (using exportToProj4() function), the output I get is incomplete:

+ellps=GRS80 +units=m +no_defs 

instead of

+proj=lcc +lat_1=34.33333333333334 +lat_2=36.16666666666666 +lat_0=33.75 +lon_0=-79 +x_0=609601.22 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs

This incomplete form of PROJ.4 definition is the main reason of the transformation failure Markus is experiencing. The transformation fails during PROJ.4 initialization using this incomplete definition, in ogrct.cpp:517

psPJTarget = pfn_pj_init_plus( pszProj4Defn );

where the returned psPJTarget is NULL.

Summarizing, the problem was caused by missing ESRI:: prefix in WKT of ESRI-style.

06/10/07 02:52:22 changed by mloskot

  • attachment llc_esri_without_prefix.prj added.

Markus' WKT definition in ESRI style without the prefix

06/10/07 02:52:42 changed by mloskot

  • attachment llc_esri_with_prefix.prj added.

Markus' WKT definition in ESRI style with the mandatory prefix

06/10/07 02:54:06 changed by mloskot

  • attachment test_esri_to_proj_from_string.cpp added.

Simple test of processing WKT in ESRI-style from string with the prefix to PROJ.4 definition

06/10/07 02:54:51 changed by mloskot

  • attachment test_esri_to_proj_from_file.cpp added.

Simple test of processing WKT in ESRI-style read directly from file, with the ESRI:: prefix, to PROJ.4 definition

06/10/07 09:57:31 changed by warmerdam

Mateusz,

Your analysis looks good. I think r11636 should go into 1.4 branch, but r11638 (as a new feature) should likely only be in trunk.

06/11/07 00:53:36 changed by mloskot

Frank,

I backported r11636 changeset to the 1.4 branch (r11646).

06/11/07 13:00:17 changed by mloskot

I added two test cases validating the ticket fix (r11647).

06/18/07 12:38:19 changed by mloskot

  • status changed from assigned to closed.
  • resolution set to fixed.

I'm closing this ticket. I believe the fix has been tested well.

Markus, please reopen it if it doesn't work for you.

06/23/07 12:31:51 changed by neteler

Hi,

thanks for the fixes (still have to test).

For the record, I have made a ticket for GRASS to add the ESRI:: prefix in case the -e flag is used:

http://wald.intevation.org/tracker/index.php?func=detail&aid=434&group_id=21&atid=204

Markus