<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Verdana","sans-serif";
        color:#003399;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>I am testing GDAL's ability to read various data formats
commonly encountered by ArcGIS users, with the goal of replacing some of my ArcGIS-based
infrastructure with GDAL. At the moment I am working through Erdas Imagine .img
format.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>The GDAL HFA driver page <a
href="http://www.gdal.org/frmt_hfa.html">http://www.gdal.org/frmt_hfa.html</a>
says &quot;</span>It supports the erdas band types u8, s8, u16, s16, u32, s32,
f32, f64, c64 and c128<span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>&quot;. I am trying to figure out how to successfully read s8. I
have a .img generated by ArcGIS from this ArcInfo ASCII grid:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>ncols
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>nrows 3<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>xllcorner 0.0<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>yllcorner 0.0<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>cellsize 1.0<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>-127 63 126<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>-127 63 126<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>-127 63 126<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>But I am getting this with the Python bindings and 1.6.0:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>&gt;&gt;&gt; dataset =
gdal.Open(r'C:\Temp\NoDataTest\IMG\WithoutNoData\int8a.img')<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>&gt;&gt;&gt; band = dataset.GetRasterBand(1)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>&gt;&gt;&gt; band.ReadAsArray()<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>array([[129,&nbsp; 63, 126],<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [129,&nbsp; 63, 126],<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [129,&nbsp; 63, 126]],
dtype=uint8)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>I expected an array with dtype int8 and the first column to have
values -127. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>I suspect this problem is here in hfadataset.cpp:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp; switch( nHFADataType )<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp; {<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case EPT_u1:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case EPT_u2:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case EPT_u4:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case EPT_u8:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case EPT_s8:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eDataType = GDT_Byte;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#003399'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>GDAL only supports unsigned 8-bit integers (GDT_Byte). That is the
ultimate difficulty but it has been worked around before in other drivers. Is
there any possibility that the HFA driver could be changed to work like the AIG
driver, so that S8 data is returned as GDT_Int16 instead of GDT_Byte? <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>If not, how exactly does this driver support S8 .img files? If I
had some way of detecting that it was S8, I guess I could fix it up by casting
the array to int16 and subtracting 256 from all cells with values &gt; 127. But
I know of no way to detect that it is S8 except by calling an ArcGIS API or
trying to parse .img format myself. Neither of those are a good solution.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>Thanks for your help,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'>Jason<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";
color:#003399'><o:p>&nbsp;</o:p></span></p>

</div>

</body>

</html>