PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_mapAlgebraExpr()

Datum RASTER_mapAlgebraExpr ( PG_FUNCTION_ARGS  )

Create a new empty raster with having the same georeference as the provided raster

If this new raster is empty (width = 0 OR height = 0) then there is nothing to compute and we return it right now

Check if the raster has the required band. Otherwise, return a raster without band

We set the initial value of the future band to nodata value. If nodata value is null, then the raster will be initialized to rt_band_get_min_value but all the values should be recomputed anyway

Set the new pixeltype

Optimization: If a nodataval is provided, use it for newinitialvalue. Then, we can initialize the raster with this value and skip the computation of nodata values one by one in the main computing loop

Optimization: If the raster is only filled with nodata values return right now a raster filled with the newinitialvalue TODO: Call rt_band_check_isnodata instead?

Optimization: If expression resume to 'RAST' and hasnodataval is zero, we can just return the band from the original raster

Optimization: If expression resume to a constant (it does not contain [rast)

Compute the new value, set it and we will return after creating the new raster

Create the raster receiving all the computed values. Initialize it to the new initial value

Optimization: If expression is NULL, or all the pixels could be set in one step, return the initialized raster now

We compute a value only for the withdata value pixel since the nodata value has already been set by the first optimization

Definition at line 4475 of file rtpg_mapalgebra.c.

4476 {
4477  rt_pgraster *pgraster = NULL;
4478  rt_pgraster *pgrtn = NULL;
4479  rt_raster raster = NULL;
4480  rt_raster newrast = NULL;
4481  rt_band band = NULL;
4482  rt_band newband = NULL;
4483  int x, y, nband, width, height;
4484  double r;
4485  double newnodatavalue = 0.0;
4486  double newinitialvalue = 0.0;
4487  double newval = 0.0;
4488  char *newexpr = NULL;
4489  char *initexpr = NULL;
4490  char *expression = NULL;
4491  int hasnodataval = 0;
4492  double nodataval = 0.;
4493  rt_pixtype newpixeltype;
4494  int skipcomputation = 0;
4495  int len = 0;
4496  const int argkwcount = 3;
4497  enum KEYWORDS { kVAL=0, kX=1, kY=2 };
4498  char *argkw[] = {"[rast]", "[rast.x]", "[rast.y]"};
4499  Oid argkwtypes[] = { FLOAT8OID, INT4OID, INT4OID };
4500  int argcount = 0;
4501  Oid argtype[] = { FLOAT8OID, INT4OID, INT4OID };
4502  uint8_t argpos[3] = {0};
4503  char place[12];
4504  int idx = 0;
4505  int ret = -1;
4506  TupleDesc tupdesc;
4507  SPIPlanPtr spi_plan = NULL;
4508  SPITupleTable * tuptable = NULL;
4509  HeapTuple tuple;
4510  char * strFromText = NULL;
4511  Datum *values = NULL;
4512  Datum datum = (Datum)NULL;
4513  char *nulls = NULL;
4514  bool isnull = FALSE;
4515  int i = 0;
4516  int j = 0;
4517 
4518  POSTGIS_RT_DEBUG(2, "RASTER_mapAlgebraExpr: Starting...");
4519 
4520  /* Check raster */
4521  if (PG_ARGISNULL(0)) {
4522  elog(NOTICE, "Raster is NULL. Returning NULL");
4523  PG_RETURN_NULL();
4524  }
4525 
4526 
4527  /* Deserialize raster */
4528  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4529  raster = rt_raster_deserialize(pgraster, FALSE);
4530  if (NULL == raster) {
4531  PG_FREE_IF_COPY(pgraster, 0);
4532  elog(ERROR, "RASTER_mapAlgebraExpr: Could not deserialize raster");
4533  PG_RETURN_NULL();
4534  }
4535 
4536  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Getting arguments...");
4537 
4538  if (PG_ARGISNULL(1))
4539  nband = 1;
4540  else
4541  nband = PG_GETARG_INT32(1);
4542 
4543  if (nband < 1)
4544  nband = 1;
4545 
4546 
4547  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Creating new empty raster...");
4548 
4553  width = rt_raster_get_width(raster);
4554  height = rt_raster_get_height(raster);
4555 
4556  newrast = rt_raster_new(width, height);
4557 
4558  if ( NULL == newrast ) {
4559  PG_FREE_IF_COPY(pgraster, 0);
4560  elog(ERROR, "RASTER_mapAlgebraExpr: Could not create a new raster");
4561  PG_RETURN_NULL();
4562  }
4563 
4564  rt_raster_set_scale(newrast,
4567 
4568  rt_raster_set_offsets(newrast,
4571 
4572  rt_raster_set_skews(newrast,
4575 
4577 
4578 
4583  if (rt_raster_is_empty(newrast))
4584  {
4585  elog(NOTICE, "Raster is empty. Returning an empty raster");
4587  PG_FREE_IF_COPY(pgraster, 0);
4588 
4589  pgrtn = rt_raster_serialize(newrast);
4590  rt_raster_destroy(newrast);
4591  if (NULL == pgrtn) {
4592 
4593  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4594  PG_RETURN_NULL();
4595  }
4596 
4597  SET_VARSIZE(pgrtn, pgrtn->size);
4598  PG_RETURN_POINTER(pgrtn);
4599  }
4600 
4601 
4602  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Getting raster band %d...", nband);
4603 
4608  if (!rt_raster_has_band(raster, nband - 1)) {
4609  elog(NOTICE, "Raster does not have the required band. Returning a raster "
4610  "without a band");
4612  PG_FREE_IF_COPY(pgraster, 0);
4613 
4614  pgrtn = rt_raster_serialize(newrast);
4615  rt_raster_destroy(newrast);
4616  if (NULL == pgrtn) {
4617  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4618  PG_RETURN_NULL();
4619  }
4620 
4621  SET_VARSIZE(pgrtn, pgrtn->size);
4622  PG_RETURN_POINTER(pgrtn);
4623  }
4624 
4625  /* Get the raster band */
4627  if ( NULL == band ) {
4628  elog(NOTICE, "Could not get the required band. Returning a raster "
4629  "without a band");
4631  PG_FREE_IF_COPY(pgraster, 0);
4632 
4633  pgrtn = rt_raster_serialize(newrast);
4634  rt_raster_destroy(newrast);
4635  if (NULL == pgrtn) {
4636  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4637  PG_RETURN_NULL();
4638  }
4639 
4640  SET_VARSIZE(pgrtn, pgrtn->size);
4641  PG_RETURN_POINTER(pgrtn);
4642  }
4643 
4644  /*
4645  * Get NODATA value
4646  */
4647  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Getting NODATA value for band...");
4648 
4650  rt_band_get_nodata(band, &newnodatavalue);
4651  }
4652 
4653  else {
4654  newnodatavalue = rt_band_get_min_value(band);
4655  }
4656 
4657  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: NODATA value for band: = %f",
4658  newnodatavalue);
4659 
4665  newinitialvalue = newnodatavalue;
4666 
4670  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Setting pixeltype...");
4671 
4672  if (PG_ARGISNULL(2)) {
4673  newpixeltype = rt_band_get_pixtype(band);
4674  }
4675 
4676  else {
4677  strFromText = text_to_cstring(PG_GETARG_TEXT_P(2));
4678  newpixeltype = rt_pixtype_index_from_name(strFromText);
4679  pfree(strFromText);
4680  if (newpixeltype == PT_END)
4681  newpixeltype = rt_band_get_pixtype(band);
4682  }
4683 
4684  if (newpixeltype == PT_END) {
4685  PG_FREE_IF_COPY(pgraster, 0);
4686  elog(ERROR, "RASTER_mapAlgebraExpr: Invalid pixeltype");
4687  PG_RETURN_NULL();
4688  }
4689 
4690  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Pixeltype set to %s",
4691  rt_pixtype_name(newpixeltype));
4692 
4693 
4694  /* Construct expression for raster values */
4695  if (!PG_ARGISNULL(3)) {
4696  expression = text_to_cstring(PG_GETARG_TEXT_P(3));
4697  len = strlen("SELECT (") + strlen(expression) + strlen(")::double precision");
4698  initexpr = (char *)palloc(len + 1);
4699 
4700  strncpy(initexpr, "SELECT (", strlen("SELECT ("));
4701  strncpy(initexpr + strlen("SELECT ("), expression, strlen(expression));
4702  strncpy(initexpr + strlen("SELECT (") + strlen(expression), ")::double precision", strlen(")::double precision"));
4703  initexpr[len] = '\0';
4704 
4705  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Expression is %s", initexpr);
4706 
4707  /* We don't need this memory */
4708  /*
4709  pfree(expression);
4710  expression = NULL;
4711  */
4712  }
4713 
4714 
4715 
4721  if (!PG_ARGISNULL(4)) {
4722  hasnodataval = 1;
4723  nodataval = PG_GETARG_FLOAT8(4);
4724  newinitialvalue = nodataval;
4725 
4726  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: new initial value = %f",
4727  newinitialvalue);
4728  }
4729  else
4730  hasnodataval = 0;
4731 
4732 
4733 
4740 
4741  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Band is a nodata band, returning "
4742  "a raster filled with nodata");
4743 
4744  ret = rt_raster_generate_new_band(newrast, newpixeltype,
4745  newinitialvalue, TRUE, newnodatavalue, 0);
4746 
4747  /* Free memory */
4748  if (initexpr)
4749  pfree(initexpr);
4751  PG_FREE_IF_COPY(pgraster, 0);
4752 
4753  /* Serialize created raster */
4754  pgrtn = rt_raster_serialize(newrast);
4755  rt_raster_destroy(newrast);
4756  if (NULL == pgrtn) {
4757  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4758  PG_RETURN_NULL();
4759  }
4760 
4761  SET_VARSIZE(pgrtn, pgrtn->size);
4762  PG_RETURN_POINTER(pgrtn);
4763  }
4764 
4765 
4770  if (initexpr != NULL && ( !strcmp(initexpr, "SELECT [rast]") || !strcmp(initexpr, "SELECT [rast.val]") ) && !hasnodataval) {
4771 
4772  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Expression resumes to RAST. "
4773  "Returning raster with band %d from original raster", nband);
4774 
4775  POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster has %d bands",
4776  rt_raster_get_num_bands(newrast));
4777 
4778  rt_raster_copy_band(newrast, raster, nband - 1, 0);
4779 
4780  POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
4781  rt_raster_get_num_bands(newrast));
4782 
4783  pfree(initexpr);
4785  PG_FREE_IF_COPY(pgraster, 0);
4786 
4787  /* Serialize created raster */
4788  pgrtn = rt_raster_serialize(newrast);
4789  rt_raster_destroy(newrast);
4790  if (NULL == pgrtn) {
4791  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4792  PG_RETURN_NULL();
4793  }
4794 
4795  SET_VARSIZE(pgrtn, pgrtn->size);
4796  PG_RETURN_POINTER(pgrtn);
4797  }
4798 
4803  if (initexpr != NULL && strstr(initexpr, "[rast") == NULL) {
4804  ret = SPI_connect();
4805  if (ret != SPI_OK_CONNECT) {
4806  PG_FREE_IF_COPY(pgraster, 0);
4807  elog(ERROR, "RASTER_mapAlgebraExpr: Could not connect to the SPI manager");
4808  PG_RETURN_NULL();
4809  };
4810 
4811  /* Execute the expresion into newval */
4812  ret = SPI_execute(initexpr, FALSE, 0);
4813 
4814  if (ret != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
4815 
4816  /* Free memory allocated out of the current context */
4817  if (SPI_tuptable)
4818  SPI_freetuptable(tuptable);
4819  PG_FREE_IF_COPY(pgraster, 0);
4820 
4821  SPI_finish();
4822  elog(ERROR, "RASTER_mapAlgebraExpr: Invalid construction for expression");
4823  PG_RETURN_NULL();
4824  }
4825 
4826  tupdesc = SPI_tuptable->tupdesc;
4827  tuptable = SPI_tuptable;
4828 
4829  tuple = tuptable->vals[0];
4830  newexpr = SPI_getvalue(tuple, tupdesc, 1);
4831  if ( ! newexpr ) {
4832  POSTGIS_RT_DEBUG(3, "Constant expression evaluated to NULL, keeping initvalue");
4833  newval = newinitialvalue;
4834  } else {
4835  newval = atof(newexpr);
4836  }
4837 
4838  SPI_freetuptable(tuptable);
4839 
4840  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: New raster value = %f",
4841  newval);
4842 
4843  SPI_finish();
4844 
4845  skipcomputation = 1;
4846 
4851  if (!hasnodataval) {
4852  newinitialvalue = newval;
4853  skipcomputation = 2;
4854  }
4855 
4856  /* Return the new raster as it will be before computing pixel by pixel */
4857  else if (FLT_NEQ(newval, newinitialvalue)) {
4858  skipcomputation = 2;
4859  }
4860  }
4861 
4866  ret = rt_raster_generate_new_band(newrast, newpixeltype,
4867  newinitialvalue, TRUE, newnodatavalue, 0);
4868 
4873  /*if (initexpr == NULL || skipcomputation == 2) {*/
4874  if (expression == NULL || skipcomputation == 2) {
4875 
4876  /* Free memory */
4877  if (initexpr)
4878  pfree(initexpr);
4880  PG_FREE_IF_COPY(pgraster, 0);
4881 
4882  /* Serialize created raster */
4883  pgrtn = rt_raster_serialize(newrast);
4884  rt_raster_destroy(newrast);
4885  if (NULL == pgrtn) {
4886  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4887  PG_RETURN_NULL();
4888  }
4889 
4890  SET_VARSIZE(pgrtn, pgrtn->size);
4891  PG_RETURN_POINTER(pgrtn);
4892  }
4893 
4894  RASTER_DEBUG(3, "RASTER_mapAlgebraExpr: Creating new raster band...");
4895 
4896  /* Get the new raster band */
4897  newband = rt_raster_get_band(newrast, 0);
4898  if ( NULL == newband ) {
4899  elog(NOTICE, "Could not modify band for new raster. Returning new "
4900  "raster with the original band");
4901 
4902  if (initexpr)
4903  pfree(initexpr);
4905  PG_FREE_IF_COPY(pgraster, 0);
4906 
4907  /* Serialize created raster */
4908  pgrtn = rt_raster_serialize(newrast);
4909  rt_raster_destroy(newrast);
4910  if (NULL == pgrtn) {
4911  elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4912  PG_RETURN_NULL();
4913  }
4914 
4915  SET_VARSIZE(pgrtn, pgrtn->size);
4916  PG_RETURN_POINTER(pgrtn);
4917  }
4918 
4919  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Main computing loop (%d x %d)",
4920  width, height);
4921 
4922  if (initexpr != NULL) {
4923  /* Convert [rast.val] to [rast] */
4924  newexpr = rtpg_strreplace(initexpr, "[rast.val]", "[rast]", NULL);
4925  pfree(initexpr); initexpr=newexpr;
4926 
4927  sprintf(place,"$1");
4928  for (i = 0, j = 1; i < argkwcount; i++) {
4929  len = 0;
4930  newexpr = rtpg_strreplace(initexpr, argkw[i], place, &len);
4931  pfree(initexpr); initexpr=newexpr;
4932  if (len > 0) {
4933  argtype[argcount] = argkwtypes[i];
4934  argcount++;
4935  argpos[i] = j++;
4936 
4937  sprintf(place, "$%d", j);
4938  }
4939  else {
4940  argpos[i] = 0;
4941  }
4942  }
4943 
4944  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: initexpr = %s", initexpr);
4945 
4946  /* define values */
4947  values = (Datum *) palloc(sizeof(Datum) * argcount);
4948  if (values == NULL) {
4949 
4950  SPI_finish();
4951 
4953  PG_FREE_IF_COPY(pgraster, 0);
4954  rt_raster_destroy(newrast);
4955 
4956  elog(ERROR, "RASTER_mapAlgebraExpr: Could not allocate memory for value parameters of prepared statement");
4957  PG_RETURN_NULL();
4958  }
4959 
4960  /* define nulls */
4961  nulls = (char *)palloc(argcount);
4962  if (nulls == NULL) {
4963 
4964  SPI_finish();
4965 
4967  PG_FREE_IF_COPY(pgraster, 0);
4968  rt_raster_destroy(newrast);
4969 
4970  elog(ERROR, "RASTER_mapAlgebraExpr: Could not allocate memory for null parameters of prepared statement");
4971  PG_RETURN_NULL();
4972  }
4973 
4974  /* Connect to SPI and prepare the expression */
4975  ret = SPI_connect();
4976  if (ret != SPI_OK_CONNECT) {
4977 
4978  if (initexpr)
4979  pfree(initexpr);
4981  PG_FREE_IF_COPY(pgraster, 0);
4982  rt_raster_destroy(newrast);
4983 
4984  elog(ERROR, "RASTER_mapAlgebraExpr: Could not connect to the SPI manager");
4985  PG_RETURN_NULL();
4986  };
4987 
4988  /* Type of all arguments is FLOAT8OID */
4989  spi_plan = SPI_prepare(initexpr, argcount, argtype);
4990 
4991  if (spi_plan == NULL) {
4992 
4994  PG_FREE_IF_COPY(pgraster, 0);
4995  rt_raster_destroy(newrast);
4996 
4997  SPI_finish();
4998 
4999  pfree(initexpr);
5000 
5001  elog(ERROR, "RASTER_mapAlgebraExpr: Could not prepare expression");
5002  PG_RETURN_NULL();
5003  }
5004  }
5005 
5006  for (x = 0; x < width; x++) {
5007  for(y = 0; y < height; y++) {
5008  ret = rt_band_get_pixel(band, x, y, &r, NULL);
5009 
5014  if (ret == ES_NONE && FLT_NEQ(r, newnodatavalue)) {
5015  if (skipcomputation == 0) {
5016  if (initexpr != NULL) {
5017  /* Reset the null arg flags. */
5018  memset(nulls, 'n', argcount);
5019 
5020  for (i = 0; i < argkwcount; i++) {
5021  idx = argpos[i];
5022  if (idx < 1) continue;
5023  idx--;
5024 
5025  if (i == kX ) {
5026  /* x is 0 based index, but SQL expects 1 based index */
5027  values[idx] = Int32GetDatum(x+1);
5028  nulls[idx] = ' ';
5029  }
5030  else if (i == kY) {
5031  /* y is 0 based index, but SQL expects 1 based index */
5032  values[idx] = Int32GetDatum(y+1);
5033  nulls[idx] = ' ';
5034  }
5035  else if (i == kVAL ) {
5036  values[idx] = Float8GetDatum(r);
5037  nulls[idx] = ' ';
5038  }
5039 
5040  }
5041 
5042  ret = SPI_execute_plan(spi_plan, values, nulls, FALSE, 0);
5043  if (ret != SPI_OK_SELECT || SPI_tuptable == NULL ||
5044  SPI_processed != 1) {
5045  if (SPI_tuptable)
5046  SPI_freetuptable(tuptable);
5047 
5048  SPI_freeplan(spi_plan);
5049  SPI_finish();
5050 
5051  pfree(values);
5052  pfree(nulls);
5053  pfree(initexpr);
5054 
5056  PG_FREE_IF_COPY(pgraster, 0);
5057  rt_raster_destroy(newrast);
5058 
5059  elog(ERROR, "RASTER_mapAlgebraExpr: Error executing prepared plan");
5060 
5061  PG_RETURN_NULL();
5062  }
5063 
5064  tupdesc = SPI_tuptable->tupdesc;
5065  tuptable = SPI_tuptable;
5066 
5067  tuple = tuptable->vals[0];
5068  datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
5069  if ( SPI_result == SPI_ERROR_NOATTRIBUTE ) {
5070  POSTGIS_RT_DEBUGF(3, "Expression for pixel %d,%d (value %g) errored, skip setting", x+1,y+1,r);
5071  newval = newinitialvalue;
5072  }
5073  else if ( isnull ) {
5074  POSTGIS_RT_DEBUGF(3, "Expression for pixel %d,%d (value %g) evaluated to NULL, skip setting", x+1,y+1,r);
5075  newval = newinitialvalue;
5076  } else {
5077  newval = DatumGetFloat8(datum);
5078  }
5079 
5080  SPI_freetuptable(tuptable);
5081  }
5082 
5083  else
5084  newval = newinitialvalue;
5085 
5086  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: new value = %f",
5087  newval);
5088  }
5089 
5090 
5091  rt_band_set_pixel(newband, x, y, newval, NULL);
5092  }
5093 
5094  }
5095  }
5096 
5097  if (initexpr != NULL) {
5098  SPI_freeplan(spi_plan);
5099  SPI_finish();
5100 
5101  pfree(values);
5102  pfree(nulls);
5103  pfree(initexpr);
5104  }
5105  else {
5106  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: no SPI cleanup");
5107  }
5108 
5109 
5110  /* The newrast band has been modified */
5111 
5112  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster modified, serializing it.");
5113  /* Serialize created raster */
5114 
5116  PG_FREE_IF_COPY(pgraster, 0);
5117 
5118  pgrtn = rt_raster_serialize(newrast);
5119  rt_raster_destroy(newrast);
5120  if (NULL == pgrtn)
5121  PG_RETURN_NULL();
5122 
5123  SET_VARSIZE(pgrtn, pgrtn->size);
5124 
5125  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster serialized");
5126 
5127 
5128  POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraExpr: returning raster");
5129 
5130 
5131  PG_RETURN_POINTER(pgrtn);
5132 }
char * r
Definition: cu_in_wkt.c:24
#define TRUE
Definition: dbfopen.c:169
#define FALSE
Definition: dbfopen.c:168
#define FLT_NEQ(x, y)
Definition: librtcore.h:2233
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
Definition: rt_raster.c:485
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_pixel.c:80
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1221
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_pixtype
Definition: librtcore.h:185
@ PT_END
Definition: librtcore.h:197
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
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:714
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_raster.c:1347
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_band.c:1745
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:974
@ ES_NONE
Definition: librtcore.h:180
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
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
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:631
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
Definition: rt_raster.c:1370
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1334
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
band
Definition: ovdump.py:57
nband
Definition: pixval.py:52
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
char * text_to_cstring(const text *textptr)
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
Definition: rtpg_internal.c:55
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:61
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
Struct definitions.
Definition: librtcore.h:2250
unsigned char uint8_t
Definition: uthash.h:79

References ovdump::band, ES_NONE, FALSE, FLT_NEQ, pixval::nband, POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, PT_END, r, rtrowdump::raster, RASTER_DEBUG, rt_band_get_hasnodata_flag(), rt_band_get_isnodata_flag(), rt_band_get_min_value(), rt_band_get_nodata(), rt_band_get_pixel(), rt_band_get_pixtype(), rt_band_set_pixel(), rt_pixtype_index_from_name(), rt_pixtype_name(), rt_raster_copy_band(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_generate_new_band(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_num_bands(), 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_has_band(), rt_raster_is_empty(), rt_raster_new(), rt_raster_serialize(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_set_skews(), rt_raster_set_srid(), rtpg_strreplace(), rt_raster_serialized_t::size, text_to_cstring(), TRUE, pixval::x, and pixval::y.

Here is the call graph for this function: