bac_cc

Raster value retrieval (c++)

Discussion created by bac_cc on Sep 5, 2012
Trying to retrieve raster values from a layer. Never seems to get the correct data. Am I forgetting to do something? Colpixel and rowpixel also seem to be wildly off.

 ILayer2Ptr ned = GetLayerView()->GetLayerByName(ned_layer);

 ISpatialReferencePtr mapSpatialRefPtr;
 GetMapView()->m_MapControlPtr->get_SpatialReference(&mapSpatialRefPtr);
 ned->putref_SpatialReference(mapSpatialRefPtr);

 IRasterLayerPtr rastLayerPtr(ned);

 IRasterPtr rastPtr;
 rastLayerPtr->get_Raster(&rastPtr);
 IRaster2Ptr rast2Ptr = (IRaster2Ptr)rastPtr;
 if(rast2Ptr == NULL)
  return;

 while(curLine.GetCurrentPoint() != NULL){
  CPoint *Pnt = curLine.GetCurrentPoint();
 
  long colpixel = 0;
  long rowpixel = 0;

  rast2Ptr->ToPixelColumn(Pnt->x, &colpixel);
  rast2Ptr->ToPixelRow(Pnt->y, &rowpixel);
  
  _variant_t ret;

  rast2Ptr->GetPixelValue(0, colpixel, rowpixel, &ret);

  double val = double(ret);
  Pnt->z = val;
  curLine.NextPoint();
 }

Outcomes