[gdal-dev] OGRLayer.Intersection() question

Tamas Szekeres szekerest at gmail.com
Fri Oct 11 02:19:22 PDT 2013


Dheeraj,

The issue is now fixed in trunk and branch-1-10 (check out the latest
sources)
I've also added a sample application for these methods:
http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/OGRLayerAlg.cs

Best regards,

Tamas



2013/10/10 Dheeraj Reddy Mamidi <drmamidi at rothwellgroup.com>

> Tamas,
>
> I appreciate you adding a ticket for this issue. Thanks. Is there any
> other option for me to use OGRLayer intersection with out C# bindings for
> now ?
>
>
> Thanks,
> Dheeraj
>
>
>
> On Thu, Oct 10, 2013 at 2:21 PM, Tamas Szekeres <szekerest at gmail.com>wrote:
>
>> Dheeraj,
>>
>> I noticed you are talking about the layer level geometry functions, which
>> hasn't been updated in the C# bindings yet. I'll add the necessary
>> implementation shorly. Also added a ticket to track the changes:
>> http://trac.osgeo.org/gdal/ticket/5264
>>
>> Best regards,
>>
>> Tamas
>>
>>
>>
>>
>> 2013/10/10 Dheeraj Reddy Mamidi <drmamidi at rothwellgroup.com>
>>
>>> Tamas,
>>>
>>> Sorry the sample code had wrong data source names. Here is the corrected
>>> 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 = dataSourceToIntersectOn.GetLayerByIndex(0);
>>>
>>> DataSource dataSourceToIntersect =
>>> driver.Open(@"C:\Temp\gdal_32\Polyline.shp", 0);
>>> Layer layerToIntersect = dataSourceToIntersect.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
>>>
>>>
>>> Thanks,
>>> Dheeraj
>>>
>>>
>>> On Thu, Oct 10, 2013 at 1:16 PM, Dheeraj Reddy Mamidi <
>>> drmamidi at rothwellgroup.com> wrote:
>>>
>>>> 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 butI 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
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>>
>>>
>>>
>>> --
>>> Dheeraj Reddy Mamidi
>>>
>>>
>>
>
>
> --
> Dheeraj Reddy Mamidi
>
> Software Developer
> The Rothwell Group, L.P.
> Email: drmamidi at rothwellgroup.com <atvaughan at rothwellgroup.com>
> Phone: 713-952-5355 ext.30
> Web: www.rothwellgroup.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131011/5c56fad5/attachment-0001.html>


More information about the gdal-dev mailing list