Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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;

if(ipPL->QueryInterface(IID_IPointCollection,(void**)&ipPC)!=S_OK)
        return E_FAIL;
for(int i=0;i<myPointCount;i++)
{
    IPointPtr ipP=this->GetPoint(i);
    if(this->m_ipDispTrn->ToMapPoint(this->m_Points[i].x,this->m_Points[i].y,&ipP)!=S_OK)
        return E_FAIL;
    if(ipPC->AddPoint(ipP)!=S_OK)
        return E_FAIL;
}
IGeometryPtr ipG;
if(ipPL->QueryInterface(IID_IGeometry,(void**)&ipG)!=S_OK)
    return E_FAIL;

//.Drawing line on the screen catch . ipS is a SimpleLineSymbol object
//....................................................StartDrawing here
this->m_ipSDisplay->SetSymbol(ipS);
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);
if(ipGE->QueryInterface(IID_IGeometryFactory2,(void**)&ipGF)!=S_OK)
    return E_FAIL;
VARIANT var;
HRESULT hr=ipGF->CreateWkbVariantFromGeometry(ipG,&var);//hr=E_OUTOFMEMORY
if(hr!=S_OK)
    return E_FAIL;
share|improve this question
    
Did you try assiging a spatial reference to both the polyline as well as each point (ipP) that you add to it first? –  Kirk Kuykendall Feb 28 '11 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 '11 at 18:31
add comment

1 Answer

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:

  HRESULT hr;

  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...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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