<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"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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 &#8216;empty
string&#8217; (not NULL) from some files and not others (even though openEv
seems to be able to open them and georeference them all fine?) &nbsp;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"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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 &#8211; 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>&nbsp;</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 &#8211; at least I think I am &#8211; 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>&nbsp;</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 &lt;proj_api.h&gt;<br>
#include &lt;gdal.h&gt;<br>
#include &lt;gdal_priv.h&gt;<br>
#include &lt;ogr_spatialref.h&gt;<br>
<br>
/* Using from the MapServer tutorial <b><span style='font-weight:bold'>...data/raster/shdrlfi020l_ugl.tif</span></b>
file.&nbsp; <br>
&nbsp;&nbsp; This file opens fine in 'openev' and gives easting/northing
readouts OK.&nbsp; <br>
&nbsp;&nbsp; However &#8211; this program fails to manage to create either a
pixel-&gt;geo transform OR<br>
&nbsp;&nbsp; a UTM to Lat/Long transform!&nbsp; Output from this program is&#8230;<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&nbsp;&nbsp; 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>
&nbsp;&nbsp; This file opens fine in 'openev' and gives Lat/Long readouts
OK.&nbsp; <br>
&nbsp;&nbsp; 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'>&nbsp;&nbsp; UTM to Lat/Long transform too!&nbsp; Output from this
program is&#8230;<br>
<br>
Driver: GTiff/GeoTIFF<br>
ProjectionRef is 'GEOGCS[&quot;WGS
84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS
84&quot;,6378137,298.2572235630016,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]'<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[&quot;WGS
84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS
84&quot;,6378137,298.2572235630016,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]&nbsp;
to WGS84<br>
*/<br>
<br>
int main(int argc, char **argv)<br>
{<br>
&nbsp; GDALDataset&nbsp; *poDataset;<br>
<br>
&nbsp; GDALAllRegister();<br>
<br>
&nbsp; poDataset = (GDALDataset *) GDALOpen( argv[1], GA_ReadOnly );<br>
&nbsp; if( poDataset == NULL )<br>
&nbsp; {<br>
&nbsp;&nbsp; &nbsp;fprintf(stderr, &quot;!!!poDataset was NULL\n&quot;);<br>
&nbsp;&nbsp;&nbsp; exit(-1);<br>
&nbsp; }<br>
&nbsp; double adfGeoTransform[6];<br>
<br>
&nbsp; fprintf(stderr, &quot;Driver: %s/%s\n&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
poDataset-&gt;GetDriver()-&gt;GetDescription(), <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
poDataset-&gt;GetDriver()-&gt;GetMetadataItem( GDAL_DMD_LONGNAME ) );<br>
<br>
&nbsp; const char *proj_ref = poDataset-&gt;GetProjectionRef();<br>
&nbsp; if( proj_ref != NULL &amp;&amp; strlen(proj_ref))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, &quot;ProjectionRef is
'%s'\n&quot;, poDataset-&gt;GetProjectionRef() );<br>
&nbsp; else<br>
&nbsp;&nbsp;&nbsp; fprintf(stderr, &quot;Input has no
ProjectionRef!\n&quot;);<br>
<br>
&nbsp; if( poDataset-&gt;GetGeoTransform( adfGeoTransform ) == CE_None )<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, &quot;Origin =
(%.6f,%.6f)\n&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
adfGeoTransform[0], adfGeoTransform[3] );<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, &quot;Pixel Size =
(%.6f,%.6f)\n&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
adfGeoTransform[1], adfGeoTransform[5] );<br>
&nbsp; }<br>
&nbsp; else<br>
&nbsp;&nbsp;&nbsp; fprintf(stderr, &quot;No geo transform!\n&quot;);<br>
<br>
&nbsp; // We have to convert from native input file <br>
&nbsp; // geospace to our standard WGS84 space so create a transform
here.<br>
<br>
&nbsp; // First create a spatial reference in the input space<br>
&nbsp; OGRSpatialReference iref;<br>
&nbsp; char *tmp = NULL;<br>
&nbsp; if (proj_ref)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; tmp = (char *)malloc(strlen(proj_ref)+1);<br>
&nbsp;&nbsp;&nbsp; iref.importFromWkt(&amp;tmp);<br>
&nbsp;&nbsp;&nbsp; //iref.SetWellKnownGeogCS(&quot;WGS84&quot;);<br>
<br>
&nbsp;&nbsp;&nbsp; // Create a spatial reference in WGS84 lat/long space
and<br>
&nbsp;&nbsp;&nbsp; // create a transform object between input and output space<br>
&nbsp;&nbsp;&nbsp; OGRSpatialReference oref;<br>
&nbsp;&nbsp;&nbsp; oref.SetWellKnownGeogCS(&quot;WGS84&quot;);<br>
&nbsp;&nbsp;&nbsp; OGRCoordinateTransformation *coord_transform<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = OGRCreateCoordinateTransformation(&amp;iref,
&amp;oref);<br>
&nbsp;&nbsp;&nbsp; if (!coord_transform)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fprintf(stderr, &quot;!!!FAILED! Cannot create
converter from %s &quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot; to WGS84\n&quot;, proj_ref);<br>
<br>
&nbsp;&nbsp;&nbsp; } // end case default<br>
&nbsp;&nbsp;&nbsp; free(tmp);<br>
<br>
&nbsp; } // end if got projection ref<br>
} // end main<br>
</span></font><font face=Arial><span style='font-family:Arial'><o:p>&nbsp;</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>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>