[gdal-dev] OGRLayer.Intersection() question

Dheeraj Reddy Mamidi drmamidi at rothwellgroup.com
Thu Oct 10 12:16:22 PDT 2013


Hi Tamas,

Thanks for your response. In fact I don't require progress notification,
but I am not able to ignore those arguments (pass them as null). If I pass
them as null I get error "Attempt to dereference null GDALProgressFunc". If
I just pass those arguments initializing them they way I am doing below in
the sample code, I get  "Attempted to read or write protected memory. This
is often an indication that other memory is corrupt." error.

I am using Gdal 1.10 library.

Here is the sample code..

var spatialReference = new OSGeo.OSR.SpatialReference("");
spatialReference.ImportFromProj4("+proj=longlat +ellps=WGS84 +datum=WGS84
+no_defs");

var driver = OSGeo.OGR.Ogr.GetDriverByName("ESRI Shapefile");

DataSource dataSourceToIntersectOn =
driver.Open(@"C:\Temp\gdal_32\Polygon.shp", 0);
Layer layerToIntersectOn = dataSourceCookieCutter.GetLayerByIndex(0);

DataSource dataSourceToIntersect =
driver.Open(@"C:\Temp\gdal_32\Polyline.shp", 0);
Layer layerToIntersect = dataSourceOriginal.GetLayerByIndex(0);

var intersectedShapeData = driver.CreateDataSource(@"C:\Temp\gdal_32", new
string[] { });
wkbGeometryType wkbGeometryType =
layerOriginal.GetLayerDefn().GetGeomType();
Layer intersectedLayer = intersectedShapeData.CreateLayer("intersection",
spatialReference, wkbGeometryType, new string[] { });

OSGeo.OGR.SWIGTYPE_p_void callback_data = new OSGeo.OGR.SWIGTYPE_p_void(new
IntPtr(5), false, layerToIntersect);

OSGeo.OGR.SWIGTYPE_p_GDALProgressFunc callback = new
SWIGTYPE_p_GDALProgressFunc(new IntPtr(5), false, layerToIntersect);

layerToIntersect.Intersection(layerToIntersectOn, intersectedLayer, new
string[] { "SKIP_FAILURES=YES" }, callback, callback_data); // Line where
it fails


The data that I am trying to intersect (shapefiles are attached).


Thanks,
Dheeraj





On Thu, Oct 10, 2013 at 12:33 PM, Tamas Szekeres <szekerest at gmail.com>wrote:

> Dheeraj,
>
> I don't think the OSGeo.OGR.Layer.Intersection supports progress
> notification. You might probably have encountered a bug which should be
> fixed. Do you have a sample code to reproduce this issue? I would
> specifically interested in the actual geometries have been passed to the
> function.
>
> Best regards,
>
> Tamas
>
>
>
> 2013/10/10 Dheeraj Reddy Mamidi <drmamidi at rothwellgroup.com>
>
>> Hi list,
>>
>> I have troubles with C# bindings of OGR. I was trying to perform
>> intersection on two feature classes (shape file formats) using
>> OSGeo.OGR.Layer.Intersection(), but have problems making it work. I keep
>> getting an error saying "AccessViolationException was unhandled.
>> Attempted to read or write protected memory. This is often an indication
>> that other memory is corrupt.
>>
>> Is the above error something to do with SWIGTYPE_p_GDALProgressFunc
>> callback and OSGeo.OGR.SWIGTYPE_p_void callback_data arguments? I tried
>> passing those parameters null as suggested by some in the forums but I
>> keep getting the error "Attempt to dereference null GDALProgressFunc". I
>> am not sure what that means.
>>
>> And when I instantiate callback as new SWIGTYPE_p_GDALProgressFunc() and
>> new callback_data as new SWIGTYPE_p_void(), I don't get error Attempt to dereference
>> null GDALProgressFunc, but still have error saying AccessViolationException
>> was unhandled. Attempted to read or write protected memory. This is often
>> an indication that other memory is corrupt.
>>
>> Can someone please help me figure this out and let me know how to make
>> use of OSGeo.OGR.Layer.Intersection() in the right way with c# bindings.
>> Thank you.
>>
>> Thanks,
>> Dheeraj
>>
>>
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>


--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131010/c49d7178/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Shapefiles.zip
Type: application/zip
Size: 18268 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131010/c49d7178/attachment-0001.zip>


More information about the gdal-dev mailing list