Hi Tamas, I was working with OsGeo.OGR.Layer.Intersection c# bindings and have problems with setting string[] of options. The intersection of layers are creating some invalid geometries to write in to intersected layer (Error is thrown - ApplicationException was unhandled - Attempt to write non-polygon (GEOMETRYCOLLECTION) geometry to POLYGON type shapefile). I read the documentation and saw options can be enabled like SKIP_FAILURES=YES to skip and continue if feature cannot be inserted, but setting option the way I did below to skip still throws the above error.
string[] options = new string[] {"SKIP_FAILURES=YES"}; layerOriginal.Intersection(layerToIntersect, intersectedLayer, options, new Ogr.GDALProgressFuncDelegate(ProgressFunc), "Intersection"); Can you help me figure out how to set the options parameter to Intersection method ? Thank you. Thanks, Dheeraj On Fri, Oct 11, 2013 at 11:25 AM, Dheeraj Reddy Mamidi < drmam...@rothwellgroup.com> wrote: > Tamas, > > You are right. Output shapefile cannot have mixed geometries in the same > file. But two input shapefiles (layers) can be of different geometries > types to perform operations like intersection. > > > Thanks, > Dhheraj > > > On Fri, Oct 11, 2013 at 11:19 AM, Tamas Szekeres <szeker...@gmail.com>wrote: > >> You may probably leave this checking out, I 'm not sure about all aspects >> of these functions. Actually the output file is a shapefile which doesn't >> support mixed geometries in the same file. >> >> Tamas >> >> >> >> >> 2013/10/11 Dheeraj Reddy Mamidi <drmam...@rothwellgroup.com> >> >>> Tamas, >>> >>> Thank you very much for fixing the issue so quickly! I really appreciate >>> it. That really saved lot of time for me to figure out what was wrong. >>> >>> One thing that I would like to discuss is with regards to >>> http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/OGRLayerAlg.cs >>> (sample >>> application). >>> >>> Line 108: >>> >>> if (layer1.GetLayerDefn().GetGeomType() != >>> layer2.GetLayerDefn().GetGeomType()) >>> { >>> Console.WriteLine("FAILURE: Geometry type doesn't match"); >>> System.Environment.Exit(-1); >>> } >>> >>> In the above line where you check if geometry type of layer1 and layer2 >>> are equal, If not equal you say Geometry type do not match. I was wondering >>> layer geometry types can be different (eg a polygon shapefile and polyline >>> shapefile etc) to do intersection right ? >>> >>> >>> Thanks, >>> Dheeraj >>> >>> >>> >>> >>> >>> On Fri, Oct 11, 2013 at 3:19 AM, Tamas Szekeres <szeker...@gmail.com>wrote: >>> >>>> 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 <drmam...@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 >>>>> <szeker...@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 <drmam...@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 < >>>>>>> drmam...@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 < >>>>>>>> szeker...@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 <drmam...@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@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: drmam...@rothwellgroup.com <atvaug...@rothwellgroup.com> >>>>> Phone: 713-952-5355 ext.30 >>>>> Web: www.rothwellgroup.com >>>>> >>>> >>>> >>> >>> >>> -- >>> Dheeraj Reddy Mamidi >>> >>> Software Developer >>> The Rothwell Group, L.P. >>> Email: drmam...@rothwellgroup.com <atvaug...@rothwellgroup.com> >>> Phone: 713-952-5355 ext.30 >>> Web: www.rothwellgroup.com >>> >> >> > > > -- > Dheeraj Reddy Mamidi > > Software Developer > The Rothwell Group, L.P. > Email: drmam...@rothwellgroup.com <atvaug...@rothwellgroup.com> > Phone: 713-952-5355 ext.30 > Web: www.rothwellgroup.com > -- Dheeraj Reddy Mamidi Software Developer The Rothwell Group, L.P. Email: drmam...@rothwellgroup.com <atvaug...@rothwellgroup.com> Phone: 713-952-5355 ext.30 Web: www.rothwellgroup.com
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev