[Gdal-dev] Finding the row and column in a Raster that includes a point

Johnson, Donald W MVK Contractor Donald.W.Johnson at mvk02.usace.army.mil
Tue Feb 8 16:19:28 EST 2005


I am trying to find the row and column in a raster that contain certain
points my current code 
Is as follows. In case anyone wonders this code is trying to find what cells
in a DEM are covered by a stream who's data points where stored in a .shp
file.


double prj[6];
	
WaterElevation.GetGeoTransform(prj);

double x_delta;
double y_delta;
	
for( unsigned long i = 0; i < points.size(); ++i )
{


	// prj[2] == 0 && prj[4] == 0
	x_delta = points.get_data()[i].get_x() - prj[0];
	y_delta = points.get_data()[i].get_y() - prj[3];

	x_delta /= prj[1];
	y_delta /= prj[5];

	r = (long) y_delta;
	c = (long) x_delta;

	// use row and column
}

This appears to work. However by closly examining my output files I have
found the calculated row position is inncorrect. The row value is initaly
correct for points whose y value is near prj[3] however the r value is
increasingly over estimated as the y value of p[i] moves away from prj[3].
Can anyone tell what I am doing wrong?

Also does GDAL have issues with large files? RasterIO returns CPL_Failure
when I try to read and ESRI grid that is 3.7 gigs. The code works fine on
smaller surfaces.

Thank You
Donald J

 



More information about the Gdal-dev mailing list