PostGIS  2.1.10dev-r@@SVN_REVISION@@
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  userargs,
575  &rtn
576  );
577  CU_ASSERT_EQUAL(noerr, ES_NONE);
578  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
579  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
580  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
581  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
582  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
583  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
584  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
585  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
586  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
587 
588  if (rtn != NULL) cu_free_raster(rtn);
589  rtn = NULL;
590 
591  /* 1 raster, 0 distance, FIRST or SECOND or LAST or UNION or INTERSECTION */
592  userargs->rasters = 1;
593  userargs->rows = 1;
594  userargs->columns = 1;
595 
596  noerr = rt_raster_iterator(
597  itrset, 1,
598  ET_UNION, NULL,
599  PT_32BUI,
600  1, 0,
601  0, 0,
602  userargs,
604  &rtn
605  );
606  CU_ASSERT_EQUAL(noerr, ES_NONE);
607  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
608  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
609  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
610  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
611  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
612  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
613  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
614  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
615  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
616 
617  if (rtn != NULL) cu_free_raster(rtn);
618  rtn = NULL;
619 
620  /* 2 raster, 0 distance, UNION */
621  userargs->rasters = 2;
622  userargs->rows = 1;
623  userargs->columns = 1;
624 
625  noerr = rt_raster_iterator(
626  itrset, 2,
627  ET_UNION, NULL,
628  PT_32BUI,
629  1, 0,
630  0, 0,
631  userargs,
633  &rtn
634  );
635  CU_ASSERT_EQUAL(noerr, ES_NONE);
636  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 6);
637  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 6);
638  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
639  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
640  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
641  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
642  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
643  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
644  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
645 
646  if (rtn != NULL) cu_free_raster(rtn);
647  rtn = NULL;
648 
649  /* 2 raster, 0 distance, INTERSECTION */
650  noerr = rt_raster_iterator(
651  itrset, 2,
652  ET_INTERSECTION, NULL,
653  PT_32BUI,
654  1, 0,
655  0, 0,
656  userargs,
658  &rtn
659  );
660  CU_ASSERT_EQUAL(noerr, ES_NONE);
661  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 4);
662  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 4);
663  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
664  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -1, DBL_EPSILON);
665  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
666  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
667  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
668  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
669  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
670 
671  if (rtn != NULL) cu_free_raster(rtn);
672  rtn = NULL;
673 
674  /* 2 raster, 0 distance, FIRST */
675  noerr = rt_raster_iterator(
676  itrset, 2,
677  ET_FIRST, NULL,
678  PT_32BUI,
679  1, 0,
680  0, 0,
681  userargs,
683  &rtn
684  );
685  CU_ASSERT_EQUAL(noerr, ES_NONE);
686  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
687  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
688  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 0, DBL_EPSILON);
689  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), 0, DBL_EPSILON);
690  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
691  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
692  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
693  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
694  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
695 
696  if (rtn != NULL) cu_free_raster(rtn);
697  rtn = NULL;
698 
699  /* 2 raster, 0 distance, LAST or SECOND */
700  noerr = rt_raster_iterator(
701  itrset, 2,
702  ET_LAST, NULL,
703  PT_32BUI,
704  1, 0,
705  0, 0,
706  userargs,
708  &rtn
709  );
710  CU_ASSERT_EQUAL(noerr, ES_NONE);
711  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 5);
712  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 5);
713  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
714  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -1, DBL_EPSILON);
715  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
716  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
717  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
718  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
719  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
720 
721  if (rtn != NULL) cu_free_raster(rtn);
722  rtn = NULL;
723 
724  /* 2 raster, 0 distance, CUSTOM */
725  noerr = rt_raster_iterator(
726  itrset, 2,
727  ET_CUSTOM, rast3,
728  PT_32BUI,
729  1, 0,
730  0, 0,
731  userargs,
733  &rtn
734  );
735  CU_ASSERT_EQUAL(noerr, ES_NONE);
736  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 2);
737  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 2);
738  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
739  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -3, DBL_EPSILON);
740  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
741  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
742  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
743  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
744  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
745 
746  if (rtn != NULL) cu_free_raster(rtn);
747  rtn = NULL;
748 
749  /* 2 raster, 1 distance, CUSTOM */
750  userargs->rasters = 2;
751  userargs->rows = 3;
752  userargs->columns = 3;
753 
754  noerr = rt_raster_iterator(
755  itrset, 2,
756  ET_CUSTOM, rast3,
757  PT_32BUI,
758  1, 0,
759  1, 1,
760  userargs,
762  &rtn
763  );
764  CU_ASSERT_EQUAL(noerr, ES_NONE);
765  CU_ASSERT_EQUAL(rt_raster_get_width(rtn), 2);
766  CU_ASSERT_EQUAL(rt_raster_get_height(rtn), 2);
767  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(rtn), 1, DBL_EPSILON);
768  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(rtn), -3, DBL_EPSILON);
769  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_scale(rtn), 1, DBL_EPSILON);
770  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_scale(rtn), -1, DBL_EPSILON);
771  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_skew(rtn), 0, DBL_EPSILON);
772  CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_skew(rtn), 0, DBL_EPSILON);
773  CU_ASSERT_EQUAL(rt_raster_get_srid(rtn), 0);
774 
775  if (rtn != NULL) cu_free_raster(rtn);
776  rtn = NULL;
777 
778  rtdealloc(userargs);
779  rtdealloc(itrset);
780 
781  cu_free_raster(rast1);
782  cu_free_raster(rast2);
783  cu_free_raster(rast3);
784 
785  if (rtn != NULL) cu_free_raster(rtn);
786 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_api.c:5527
static int testRasterIterator7_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
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)
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_api.c:5486
tuple band
Definition: ovdump.py:57
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_api.c:5495
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_api.c:5518
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
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_api.c:5442
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_api.c:5455
rt_raster raster
Definition: rt_api.h:2360
tuple x
Definition: pixval.py:53
uint16_t nband
Definition: rt_api.h:2361
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_api.c:5434
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
uint8_t nbnodata
Definition: rt_api.h:2362
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, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
Definition: rt_api.c:13927
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_api.c:5464
static int testRasterIterator2_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
Definition: cu_mapalgebra.c:95
static int testRasterIterator5_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_api.c:5504
tuple y
Definition: pixval.py:54
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_api.c:5426
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function:

Here is the caller graph for this function: