[gdal-dev] OSGeo.OGR.Layer.Clip in C# application
Ellis Robin (Bundaberg)
Robin.Ellis at science.dsitia.qld.gov.au
Sun Dec 15 21:12:20 PST 2013
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:
'System.ApplicationException' occurred in ogr_csharp.dll
Which ultimately leads to the GEOMETRYCOLLECTION error reported
previously. I can only assume that clean topology will avoid this.
Regards
Rob
From: gdal-dev-bounces at lists.osgeo.org
[mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Ellis Robin
(Bundaberg)
Sent: Friday, 13 December 2013 10:32 AM
To: gdal-dev at lists.osgeo.org
Subject: [gdal-dev] OSGeo.OGR.Layer.Clip in C# application
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/20131216/d87d8a29/attachment.html>
More information about the gdal-dev
mailing list