PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_raster_convex_hull ( )
static

Definition at line 27 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().

27  {
28  rt_raster raster = NULL;
29  LWGEOM *hull = NULL;
30  LWPOLY *poly = NULL;
31  POINTARRAY *ring = NULL;
32  POINT4D pt;
33 
34  /* NULL raster */
35  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(NULL, &hull), ES_NONE);
36  CU_ASSERT(hull == NULL);
37 
38  /* width = 0, height = 0 */
39  raster = rt_raster_new(0, 0);
40  CU_ASSERT(raster != NULL);
41 
42  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
43  CU_ASSERT_EQUAL(hull->type, POINTTYPE);
44  lwgeom_free(hull);
45  cu_free_raster(raster);
46 
47  /* width = 0 */
48  raster = rt_raster_new(0, 256);
49  CU_ASSERT(raster != NULL);
50 
51  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
52  CU_ASSERT_EQUAL(hull->type, LINETYPE);
53  lwgeom_free(hull);
54  cu_free_raster(raster);
55 
56  /* height = 0 */
57  raster = rt_raster_new(256, 0);
58  CU_ASSERT(raster != NULL);
59 
60  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
61  CU_ASSERT_EQUAL(hull->type, LINETYPE);
62  lwgeom_free(hull);
63  cu_free_raster(raster);
64 
65  /* normal raster */
66  raster = rt_raster_new(256, 256);
67  CU_ASSERT(raster != NULL);
68 
69  rt_raster_set_offsets(raster, 0.5, 0.5);
70  rt_raster_set_scale(raster, 1, 1);
71  rt_raster_set_skews(raster, 4, 5);
72 
73  CU_ASSERT_EQUAL(rt_raster_get_convex_hull(raster, &hull), ES_NONE);
74  poly = lwgeom_as_lwpoly(hull);
75  CU_ASSERT_EQUAL(poly->srid, rt_raster_get_srid(raster));
76  CU_ASSERT_EQUAL(poly->nrings, 1);
77 
78  ring = poly->rings[0];
79  CU_ASSERT(ring != NULL);
80  CU_ASSERT_EQUAL(ring->npoints, 5);
81 
82  getPoint4d_p(ring, 0, &pt);
83  CU_ASSERT_DOUBLE_EQUAL(pt.x, 0.5, DBL_EPSILON);
84  CU_ASSERT_DOUBLE_EQUAL(pt.y, 0.5, DBL_EPSILON);
85 
86  getPoint4d_p(ring, 1, &pt);
87  CU_ASSERT_DOUBLE_EQUAL(pt.x, 256.5, DBL_EPSILON);
88  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1280.5, DBL_EPSILON);
89 
90  getPoint4d_p(ring, 2, &pt);
91  CU_ASSERT_DOUBLE_EQUAL(pt.x, 1280.5, DBL_EPSILON);
92  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1536.5, DBL_EPSILON);
93 
94  getPoint4d_p(ring, 3, &pt);
95  CU_ASSERT_DOUBLE_EQUAL(pt.x, 1024.5, DBL_EPSILON);
96  CU_ASSERT_DOUBLE_EQUAL(pt.y, 256.5, DBL_EPSILON);
97 
98  getPoint4d_p(ring, 4, &pt);
99  CU_ASSERT_DOUBLE_EQUAL(pt.x, 0.5, DBL_EPSILON);
100  CU_ASSERT_DOUBLE_EQUAL(pt.y, 0.5, DBL_EPSILON);
101 
102  lwgeom_free(hull);
103  cu_free_raster(raster);
104 }
double x
Definition: liblwgeom.h:308
#define LINETYPE
Definition: liblwgeom.h:61
int npoints
Definition: liblwgeom.h:327
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_api.c:5473
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_api.c:5442
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
int32_t srid
Definition: liblwgeom.h:410
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_api.c:6556
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
double y
Definition: liblwgeom.h:308
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_api.c:5504
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217

Here is the call graph for this function:

Here is the caller graph for this function: