Vishful thinking…

ESRI bug on performing a spatial query with a GeometryBag containing multiple shapes against SDE

Posted in ArcGIS, ESRI by viswaug on August 20, 2007

This is an bug that I came up on when building some productivity tools for ArcMAP. It is interesting to note that this bug was introduced in ArcGIS 9.2 while ArcGIS 9.1 works fine. The bug took me by surprise since the bug happens in the core geometry functions of the ArcObjects library.

The feature I was building was performing a pretty simple spatial query operation using a SpatialFilter object on a featureclass. The featureclass against which the query was being performed was in a SDE database. Much to my chagrin, I came to find out that this bug occurs only when the featureclass is a SDE featureclass and not when it is from a file geodatabase. That doesn’t help too much cause our customers expect the application to work everywhere. Getting back to the SpatialFilter, the geometry being used in the filter was a GeometryBag containing more than one feature. On running the query, the results weren’t as expected. Even though, the GeometryBag contained more than one geometry in it, the results returned corresponded only to the first geometry in the GeometryBag. After, spending quite a bit of time figuring out all the cases when the error occurred I was able to contact ESRI support and confirm this as an issue and obtain an incident number.

#NIM010450 – SelectFeatures with a spatial query does not work when using a query geometry which is a GeometryBag with more than one feature in it.

Now, we just have to sit on our hands and wait patiently for ESRI to get around to fixing it. I was actually excited when ESRI had announced that they were making the effort to publish the list of known software defects online by August 2007. But this latest blog entry from the ESRI support center doesn’t sound too promising.

Persisting ESRI objects to the database

Posted in .NET, ArcGIS, ESRI by viswaug on August 20, 2007

A little while ago, I was trying to persist some objects implementing the IPersistStream to the database. The database was MS SQL Server 2005 and the field type where the object was going to be stored was VARBINARY(MAX). The field was exposed in the DAL as an Byte array like it is supposed to be. So, now I had to write my objects implementing IPersistStream into an byte array. This took me a little while to figure out but turned to be simple enough. When, I had to do this before, I was writing to a table in a personal geodatabase. This was pretty straightforward since I was accessing and updating the storage table using ESRI’s ITable interfaces. In that case, I simply serialized my objects to a MemoryBlobStream and the wrote the MemoryBlobStream object into the table using the “Value” property on IRow. But this wouldn’t work for the current MS SQL server tables since I wasn’t accessing in through the ITable interface. So, I HAD to convert my MemoryBlobStream into an byte array. This is where the IMemoryBlobStreamVariant interface comes in handy. The following is how I was able to convert the MemoryBlobStream object to an byte array.

        Dim s As MemoryBlobStream = New MemoryBlobStream()

        Dim os As IObjectStream = New ObjectStream()

        os.Stream = TryCast(s, ESRI.ArcGIS.esriSystem.IStream)

        pitem.Save(os, 0)

 

        Dim content As Object = Nothing

        Dim mvar As IMemoryBlobStreamVariant = TryCast(s, IMemoryBlobStreamVariant)

        mvar.ExportToVariant(content)

        Dim bContent As Byte() = CType(content, Byte())