extracted code to obtain grid points for a region
Use separate function to obtain grid, use WITH rather than temporary table