[GRASS-SVN] r68452 - grass/trunk/raster/r.resamp.filter

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 17 13:48:12 PDT 2016


Author: mmetz
Date: 2016-05-17 13:48:12 -0700 (Tue, 17 May 2016)
New Revision: 68452

Modified:
   grass/trunk/raster/r.resamp.filter/main.c
Log:
r.resamp.filter: do not use Rast_easting_to_col() because it does ll wrap

Modified: grass/trunk/raster/r.resamp.filter/main.c
===================================================================
--- grass/trunk/raster/r.resamp.filter/main.c	2016-05-17 20:21:16 UTC (rev 68451)
+++ grass/trunk/raster/r.resamp.filter/main.c	2016-05-17 20:48:12 UTC (rev 68452)
@@ -177,8 +177,13 @@
 
     for (col = 0; col < dst_w.cols; col++) {
 	double dx = Rast_col_to_easting(col + 0.5, &dst_w);
+	/* do not use Rast_easting_to_col() because it does ll wrap */
+	/*
 	double x0 = Rast_easting_to_col(dx - f_x_radius, &src_w);
 	double x1 = Rast_easting_to_col(dx + f_x_radius, &src_w);
+	 */
+	double x0 = (dx - f_x_radius - src_w.west) / src_w.ew_res;
+	double x1 = (dx + f_x_radius - src_w.west) / src_w.ew_res;
 	int col0 = (int)floor(x0);
 	int col1 = (int)floor(x1) + 1;
 	int cols = col1 - col0;
@@ -312,7 +317,7 @@
 
 static void filter(void)
 {
-    int cur_row;
+    int cur_row = 0;
     int num_rows = 0;
     int row;
 
@@ -488,6 +493,18 @@
     /* set window to old map */
     Rast_get_cellhd(parm.rastin->answer, "", &src_w);
 
+    if (G_projection() == PROJECTION_LL) {
+	/* try to shift source window to overlap with destination window */
+	while (src_w.west >= dst_w.east && src_w.east - 360.0 > dst_w.west) {
+	    src_w.east -= 360.0;
+	    src_w.west -= 360.0;
+	}
+	while (src_w.east <= dst_w.west && src_w.west + 360.0 < dst_w.east) {
+	    src_w.east += 360.0;
+	    src_w.west += 360.0;
+	}
+    }
+
     /* enlarge source window */
     {
 	double y0 = Rast_row_to_northing(0.5, &dst_w);
@@ -496,8 +513,13 @@
 	double x1 = Rast_col_to_easting(dst_w.cols - 0.5, &dst_w);
 	int r0 = (int)floor(Rast_northing_to_row(y0 + f_y_radius, &src_w) - 0.1);
 	int r1 = (int)ceil(Rast_northing_to_row(y1 - f_y_radius, &src_w) + 0.1);
+	/* do not use Rast_easting_to_col() because it does ll wrap */
+	/*
 	int c0 = (int)floor(Rast_easting_to_col(x0 - f_x_radius, &src_w) - 0.1);
 	int c1 = (int)ceil(Rast_easting_to_col(x1 + f_x_radius, &src_w) + 0.1);
+	*/
+	int c0 = (int)floor((x0 - f_x_radius - src_w.west) / src_w.ew_res - 0.1);
+	int c1 = (int)ceil((x1 + f_x_radius - src_w.west) / src_w.ew_res + 0.1);
 
 	src_w.south -= src_w.ns_res * (r1 - src_w.rows);
 	src_w.north += src_w.ns_res * (-r0);



More information about the grass-commit mailing list