PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_raster_misc.c
Go to the documentation of this file.
1 /*
2  * PostGIS Raster - Raster Types for PostGIS
3  * http://trac.osgeo.org/postgis/wiki/WKTRaster
4  *
5  * Copyright (C) 2012 Regents of the University of California
6  * <bkpark@ucdavis.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "CUnit/Basic.h"
25 #include "cu_tester.h"
26 
29  int rtn;
30  double xw, yw;
31  double gt[6] = {-128.604911499087763, 0.002424431085498, 0, 53.626968388905752, 0, -0.002424431085498};
32 
33  raster = rt_raster_new(1, 1);
34  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
37 
38  rtn = rt_raster_cell_to_geopoint(raster, 0, 0, &xw, &yw, NULL);
39  CU_ASSERT_EQUAL(rtn, ES_NONE);
40  CU_ASSERT_DOUBLE_EQUAL(xw, gt[0], DBL_EPSILON);
41  CU_ASSERT_DOUBLE_EQUAL(yw, gt[3], DBL_EPSILON);
42 
44 }
45 
48  int rtn;
49  double xr, yr;
50  double gt[6] = {-128.604911499087763, 0.002424431085498, 0, 53.626968388905752, 0, -0.002424431085498};
51 
52  raster = rt_raster_new(1, 1);
53  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
56 
57  rtn = rt_raster_geopoint_to_cell(raster, gt[0], gt[3], &xr, &yr, NULL);
58  CU_ASSERT_EQUAL(rtn, ES_NONE);
59  CU_ASSERT_DOUBLE_EQUAL(xr, 0, DBL_EPSILON);
60  CU_ASSERT_DOUBLE_EQUAL(yr, 0, DBL_EPSILON);
61 
63 }
64 
66  rt_raster rast1;
67  rt_raster rast2;
68  rt_raster rast = NULL;
69  int err;
70  double offset[4] = {0.};
71 
72  rast1 = rt_raster_new(4, 4);
73  CU_ASSERT(rast1 != NULL);
74  rt_raster_set_scale(rast1, 1, 1);
75  rt_raster_set_offsets(rast1, -2, -2);
76 
77  rast2 = rt_raster_new(2, 2);
78  CU_ASSERT(rast2 != NULL);
79  rt_raster_set_scale(rast2, 1, 1);
80 
82  rast1, rast2,
83  ET_FIRST,
84  &rast,
85  offset
86  );
87  CU_ASSERT_EQUAL(err, ES_NONE);
88  CU_ASSERT(rast != NULL);
89  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 4);
90  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 4);
91  CU_ASSERT_DOUBLE_EQUAL(offset[0], 0, DBL_EPSILON);
92  CU_ASSERT_DOUBLE_EQUAL(offset[1], 0, DBL_EPSILON);
93  CU_ASSERT_DOUBLE_EQUAL(offset[2], 2, DBL_EPSILON);
94  CU_ASSERT_DOUBLE_EQUAL(offset[3], 2, DBL_EPSILON);
96 
98  rast1, rast2,
99  ET_SECOND,
100  &rast,
101  offset
102  );
103  CU_ASSERT_EQUAL(err, ES_NONE);
104  CU_ASSERT(rast != NULL);
105  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 2);
106  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 2);
107  CU_ASSERT_DOUBLE_EQUAL(offset[0], -2, DBL_EPSILON);
108  CU_ASSERT_DOUBLE_EQUAL(offset[1], -2, DBL_EPSILON);
109  CU_ASSERT_DOUBLE_EQUAL(offset[2], 0, DBL_EPSILON);
110  CU_ASSERT_DOUBLE_EQUAL(offset[3], 0, DBL_EPSILON);
112 
114  rast1, rast2,
116  &rast,
117  offset
118  );
119  CU_ASSERT_EQUAL(err, ES_NONE);
120  CU_ASSERT(rast != NULL);
121  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 2);
122  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 2);
123  CU_ASSERT_DOUBLE_EQUAL(offset[0], -2, DBL_EPSILON);
124  CU_ASSERT_DOUBLE_EQUAL(offset[1], -2, DBL_EPSILON);
125  CU_ASSERT_DOUBLE_EQUAL(offset[2], 0, DBL_EPSILON);
126  CU_ASSERT_DOUBLE_EQUAL(offset[3], 0, DBL_EPSILON);
128 
130  rast1, rast2,
131  ET_UNION,
132  &rast,
133  offset
134  );
135  CU_ASSERT_EQUAL(err, ES_NONE);
136  CU_ASSERT(rast != NULL);
137  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 4);
138  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 4);
139  CU_ASSERT_DOUBLE_EQUAL(offset[0], 0, DBL_EPSILON);
140  CU_ASSERT_DOUBLE_EQUAL(offset[1], 0, DBL_EPSILON);
141  CU_ASSERT_DOUBLE_EQUAL(offset[2], 2, DBL_EPSILON);
142  CU_ASSERT_DOUBLE_EQUAL(offset[3], 2, DBL_EPSILON);
144 
145  rt_raster_set_scale(rast2, 1, 0.1);
147  rast1, rast2,
148  ET_UNION,
149  &rast,
150  offset
151  );
152  CU_ASSERT_NOT_EQUAL(err, ES_NONE);
153  rt_raster_set_scale(rast2, 1, 1);
154 
155  rt_raster_set_srid(rast2, 9999);
157  rast1, rast2,
158  ET_UNION,
159  &rast,
160  offset
161  );
162  CU_ASSERT_NOT_EQUAL(err, ES_NONE);
163  rt_raster_set_srid(rast2, 0);
164 
165  rt_raster_set_skews(rast2, -1, 1);
167  rast1, rast2,
168  ET_UNION,
169  &rast,
170  offset
171  );
172  CU_ASSERT_NOT_EQUAL(err, ES_NONE);
173 
174  cu_free_raster(rast2);
175  cu_free_raster(rast1);
176 }
177 
179  rt_envelope extent;
180  rt_raster rast;
181  double skew[2] = {0.25, 0.25};
182  double scale[2] = {1, -1};
183 
184  extent.MinX = 0;
185  extent.MaxY = 0;
186  extent.MaxX = 2;
187  extent.MinY = -2;
188  extent.UpperLeftX = extent.MinX;
189  extent.UpperLeftY = extent.MaxY;
190 
192  extent,
193  skew,
194  scale,
195  0
196  );
197 
198  CU_ASSERT(rast != NULL);
199  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 2);
200  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 3);
201  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rast), -0.5, DBL_EPSILON);
202  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rast), 0, DBL_EPSILON);
203 
205 }
206 
207 /* register tests */
208 void raster_misc_suite_setup(void);
210 {
211  CU_pSuite suite = CU_add_suite("raster_misc", NULL, NULL);
216 }
217 
static void test_raster_cell_to_geopoint()
static void test_raster_from_two_rasters()
void raster_misc_suite_setup(void)
static void test_raster_compute_skewed_raster()
static void test_raster_geopoint_to_cell()
#define PG_ADD_TEST(suite, testfunc)
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
Definition: rt_raster.c:755
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition: rt_raster.c:727
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
Definition: rt_raster.c:806
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:168
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_raster rt_raster_compute_skewed_raster(rt_envelope extent, double *skew, double *scale, double tolerance)
Definition: rt_raster.c:960
@ ES_NONE
Definition: librtcore.h:180
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_raster.c:363
@ ET_INTERSECTION
Definition: librtcore.h:201
@ ET_UNION
Definition: librtcore.h:202
@ ET_SECOND
Definition: librtcore.h:204
@ ET_FIRST
Definition: librtcore.h:203
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition: rt_raster.c:3361
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
gt
Definition: window.py:77
void cu_free_raster(rt_raster raster)
double MinX
Definition: librtcore.h:165
double UpperLeftY
Definition: librtcore.h:171
double UpperLeftX
Definition: librtcore.h:170
double MaxX
Definition: librtcore.h:166
double MinY
Definition: librtcore.h:167
double MaxY
Definition: librtcore.h:168