PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_convex_hull()

static void test_raster_convex_hull ( )
static

Definition at line 166 of file cu_raster_geometry.c.

References cu_free_raster(), ES_NONE, getPoint4d_p(), LINETYPE, lwgeom_as_lwpoly(), lwgeom_free(), POINTARRAY::npoints, LWPOLY::nrings, POINTTYPE, rtrowdump::raster, LWPOLY::rings, rt_raster_get_convex_hull(), rt_raster_get_srid(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_set_skews(), LWPOLY::srid, LWGEOM::type, POINT4D::x, and POINT4D::y.

Referenced by raster_geometry_suite_setup().

166  {
167  rt_raster raster = NULL;
168  LWGEOM *hull = NULL;
169  LWPOLY *poly = NULL;
170  POINTARRAY *ring = NULL;
171  POINT4D pt;
172 
173  /* NULL raster */
174  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(NULL, &hull), ES_NONE);
175  CU_ASSERT(hull == NULL);
176 
177  /* width = 0, height = 0 */
178  raster = rt_raster_new(0, 0);
179  CU_ASSERT(raster != NULL);
180 
181  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
182  CU_ASSERT_EQUAL(hull->type, POINTTYPE);
183  lwgeom_free(hull);
184  cu_free_raster(raster);
185 
186  /* width = 0 */
187  raster = rt_raster_new(0, 256);
188  CU_ASSERT(raster != NULL);
189 
190  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
191  CU_ASSERT_EQUAL(hull->type, LINETYPE);
192  lwgeom_free(hull);
193  cu_free_raster(raster);
194 
195  /* height = 0 */
196  raster = rt_raster_new(256, 0);
197  CU_ASSERT(raster != NULL);
198 
199  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
200  CU_ASSERT_EQUAL(hull->type, LINETYPE);
201  lwgeom_free(hull);
202  cu_free_raster(raster);
203 
204  /* normal raster */
205  raster = rt_raster_new(256, 256);
206  CU_ASSERT(raster != NULL);
207 
208  rt_raster_set_offsets(raster, 0.5, 0.5);
209  rt_raster_set_scale(raster, 1, 1);
210  rt_raster_set_skews(raster, 4, 5);
211 
212  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
213  poly = lwgeom_as_lwpoly(hull);
214  CU_ASSERT_EQUAL(poly->srid, rt_raster_get_srid(raster));
215  CU_ASSERT_EQUAL(poly->nrings, 1);
216 
217  ring = poly->rings[0];
218  CU_ASSERT(ring != NULL);
219  CU_ASSERT_EQUAL(ring->npoints, 5);
220 
221  getPoint4d_p(ring, 0, &pt);
222  CU_ASSERT_DOUBLE_EQUAL(pt.x, 0.5, DBL_EPSILON);
223  CU_ASSERT_DOUBLE_EQUAL(pt.y, 0.5, DBL_EPSILON);
224 
225  getPoint4d_p(ring, 1, &pt);
226  CU_ASSERT_DOUBLE_EQUAL(pt.x, 256.5, DBL_EPSILON);
227  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1280.5, DBL_EPSILON);
228 
229  getPoint4d_p(ring, 2, &pt);
230  CU_ASSERT_DOUBLE_EQUAL(pt.x, 1280.5, DBL_EPSILON);
231  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1536.5, DBL_EPSILON);
232 
233  getPoint4d_p(ring, 3, &pt);
234  CU_ASSERT_DOUBLE_EQUAL(pt.x, 1024.5, DBL_EPSILON);
235  CU_ASSERT_DOUBLE_EQUAL(pt.y, 256.5, DBL_EPSILON);
236 
237  getPoint4d_p(ring, 4, &pt);
238  CU_ASSERT_DOUBLE_EQUAL(pt.x, 0.5, DBL_EPSILON);
239  CU_ASSERT_DOUBLE_EQUAL(pt.y, 0.5, DBL_EPSILON);
240 
241  lwgeom_free(hull);
242  cu_free_raster(raster);
243 }
double x
Definition: liblwgeom.h:352
#define LINETYPE
Definition: liblwgeom.h:86
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
int npoints
Definition: liblwgeom.h:371
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
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:174
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_geometry.c:803
void cu_free_raster(rt_raster raster)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
int32_t srid
Definition: liblwgeom.h:454
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:352
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Here is the call graph for this function:
Here is the caller graph for this function: