why I can't read point data from polyline

2481
2
10-28-2012 05:15 AM
Highlighted
New Contributor
I write an ATL project like logomarkersymbol. I want to read polyline data in Draw function , I use IPointCollectionPtr to read, but failed, the pointcollection is empty. Why???

my code is :

IPolylinePtr spPolyline(Geometry);
           IGeometryCollectionPtr spGeometryCollection(spPolyline);

if(NULL == spGeometryCollection)
  return E_FAIL;

long nGeos=0;
spGeometryCollection->get_GeometryCount(&nGeos);

for (i=0;i<nGeos;i++)
{
  IGeometryPtr spGeometry;
  spGeometryCollection->get_Geometry(i, &spGeometry);
  IPointCollectionPtr spCollection(spGeometry);

  long nPoints=0;
  nPoints = spPointCollection->get_PointCount(&nPoints);

                      //spPolyline, spGeometry and spPointCollection has values, but npoint is empty. why???
                      ??????  
             }
Reply
0 Kudos
2 Replies
Highlighted
Occasional Contributor
spPolyline, spGeometry and spPointCollection has values, but npoint is empty. why???


Have you tried to query IGeometry.IsEmpty? Maybe you just got an empty polyline object, i.e. the collections are defined but the geometry does not contain any points.
Reply
0 Kudos
Highlighted
New Contributor
I've only looked at this for a few minutes, but it looks like you have two bugs here:



...

IPointCollectionPtr spCollection(spGeometry);   // BUG 1: this variable needs to be called "spPointCollection" to match the next use

long nPoints=0;
nPoints = spPointCollection->get_PointCount(&nPoints);  // BUG 2: you are returning your HRESULT into your nPoints variable

...


So here's how I would fix this:

...

IPointCollectionPtr spPointCollection(spGeometry);

long nPoints=0;
HRESULT hr = spPointCollection->get_PointCount(&nPoints);

...

Keep in mind, the reason your points kept returning "0" is because that is the HRESULT code for "OK".  I tested these changes out and they seem to give me good results.

-Sigma3 Engineer
Reply
0 Kudos