[Gdal-dev] "Old-Style" ESRI .PRJ files -- Access Violation on ImportFromESRI

Christopher Michaelis cmichaelis at happysquirrel.com
Fri Dec 9 22:25:07 EST 2005


Hello everyone,

I've got a question more related to OGR than to GDAL itself... but as 
I'm using OGR through GDAL I figured the question may be appropriate 
here. Apologies if it's not!

I've been reading the previous list messages on the various ESRI .prj 
file formats, and I think I've just run into my first "old-style" 
projection file. I have up until now been using .ImportFromWkt() to load 
projections, and it works perfectly for the WKT-style projection files.

Based on previous posts, I think that .ImportFromESRI() should be able 
to read these old-style PRJ files as well as the WKT. Am I correct in 
this assumption?

Now... to test it, I simply changed "ImportFromWkt" to "ImportFromESRI" 
in my code. No matter whether I try to read a new or old-style .prj 
file, this function call results in an access violation in GDAL13.dll.

Does anyone out there have a similar experience with this? I'd be 
eternally grateful for any advice. I put together a simple C++ test 
program to try to figure out what I was doing wrong; code follows below.

Thanks in advance for any help, and thanks in advance for reading my 
ramblings.

--Chris Michaelis of MapWindow.org

My troublesome PRJ file:
Projection    ALBERS
Datum         NAD83
Spheroid      GRS80
Units         METERS
Zunits        NO
Xshift        0.0
Yshift        0.0
Parameters
   29 30  0.0 /* 1st standard parallel
   45 30  0.0 /* 2nd standard parallel
  -96  0  0.0 /* central meridian
   23  0  0.0 /* latitude of projection's origin
0.0 /* false easting (meters)
0.0 /* false northing (meters)

The source code I'm trying to read this with: (takes the .prj file as a 
command-line argument -- this is on Windows, if "_tmain" and the 
reference to the gdal DLL above doesn't give that away)

int _tmain(int argc, _TCHAR* argv[])
{
	OGRSpatialReference oSRS, rSRS;
     	char *pszProj4 = NULL;

	FILE * prjFile;
	char * pszWKT = NULL;

	prjFile = fopen(argv[1], "rb");
	if (!prjFile)
	{
		printf("Couldn't open file.\n");
		exit(1);
	}

	fseek (prjFile, 0, SEEK_END);
	long lSize = ftell (prjFile);
	rewind (prjFile);

	pszWKT = (char*) malloc (lSize);
	if (pszWKT == NULL)
	{
		printf("Couldn't allocate mem.\n");
		exit (2);
	}

	fread (pszWKT,1,lSize,prjFile);
	fclose(prjFile);

	printf("INPUT = %s\n", pszWKT);

	oSRS.importFromESRI( &pszWKT );  // Crashes Here. ImportFromWkt works 
fine (for WKT, but not old-style of course)

     	oSRS.exportToProj4( &pszProj4 );

	printf( "OUTPUT Proj4 = %s\n", pszProj4 );

	// Clean up the allocated strings here...

	return 0;
}

Thanks again,
--Chris




More information about the Gdal-dev mailing list