I have some points in an array,stored by user click on the map in ArcMap,and I want to build a polyline and create a Well Known Binary sequence.

I use IPointCollection interface to add this points to Polyline object,and when I draw this polyline,it shows line successfully but the function "CreateWkbVariantFromGeometry" returns E_OUTOFMEMORY error when I pass this geometry into it.What's wrong with this method for creating a plolyline?

IPolylinePtr ipPL(CLSID_Polyline);

IPointCollectionPtr ipPC;

        return E_FAIL;
for(int i=0;i<myPointCount;i++)
    IPointPtr ipP=this->GetPoint(i);
        return E_FAIL;
        return E_FAIL;
IGeometryPtr ipG;
    return E_FAIL;

//.Drawing line on the screen catch . ipS is a SimpleLineSymbol object
//....................................................StartDrawing here
if(this->m_ipSDisplay->DrawPolyline(ipG)=S_OK)//This line works successfully
    return E_FAIL;
//....................................................FinishDrawing here

//.Building WKB from geometry
IGeometryFactory2Ptr ipGF;
IGeometryEnvironmentPtr ipGE(CLSID_GeometryEnvironment);
    return E_FAIL;
HRESULT hr=ipGF->CreateWkbVariantFromGeometry(ipG,&var);//hr=E_OUTOFMEMORY
    return E_FAIL;
  • Did you try assiging a spatial reference to both the polyline as well as each point (ipP) that you add to it first? Feb 28, 2011 at 1:53
  • yes Kirk,after your comment,I added spatial reference to both points and line,but not working properly.Then I build 2 point simple lines(ILine) as segments with each points pair([0,1],[1,2],[2,3],..) and built a polyline using ISegmentCollection,but not working again.I'm sure there is a problem with the method I build polyline,but I don't know why IScreenDisplay::DrawPolyline can work with it.
    – Reza
    Feb 28, 2011 at 18:31

1 Answer 1


There is a much easier solution. Just QI to IWKB and use the ExportToWkb method. This is an extract of the arcobjects driver I wrote for GDAL:


  esriGeometry::IWkbPtr ipWkb = pInAOGeo;

  long reqSize = 0;

  if (FAILED(hr = ipWkb->get_WkbSize(&reqSize)))
    AOErr(hr, "Error getting Wkb buffer size");
    return false;

  if (reqSize > inOutBufferSize)
    // resize working buffer
    delete [] pInOutWorkingBuffer;
    pInOutWorkingBuffer = new unsigned char[reqSize];
    inOutBufferSize = reqSize;

  if (FAILED(hr = ipWkb->ExportToWkb(&reqSize, pInOutWorkingBuffer)))
    AOErr(hr, "Error exporting to WKB buffer");
    return false;

You can find the complete code in the GDAL SVN. I know it works, so hopefully this helps...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.