<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 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 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:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></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="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>I sure hope someone can give me some advice. I'm modestly experienced with GIS and spatial stuff, but I'm trying to do rasters in C++ for the first time. I've been cobbling experiments together, generally successfully, but have not consistently been able to get a raster read working, and I don't know C++ or GDAL deeply enough to understand what to do.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Code is snapshotted below. Using Windows, Visual Studio 2017. If I enable the 5 lines in the inner loop near the bottom, I get an Exception/Access Violation on the “inDS->GetRasterBand(etc)” statement. If I disable that section, and specifically that line, it runs to completion without problem. Can anyone suggest what I might try? Thanks for helping!<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>*************************<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:gray'>#include</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>"stdafx.h"</span><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:gray'>#include</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'><iostream></span><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:gray'>#include</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'><gdal.h></span><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:gray'>#include</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'><gdal_priv.h></span><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:gray'>#include</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>"cpl_conv.h"</span><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:blue'>using</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>namespace</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> std;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:blue'>int</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> main()<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'>{<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#2B91AF'>GDALDataset</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> *inDS;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> GDALAllRegister();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>const</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>char</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> *input = </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>"D:/Imagery/CDLClipped.tif"</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> inDS = (</span><span style='font-size:9.5pt;font-family:Consolas;color:#2B91AF'>GDALDataset</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>*) GDALOpen(input, </span><span style='font-size:9.5pt;font-family:Consolas;color:darkslategray'>GA_ReadOnly</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>if</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> (inDS == </span><span style='font-size:9.5pt;font-family:Consolas;color:#6F008A'>NULL</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> cout </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>"unable to open input"</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> endl;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>int</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> nRows, nCols;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>double</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> transform[6];<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>double</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> noData;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> nRows = inDS->GetRasterBand(1)->GetYSize();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> nCols = inDS->GetRasterBand(1)->GetXSize();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> noData = inDS->GetRasterBand(1)->GetNoDataValue();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> inDS->GetGeoTransform(transform);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> cout </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>"nRows, nCols, noData = "</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> nRows </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>", "</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> nCols </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:#A31515'>", "</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> noData </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> endl;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>float</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> *inDSRow = (</span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>float</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>*)CPLMalloc(</span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>sizeof</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>(</span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>float</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>)*nCols);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>for</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> (</span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>int</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> i = 0; i < 5; i++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> inDS->GetRasterBand(1)->RasterIO(</span><span style='font-size:9.5pt;font-family:Consolas;color:darkslategray'>GF_Read</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>, 0, i, nCols, 1, inDSRow, nCols, 1, </span><span style='font-size:9.5pt;font-family:Consolas;color:darkslategray'>GDT_CFloat32</span><span style='font-size:9.5pt;font-family:Consolas;color:black'>, 0, 0);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> </span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>for</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> (</span><span style='font-size:9.5pt;font-family:Consolas;color:blue'>int</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> j = 0; j < 5 ; j++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> cout </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> inDSRow[j] </span><span style='font-size:9.5pt;font-family:Consolas;color:teal'><<</span><span style='font-size:9.5pt;font-family:Consolas;color:black'> endl;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:black'> cin.ignore();<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.5pt;font-family:Consolas;color:black'>}</span><o:p></o:p></p></div></body></html>