<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:ns0="urn:schemas-microsoft-com:office:smarttags">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:595.3pt 841.9pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
/* List Definitions */
@list l0
        {mso-list-id:706754484;
        mso-list-type:hybrid;
        mso-list-template-ids:733122790 134807569 134807577 134807579 134807567 134807577 134807579 134807567 134807577 134807579;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</style>
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal style='margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'><span
style='mso-list:Ignore'>1)<font size=1 face="Times New Roman"><span
style='font:7.0pt "Times New Roman"'> </span></font></span></span></font><![endif]><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Can anyone
tell me why the following program returns a GetProjectionRef as ‘empty
string’ (not NULL) from some files and not others (even though openEv
seems to be able to open them and georeference them all fine?) I am
looking at geotiffs from the MapServer tutorial directory.<o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'><span
style='mso-list:Ignore'>2)<font size=1 face="Times New Roman"><span
style='font:7.0pt "Times New Roman"'> </span></font></span></span></font><![endif]><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Can anyone
offer an explanation as to why – even with a valid projectionRef, I can
never create the OGRSpatialReference<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I am using Linux SLES10 SP2, gdal-svn-trunk-2009.12.14 and
proj4-4.7.0-1.1 (well – at least I think I am – can someone tell me
a good way to test this?)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>// g++ -Wno-deprecated -m64 -g -o georef georef.c++ -lgdal<br>
<br>
#include <proj_api.h><br>
#include <gdal.h><br>
#include <gdal_priv.h><br>
#include <ogr_spatialref.h><br>
<br>
/* Using from the MapServer tutorial <b><span style='font-weight:bold'>...data/raster/shdrlfi020l_ugl.tif</span></b>
file. <br>
This file opens fine in 'openev' and gives easting/northing
readouts OK. <br>
However – this program fails to manage to create either a
pixel->geo transform OR<br>
a UTM to Lat/Long transform! Output from this program is…<br>
<br>
Driver: GTiff/GeoTIFF<br>
Input has no ProjectionRef!<br>
No geo transform!<br>
ERROR 1: No PROJ.4 translation for source SRS, coordinate<br>
transformation initialization has failed.<br>
!!!FAILED! Cannot create transform from input space to WGS84<br>
*/<br>
<br>
/* Using the MapServer tutorial <b><span style='font-weight:bold'>...data/raster/mod09a12003161_ugl_ll_8bit.tif</span></b>
file.<br>
This file opens fine in 'openev' and gives Lat/Long readouts
OK. <br>
This program does get a geoTransform but fails to create the <o:p></o:p></span></font></p>
<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'> UTM to Lat/Long transform too! Output from this
program is…<br>
<br>
Driver: GTiff/GeoTIFF<br>
ProjectionRef is 'GEOGCS["WGS
84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.2572235630016,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]'<br>
Origin = (-97.374337,49.415919)<br>
Pixel Size = (0.004733,-0.004733)<br>
ERROR 1: No PROJ.4 translation for source SRS, coordinate<br>
transformation initialization has failed.<br>
!!!FAILED! Cannot create transform from input space GEOGCS["WGS
84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.2572235630016,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]
to WGS84<br>
*/<br>
<br>
int main(int argc, char **argv)<br>
{<br>
GDALDataset *poDataset;<br>
<br>
GDALAllRegister();<br>
<br>
poDataset = (GDALDataset *) GDALOpen( argv[1], GA_ReadOnly );<br>
if( poDataset == NULL )<br>
{<br>
fprintf(stderr, "!!!poDataset was NULL\n");<br>
exit(-1);<br>
}<br>
double adfGeoTransform[6];<br>
<br>
fprintf(stderr, "Driver: %s/%s\n",<br>
poDataset->GetDriver()->GetDescription(), <br>
poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );<br>
<br>
const char *proj_ref = poDataset->GetProjectionRef();<br>
if( proj_ref != NULL && strlen(proj_ref))<br>
fprintf(stderr, "ProjectionRef is
'%s'\n", poDataset->GetProjectionRef() );<br>
else<br>
fprintf(stderr, "Input has no
ProjectionRef!\n");<br>
<br>
if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )<br>
{<br>
fprintf(stderr, "Origin =
(%.6f,%.6f)\n",<br>
adfGeoTransform[0], adfGeoTransform[3] );<br>
<br>
fprintf(stderr, "Pixel Size =
(%.6f,%.6f)\n",<br>
adfGeoTransform[1], adfGeoTransform[5] );<br>
}<br>
else<br>
fprintf(stderr, "No geo transform!\n");<br>
<br>
// We have to convert from native input file <br>
// geospace to our standard WGS84 space so create a transform
here.<br>
<br>
// First create a spatial reference in the input space<br>
OGRSpatialReference iref;<br>
char *tmp = NULL;<br>
if (proj_ref)<br>
{<br>
tmp = (char *)malloc(strlen(proj_ref)+1);<br>
iref.importFromWkt(&tmp);<br>
//iref.SetWellKnownGeogCS("WGS84");<br>
<br>
// Create a spatial reference in WGS84 lat/long space
and<br>
// create a transform object between input and output space<br>
OGRSpatialReference oref;<br>
oref.SetWellKnownGeogCS("WGS84");<br>
OGRCoordinateTransformation *coord_transform<br>
= OGRCreateCoordinateTransformation(&iref,
&oref);<br>
if (!coord_transform)<br>
{<br>
fprintf(stderr, "!!!FAILED! Cannot create
converter from %s "<br>
" to WGS84\n", proj_ref);<br>
<br>
} // end case default<br>
free(tmp);<br>
<br>
} // end if got projection ref<br>
} // end main<br>
</span></font><font face=Arial><span style='font-family:Arial'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><st1:place w:st="on"><st1:City w:st="on"><b><i><font size=2
color=purple face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:purple;font-weight:bold;font-style:italic'>Gary</span></font></i></b></st1:City></st1:place><b><i><font
color=navy><span style='color:navy;font-weight:bold;font-style:italic'><o:p></o:p></span></font></i></b></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>