<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 14 (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:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 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:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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-AU link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>As an update, this would appear to be a topological issue with my input shapefile. I can successfully complete Intersection processes using the method described previously if I use simple data inputs. Similarly, I can complete a Clip process on simple data inputs, although the results aren’t always entirely as expected. If I hook up the GDALProgressFuncDelegate I do notice this message pops up during intersection/clip of complex inputs:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>'System.ApplicationException' occurred in ogr_csharp.dll<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Which ultimately leads to the GEOMETRYCOLLECTION error reported previously. I can only assume that clean topology will avoid this.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Regards<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Rob<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-AU'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-AU'> gdal-dev-bounces@lists.osgeo.org [mailto:gdal-dev-bounces@lists.osgeo.org] <b>On Behalf Of </b>Ellis Robin (Bundaberg)<br><b>Sent:</b> Friday, 13 December 2013 10:32 AM<br><b>To:</b> gdal-dev@lists.osgeo.org<br><b>Subject:</b> [gdal-dev] OSGeo.OGR.Layer.Clip in C# application<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’m working in Win 7 x64 and  VS2010 using gdal/ogr compiled libraries in a C# project (libraries from ‘release-1600-x64-dev.zip’, built 12/12/2013). I can successfully open two polygon shapefiles as ‘DataSource’ objects, however when I attempt to clip one shapefile by the other I get this error message:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Attempt to write non-polygon (GEOMETRYCOLLECTION) geometry to POLYGON type shapefile<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My code is posted below, any assistance appreciated. I’m happy to read more documentation/examples if somebody can point me in the right direction.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks very much<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Rob<o:p></o:p></p><p class=MsoNormal style='text-autospace:none'><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:blue'>public</span><span style='font-size:9.5pt;font-family:Consolas'> <span style='color:blue'>static</span> <span style='color:#2B91AF'>Layer</span> clipAGdalDSByAnother(<span style='color:#2B91AF'>DataSource</span> baseDS, <span style='color:#2B91AF'>DataSource</span> clipDS)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>{<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:#2B91AF'>Layer</span> baseLayer = baseDS.GetLayerByIndex(0);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:#2B91AF'>Layer</span> clipLayer = clipDS.GetLayerByIndex(0);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:blue'>string</span> newDataName = <span style='color:#A31515'>"tester.shp"</span>;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:#2B91AF'>Layer</span> layer;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:blue'>int</span> i;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:blue'>for</span> (i = 0; i < baseDS.GetLayerCount(); i++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>        layer = baseDS.GetLayerByIndex(i);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>        <span style='color:blue'>if</span> (layer != <span style='color:blue'>null</span> && layer.GetLayerDefn().GetName() == newDataName)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>        {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>            <span style='color:#2B91AF'>Console</span>.WriteLine(<span style='color:#A31515'>"Layer already existed. Recreating it.\n"</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>            baseDS.DeleteLayer(i);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>            <span style='color:blue'>break</span>;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>        }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>           <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:#2B91AF'>Layer</span> result = baseDS.CreateLayer(newDataName, <span style='color:blue'>null</span>, baseLayer.GetLayerDefn().GetGeomType(), <span style='color:blue'>new</span> <span style='color:blue'>string</span>[] { });<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    baseLayer.Clip(clipLayer, result, <span style='color:blue'>new</span> <span style='color:blue'>string</span>[] { <span style='color:#A31515'>"SKIP_FAILURES=YES"</span> }, <span style='color:blue'>null</span>, <span style='color:blue'>null</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>    <span style='color:blue'>return</span> result;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>}<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p><span style='font-size:7.5pt;font-family:"Courier New"'>***************************** Disclaimer  *****************************</span><o:p></o:p></p><p><span style='font-size:7.5pt;font-family:"Courier New"'>The contents of this electronic message and any attachments are intended only for the addressee and may contain privileged or confidential information. They may only be used for the purposes for which they were supplied. If you are not the addressee, you are notified that any transmission, distribution, downloading, printing or photocopying of the contents of this message or attachments is strictly prohibited.<br>The privilege of confidentiality attached to this message and attachments is not waived, lost or destroyed by reason of mistaken delivery to you. If you receive this message in error please notify the sender by return e-mail or telephone.</span><o:p></o:p></p><p><span style='font-size:7.5pt;font-family:"Courier New"'>Please note: the Department of Science, Information Technology, Innovation and the Arts carries out automatic software scanning, filtering and blocking of E-mails and attachments (including emails of a personal nature) for detection of viruses, malicious code, SPAM, executable programs or content it deems unacceptable. All reasonable precautions will be taken to respect the privacy of individuals in accordance with the Information Privacy Act 2009 (Qld). Personal information will only be used for official purposes, e.g. monitoring Departmental Personnel's compliance with Departmental Policies. Personal information will not be divulged or disclosed to others, unless authorised or required by Departmental Policy and/or law.</span><o:p></o:p></p></div></body></html>