Re: [gdal-dev] OGRLayer.Intersection() question
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 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 >> >>> 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 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 >>>> >>>>> 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 >>>>> 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 >>>>>> >>>>>>> Tamas, >>>>>>> >>>>>>> Sorry the sample code had wrong data source names. Here is the >>>>>>> corre
Re: [gdal-dev] OGRLayer.Intersection() question
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 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 >> >>> 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 >
[gdal-dev] OGRLayer.Intersection() question
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@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGRLayer.Intersection() Question
Hi Ari, I did try passing the two callback arguments as null (trying to ignore). It doesn't seem to work by doing that. Thanks, Dheeraj On Fri, Jul 26, 2013 at 1:09 AM, Ari Jolma wrote: > On 07/01/2013 10:13 PM, Dheeraj Reddy Mamidi wrote: > > Hi All, > > I was trying to perform intersection on two feature classes (shape file > format) using OGRLayer.Intersection(), but have problems making it work > with C# bindings. I am not able to figure out on how to pass the > arguments SWIGTYPE_p_GDALProgressFunc callback > and OSGeo.OGR.SWIGTYPE_p_void callback_data. Can someone please help me > figure out on how to handle these. I keep getting the error "Attempt to > dereference null GDALProgressFunc". I am not sure what that means. > > > I don't know the details of C# bindings but the callback function and the > callback data are by default NULL and you should be able to just ignore > them, i.e., not supply any arguments. > > Ari > > > Please share an example on how to call Intersection routine or some > other routine which takes above mentioned argument types. > > Thank you, > Dheeraj Reddy Mamidi > > > > > ___ > gdal-dev mailing > listgdal-dev@lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/gdal-dev > > > > ___________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev > -- Dheeraj Reddy Mamidi Software Developer The Rothwell Group, L.P. Email: drmam...@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
[gdal-dev] OGRLayer.Intersection() Question
Hi All, I was trying to perform intersection on two feature classes (shape file format) using OGRLayer.Intersection(), but have problems making it work with C# bindings. I am not able to figure out on how to pass the arguments SWIGTYPE_p_GDALProgressFunc callback and OSGeo.OGR.SWIGTYPE_p_void callback_data. Can someone please help me figure out on how to handle these. I keep getting the error "Attempt to dereference null GDALProgressFunc". I am not sure what that means. Please share an example on how to call Intersection routine or some other routine which takes above mentioned argument types. Thank you, Dheeraj Reddy Mamidi ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Creating Raster using Spatial Coordinates (Latitude and Longitude)
I am using C# Gdal library. On Wed, Jan 16, 2013 at 5:25 PM, Dheeraj Reddy Mamidi < drmam...@rothwellgroup.com> wrote: > Hi, > > I am trying to create a Raster using grid of points(with latitude and > longitude values) within an area which are separated at a distance measured > in degrees. At higher latitudes the number of samples reduce that is number > of points for a row reduces. > > When distance between points is determined with a fixed degree, how do I > create a raster where the number of columns for higher latitudes reduces ? > In this case, points for grid at higher latitudes are not exactly above the > points at lower latitudes. Can some one suggest a way to create raster for > spatial coordinates in this case? > > Thanks, > Dheeraj > > > -- Dheeraj Reddy Mamidi Software Developer The Rothwell Group, L.P. Email: drmam...@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
[gdal-dev] Creating Raster using Spatial Coordinates (Latitude and Longitude)
Hi, I am trying to create a Raster using grid of points(with latitude and longitude values) within an area which are separated at a distance measured in degrees. At higher latitudes the number of samples reduce that is number of points for a row reduces. When distance between points is determined with a fixed degree, how do I create a raster where the number of columns for higher latitudes reduces ? In this case, points for grid at higher latitudes are not exactly above the points at lower latitudes. Can some one suggest a way to create raster for spatial coordinates in this case? Thanks, Dheeraj ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
[gdal-dev] Creating Raster using Spatial Coordinates
Hi, I am trying to create a raster (.img format or any other) using some spatial information (using set of points with latitude and longitude). Each point is associated with a value. I need to create a raster file with only those points setting some defined boundary using GDAL (C#). I am new to using GDAL. Can some one help me achieve this? Thanks. -- Dheeraj Reddy Mamidi ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev