PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_raster_iterator()

static void test_raster_iterator ( )
static

Definition at line 495 of file cu_mapalgebra.c.

References ovdump::band, _callback_userargs_t::columns, cu_add_band(), cu_free_raster(), ES_NONE, ET_CUSTOM, ET_FIRST, ET_INTERSECTION, ET_LAST, ET_UNION, rt_iterator_t::nband, rt_iterator_t::nbnodata, PT_32BUI, rt_iterator_t::raster, _callback_userargs_t::rasters, _callback_userargs_t::rows, rt_band_set_pixel(), rt_raster_get_height(), rt_raster_get_srid(), rt_raster_get_width(), rt_raster_get_x_offset(), rt_raster_get_x_scale(), rt_raster_get_x_skew(), rt_raster_get_y_offset(), rt_raster_get_y_scale(), rt_raster_get_y_skew(), rt_raster_iterator(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rtalloc(), rtdealloc(), testRasterIterator1_callback(), testRasterIterator2_callback(), testRasterIterator3_callback(), testRasterIterator4_callback(), testRasterIterator5_callback(), testRasterIterator6_callback(), testRasterIterator7_callback(), pixval::x, and pixval::y.

Referenced by mapalgebra_suite_setup().

495  {
496  rt_raster rast1;
497  rt_raster rast2;
498  rt_raster rast3;
499 
500  int num = 2;
501 
502  rt_raster rtn = NULL;
503  rt_band band;
504  int maxX = 5;
505  int maxY = 5;
506  rt_iterator itrset;
507  _callback_userargs userargs;
508  int noerr = 0;
509  int x = 0;
510  int y = 0;
511 
512  rast1 = rt_raster_new(maxX, maxY);
513  CU_ASSERT(rast1 != NULL);
514 
515  rt_raster_set_offsets(rast1, 0, 0);
516  rt_raster_set_scale(rast1, 1, -1);
517 
518  band = cu_add_band(rast1, PT_32BUI, 1, 6);
519  CU_ASSERT(band != NULL);
520 
521  for (y = 0; y < maxY; y++) {
522  for (x = 0; x < maxX; x++) {
523  rt_band_set_pixel(band, x, y, x + (y * maxX), NULL);
524  }
525  }
526 
527  rast2 = rt_raster_new(maxX, maxY);
528  CU_ASSERT(rast2 != NULL);
529 
530  rt_raster_set_offsets(rast2, 1, -1);
531  rt_raster_set_scale(rast2, 1, -1);
532 
533  band = cu_add_band(rast2, PT_32BUI, 1, 110);
534  CU_ASSERT(band != NULL);
535 
536  for (y = 0; y < maxY; y++) {
537  for (x = 0; x < maxX; x++) {
538  rt_band_set_pixel(band, x, y, (x + (y * maxX)) + 100, NULL);
539  }
540  }
541 
542  rast3 = rt_raster_new(2, 2);
543  CU_ASSERT(rast3 != NULL);
544 
545  rt_raster_set_offsets(rast3, 1, -3);
546  rt_raster_set_scale(rast3, 1, -1);
547 
548  /* allocate user args */
549  userargs = rtalloc(sizeof(struct _callback_userargs_t));
550  CU_ASSERT(userargs != NULL);
551 
552  /* allocate itrset */
553  itrset = rtalloc(sizeof(struct rt_iterator_t) * num);
554  CU_ASSERT(itrset != NULL);
555  itrset[0].raster = rast1;
556  itrset[0].nband = 0;
557  itrset[0].nbnodata = 1;
558  itrset[1].raster = rast2;
559  itrset[1].nband = 0;
560  itrset[1].nbnodata = 1;
561 
562  /* 1 raster, 0 distance, FIRST or SECOND or LAST or UNION or INTERSECTION */
563  userargs->rasters = 1;
564  userargs->rows = 1;
565  userargs->columns = 1;
566 
567  noerr = rt_raster_iterator(
568  itrset, 1,
569  ET_INTERSECTION, NULL,
570  PT_32BUI,
571  1, 0,
572  0, 0,
573  NULL,
574  userargs,
576  &rtn
577  );
578  CU_ASSERT_EQUAL(noerr, ES_NONE);
579  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
580  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
581  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
582  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
583  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
584  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
585  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
586  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
587  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
588 
589  if (rtn != NULL) cu_free_raster(rtn);
590  rtn = NULL;
591 
592  /* 1 raster, 0 distance, FIRST or SECOND or LAST or UNION or INTERSECTION */
593  userargs->rasters = 1;
594  userargs->rows = 1;
595  userargs->columns = 1;
596 
597  noerr = rt_raster_iterator(
598  itrset, 1,
599  ET_UNION, NULL,
600  PT_32BUI,
601  1, 0,
602  0, 0,
603  NULL,
604  userargs,
606  &rtn
607  );
608  CU_ASSERT_EQUAL(noerr, ES_NONE);
609  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
610  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
611  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
612  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
613  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
614  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
615  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
616  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
617  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
618 
619  if (rtn != NULL) cu_free_raster(rtn);
620  rtn = NULL;
621 
622  /* 2 raster, 0 distance, UNION */
623  userargs->rasters = 2;
624  userargs->rows = 1;
625  userargs->columns = 1;
626 
627  noerr = rt_raster_iterator(
628  itrset, 2,
629  ET_UNION, NULL,
630  PT_32BUI,
631  1, 0,
632  0, 0,
633  NULL,
634  userargs,
636  &rtn
637  );
638  CU_ASSERT_EQUAL(noerr, ES_NONE);
639  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 6);
640  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 6);
641  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
642  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
643  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
644  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
645  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
646  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
647  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
648 
649  if (rtn != NULL) cu_free_raster(rtn);
650  rtn = NULL;
651 
652  /* 2 raster, 0 distance, INTERSECTION */
653  noerr = rt_raster_iterator(
654  itrset, 2,
655  ET_INTERSECTION, NULL,
656  PT_32BUI,
657  1, 0,
658  0, 0,
659  NULL,
660  userargs,
662  &rtn
663  );
664  CU_ASSERT_EQUAL(noerr, ES_NONE);
665  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 4);
666  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 4);
667  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
668  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -1, DBL_EPSILON);
669  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
670  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
671  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
672  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
673  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
674 
675  if (rtn != NULL) cu_free_raster(rtn);
676  rtn = NULL;
677 
678  /* 2 raster, 0 distance, FIRST */
679  noerr = rt_raster_iterator(
680  itrset, 2,
681  ET_FIRST, NULL,
682  PT_32BUI,
683  1, 0,
684  0, 0,
685  NULL,
686  userargs,
688  &rtn
689  );
690  CU_ASSERT_EQUAL(noerr, ES_NONE);
691  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
692  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
693  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
694  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
695  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
696  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
697  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
698  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
699  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
700 
701  if (rtn != NULL) cu_free_raster(rtn);
702  rtn = NULL;
703 
704  /* 2 raster, 0 distance, LAST or SECOND */
705  noerr = rt_raster_iterator(
706  itrset, 2,
707  ET_LAST, NULL,
708  PT_32BUI,
709  1, 0,
710  0, 0,
711  NULL,
712  userargs,
714  &rtn
715  );
716  CU_ASSERT_EQUAL(noerr, ES_NONE);
717  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
718  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
719  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
720  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -1, DBL_EPSILON);
721  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
722  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
723  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
724  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
725  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
726 
727  if (rtn != NULL) cu_free_raster(rtn);
728  rtn = NULL;
729 
730  /* 2 raster, 0 distance, CUSTOM */
731  noerr = rt_raster_iterator(
732  itrset, 2,
733  ET_CUSTOM, rast3,
734  PT_32BUI,
735  1, 0,
736  0, 0,
737  NULL,
738  userargs,
740  &rtn
741  );
742  CU_ASSERT_EQUAL(noerr, ES_NONE);
743  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 2);
744  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 2);
745  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
746  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -3, DBL_EPSILON);
747  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
748  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
749  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
750  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
751  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
752 
753  if (rtn != NULL) cu_free_raster(rtn);
754  rtn = NULL;
755 
756  /* 2 raster, 1 distance, CUSTOM */
757  userargs->rasters = 2;
758  userargs->rows = 3;
759  userargs->columns = 3;
760 
761  noerr = rt_raster_iterator(
762  itrset, 2,
763  ET_CUSTOM, rast3,
764  PT_32BUI,
765  1, 0,
766  1, 1,
767  NULL,
768  userargs,
770  &rtn
771  );
772  CU_ASSERT_EQUAL(noerr, ES_NONE);
773  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 2);
774  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 2);
775  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
776  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -3, DBL_EPSILON);
777  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
778  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
779  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
780  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
781  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
782 
783  if (rtn != NULL) cu_free_raster(rtn);
784  rtn = NULL;
785 
786  rtdealloc(userargs);
787  rtdealloc(itrset);
788 
789  cu_free_raster(rast1);
790  cu_free_raster(rast2);
791  cu_free_raster(rast3);
792 
793  if (rtn != NULL) cu_free_raster(rtn);
794 }
static int testRasterIterator7_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static int testRasterIterator1_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
Definition: cu_mapalgebra.c:35
static int testRasterIterator4_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
band
Definition: ovdump.py:57
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
static int testRasterIterator6_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
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
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
int32_t rt_raster_get_srid(rt_raster raster)
Get raster&#39;s SRID.
Definition: rt_raster.c:356
rt_raster raster
Definition: librtcore.h:2423
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
uint16_t nband
Definition: librtcore.h:2424
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
void rtdealloc(void *mem)
Definition: rt_context.c:186
uint8_t nbnodata
Definition: librtcore.h:2425
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:926
static int testRasterIterator2_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
Definition: cu_mapalgebra.c:95
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
static int testRasterIterator5_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
Here is the call graph for this function:
Here is the caller graph for this function: