Error returned from IWkb::ExportToWkb() method

434
4
Jump to solution
07-23-2012 11:55 AM
BobCave
New Contributor
Hello,

I am using the IWkb interface to read data from a geometry.  When reading from a file or personal geodatabase, I get the following result:  HR=-2147220968 (E_GEOMETRY_NOTSIMPLE).  When I call ITopologicalOperator::get_IsSimple(), it returns true.  Does anyone know how a geometry can be both simple and non-simple?

Here is the code I am using:

esriGeometry::ITopologicalOperatorPtr topoOp = pGeo; // pGeo initialized earlier   if (topoOp != NULL) {     VARIANT_BOOL isSimple = VARIANT_TRUE;     hr = topoOp->get_IsSimple(&isSimple);  // returns 'true' for the geometry in question       if (VARIANT_FALSE == isSimple)     {         // Simplifies the geometry in place         hr = topoOp->Simplify();     } }   esriGeometry::IWkbPtr ipWkb = pGeo;   long reqSize = 0;  if (FAILED(hr = ipWkb->get_WkbSize(&reqSize))) {     return false; }  esriGeometry::esriGeometryType aoGeoType; hr = pGeo->get_GeometryType(&aoGeoType); unsigned char* pInOutWorkingBuffer = new unsigned char[reqSize];  if (FAILED(hr = ipWkb->ExportToWkb(&reqSize, pInOutWorkingBuffer))) {     // Fails here with hr=-2147220968     return false; }


One other note: the geometry that fails is the first one in the feature class.  The WKB size is 59629.  Is there a limitation on the size of a WKB buffer?

I am using ArcGIS 10.1, ArcObjects C++, Visual Studio 2008.

Thanks,

Bob
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
In order to simplify a geometry, you must use ITopologicalOperator2 and set IsKnownSimple to False.  After that, calling Simplify will simplify the geometry.  If you call Simplify without first setting IsKnownSimple to False, it will exit without doing anything if IsSimple returns true.  IsSimple pretty much returns True all of the time, which is the reason IsKnownSimple was added to the object model.  I don't know that it will solve your problem, but give it a try.

View solution in original post

0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
In order to simplify a geometry, you must use ITopologicalOperator2 and set IsKnownSimple to False.  After that, calling Simplify will simplify the geometry.  If you call Simplify without first setting IsKnownSimple to False, it will exit without doing anything if IsSimple returns true.  IsSimple pretty much returns True all of the time, which is the reason IsKnownSimple was added to the object model.  I don't know that it will solve your problem, but give it a try.
0 Kudos
BobCave
New Contributor
Neil,

Thanks.  That solved the problem.

Another question:  Is there a good way to determine whether or not the geometry needs to be simplified?  The documentation led me to believe that ITopologicalOperator::get_IsSimple() would do that for me, but apparently not.  If I first set IsKnownSimple to false, should IsSimple then tell me whether or not the geometry is simple?  I tried that, and at first it seemed to be working, but there were still cases where IsSimple returned true, but IWkb::ExportToWkb failed.

Cheers,

Bob
0 Kudos
NeilClemmons
Regular Contributor III
If I remember right, features taken from a feature class are assumed to be simple whether or not they actually are.  I don't think there's any way to tell for all geometry types.  If you're working with polygons then I believe you can call IToplogicalOperator3.IsSimpleEx.
0 Kudos
BobCave
New Contributor
OK.  Thanks for the information.
0 Kudos