<div dir="ltr"><div class="gmail_default" style="font-size:small">Awesome, thanks! <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 14, 2019 at 9:39 AM Martin Chapman <<a href="mailto:mchapman@hyperacktive.com">mchapman@hyperacktive.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="gmail-m_2117976389129010773WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Ahmet,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">You can use either the gdalwarp.exe or the underlying gdal warper C++ API to create a new image using the polygon geometry as a cutline.  See the gdalwarp.exe or gdal warper C++ API documentation on how to do that.  <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Basically, the cutline geometry will NULL out any pixels in the output image that are not within the polygon geometry.  If you use the gdalwarp.exe utility it will output a new image to disk.  If you use the gdal warper C++ API then you can write the output image to disk or memory.  For more information on how this is done programmatically see the source code for the gdalwarp.exe that is included with the gdal source code.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">NOTE:  Your cutline geometry needs to be topologically correct in order to produce good output.  Topologically correct geometries do not contain self-intersections, slivers, etc.  An example of a self-intersecting geometry is a bow-tie where two lines in the geometry cross each other.  Slivers are where two adjacent geometries share an edge but there is a gap between the edges.  Lots of shape files contain geometries that are not topologically correct because ArcMap and other tools don’t enforce that.  The warp API can handle polygons and multi-polygons.  If your output comes out looking screwed up it is most likely because your cutline geometry is not topologically correct OR you didn’t convert the cutline geometry from coordinate space to pixel space before feeding it to the warper C++ API (in the case you do it programmatically).  The gdalwarp.exe can handle geometries in coordinate space.  If by chance your cutline geometry is not topologically correct you may be able to fix it by doing a Buffer() operation on it using the OGR API with a buffer distance of 0.  GEOS (the underlying engine for the OGR buffer operation) will create a new geometry that is exactly the same as the input because the buffer distance is zero but the GEOS API will attempt to correct the topology of the new geometry.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Best regards,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Martin Chapman<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">  <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"> gdal-dev [mailto:<a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a>] <b>On Behalf Of </b>Ahmet Temiz<br><b>Sent:</b> Saturday, November 9, 2019 9:57 AM<br><b>To:</b> gdal-dev<br><b>Subject:</b> [gdal-dev] extracting a raster data within a polygon?<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><span style="color:rgb(49,49,49);background:white">Hi,<u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="color:rgb(49,49,49);background:white">how I can extract a raster data within a polygon (not a rectangle) using C++?<u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="color:rgb(49,49,49);background:white">i.e. dem within provincial boundary<u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="color:rgb(49,49,49);background:white">Regards<u></u><u></u></span></p></div><p class="MsoNormal">-- <u></u><u></u></p><div><div><div><div><div><p class="MsoNormal">Ahmet Temiz<br>Jeoloji Müh.<br>Afet ve Acil Durum Yönetimi Başkanlığı<br>Bilgi İşlem  Dairesi Başkanlığı-CBS Grubu<br><br><br>________________________<br><br>Ahmet Temiz<br>Geological Eng.<br>Information Systems - GIS Group<br>Disaster and Emergency Management<br>of Presidency<u></u><u></u></p></div></div></div></div></div></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Ahmet Temiz<br>Jeoloji Müh.<br>Afet ve Acil Durum Yönetimi Başkanlığı<br>Bilgi İşlem  Dairesi Başkanlığı-CBS Grubu<br><br><br>________________________<br><br>Ahmet Temiz<br>Geological Eng.<br>Information Systems - GIS Group<br>Disaster and Emergency Management<br>of Presidency</div></div></div></div></div>