[Gdal-dev] OGR Performance Rasterize Contains Overlaps

Jean Michel PIERRET jmp at geosys.com
Tue Jul 17 12:54:41 EDT 2007


Hi,
	
	I would like to get a matrix like with gdal_rasterize in c#, but
with the difference between pixels that are on polygon boundaries and pixels
that are completely inside polygon. It works with the following code but
it's very slow.

Thanks for your help.
Regards.

public void test()
{
	int [, ] mat = new int[width, height];
	Geometry geometry = Geometry.CreateFromWkt("...");

	//Browse each pixel of a raster
	for (i = 0, x = XUL; i < width; x += pixelsizeX, i++)	
      {
  	  for (j = 0, y = YUL; j < height; y += pixelsizeY, j++)
        {
		//x, y are the upper left corner of pixel
		double x1, y1, x2, y2, x3, y3, x4, y4;

		x1 = x;
		y1 = y;

		x2 = x1 + pixelsizeX; 
		y2 = y1;

		x3 = x1 + pixelsizeX; 
		y3 = y1 + pixelsizeY;

		x4 = x1; 
		y4 = y1 + pixelsizeY;

		Geometry geompixel =
Geometry.CreateFromWkt(string.Format("POLYGON(({0} {1}, {2} {3}, {4} {5},
{6} {7}, {0} {1}))", x1, y1, x2, y2, x3, y3, x4, y4));

		//get if pixel is overlap, contains or none by polygon
		if (geometry.Contains(geompixel))
			mat[i, j] = 2;	
		else if (geometry.Overlaps(geompixel))
			mat[i, j] = 1;
		else
			mat[i, j] = 0;

		geompixel.Dispose();
        }
	}

	geometry.Dispose();
}

Jean-michel PIERRET - Poste  376
Tel : +33 (0)5 62 47 80 76
Mail : jmp at geosys.com
GEOSYS SA





More information about the Gdal-dev mailing list