[gdal-dev] OSGeo.OGR.Layer.Clip in C# application

Ellis Robin (Bundaberg) Robin.Ellis at science.dsitia.qld.gov.au
Thu Dec 12 16:31:58 PST 2013


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:

 

Attempt to write non-polygon (GEOMETRYCOLLECTION) geometry to POLYGON
type shapefile

 

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.

 

Thanks very much

 

Rob

 

public static Layer clipAGdalDSByAnother(DataSource baseDS, DataSource
clipDS)

{

    Layer baseLayer = baseDS.GetLayerByIndex(0);

    Layer clipLayer = clipDS.GetLayerByIndex(0);

 

    string newDataName = "tester.shp";

 

    Layer layer;

 

    int i;

    for (i = 0; i < baseDS.GetLayerCount(); i++)

    {

        layer = baseDS.GetLayerByIndex(i);

        if (layer != null && layer.GetLayerDefn().GetName() ==
newDataName)

        {

            Console.WriteLine("Layer already existed. Recreating
it.\n");

            baseDS.DeleteLayer(i);

            break;

        }

    }

           

    Layer result = baseDS.CreateLayer(newDataName, null,
baseLayer.GetLayerDefn().GetGeomType(), new string[] { });

 

    baseLayer.Clip(clipLayer, result, new string[] { "SKIP_FAILURES=YES"
}, null, null);

 

    return result;

}

 


***************************** Disclaimer  *****************************

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.
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.

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131213/fbb46e67/attachment.html>


More information about the gdal-dev mailing list