PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_mapAlgebraFctNgb()

Datum RASTER_mapAlgebraFctNgb ( 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 the raster is only filled with nodata values return right now a raster filled with the nodatavalueexpr TODO: Call rt_band_check_isnodata instead?

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

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

Definition at line 5496 of file rtpg_mapalgebra.c.

References ovdump::band, ES_NONE, FALSE, FLT_NEQ, rt_raster_serialized_t::height, pixval::nband, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, PT_END, r, rtrowdump::raster, RASTER_mapAlgebra2(), 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_deserialize(), rt_raster_destroy(), rt_raster_generate_new_band(), rt_raster_get_band(), 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_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_strtoupper(), rt_raster_serialized_t::size, text_to_cstring(), TRUE, rt_raster_serialized_t::width, pixval::x, and pixval::y.

Referenced by RASTER_mapAlgebraFct().

5497 {
5498  rt_pgraster *pgraster = NULL;
5499  rt_pgraster *pgrtn = NULL;
5500  rt_raster raster = NULL;
5501  rt_raster newrast = NULL;
5502  rt_band band = NULL;
5503  rt_band newband = NULL;
5504  int x, y, nband, width, height, ngbwidth, ngbheight, winwidth, winheight, u, v, nIndex, nNullItems;
5505  double r, rpix;
5506  double newnodatavalue = 0.0;
5507  double newinitialvalue = 0.0;
5508  double newval = 0.0;
5509  rt_pixtype newpixeltype;
5510  int ret = -1;
5511  Oid oid;
5512  FmgrInfo cbinfo;
5513  FunctionCallInfoData cbdata;
5514  Datum tmpnewval;
5515  ArrayType * neighborDatum;
5516  char * strFromText = NULL;
5517  text * txtNodataMode = NULL;
5518  text * txtCallbackParam = NULL;
5519  int intReplace = 0;
5520  float fltReplace = 0;
5521  bool valuereplace = false, pixelreplace, nNodataOnly = true, nNullSkip = false;
5522  Datum * neighborData = NULL;
5523  bool * neighborNulls = NULL;
5524  int neighborDims[2];
5525  int neighborLbs[2];
5526  int16 typlen;
5527  bool typbyval;
5528  char typalign;
5529 
5530  POSTGIS_RT_DEBUG(2, "RASTER_mapAlgebraFctNgb: STARTING...");
5531 
5532  /* Check raster */
5533  if (PG_ARGISNULL(0)) {
5534  elog(WARNING, "Raster is NULL. Returning NULL");
5535  PG_RETURN_NULL();
5536  }
5537 
5538 
5539  /* Deserialize raster */
5540  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
5541  raster = rt_raster_deserialize(pgraster, FALSE);
5542  if (NULL == raster)
5543  {
5544  PG_FREE_IF_COPY(pgraster, 0);
5545  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not deserialize raster");
5546  PG_RETURN_NULL();
5547  }
5548 
5549  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting arguments...");
5550 
5551  /* Get the rest of the arguments */
5552 
5553  if (PG_ARGISNULL(1))
5554  nband = 1;
5555  else
5556  nband = PG_GETARG_INT32(1);
5557 
5558  if (nband < 1)
5559  nband = 1;
5560 
5561  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Creating new empty raster...");
5562 
5567  width = rt_raster_get_width(raster);
5568  height = rt_raster_get_height(raster);
5569 
5570  newrast = rt_raster_new(width, height);
5571 
5572  if ( NULL == newrast ) {
5573  rt_raster_destroy(raster);
5574  PG_FREE_IF_COPY(pgraster, 0);
5575  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not create a new raster");
5576  PG_RETURN_NULL();
5577  }
5578 
5579  rt_raster_set_scale(newrast,
5580  rt_raster_get_x_scale(raster),
5581  rt_raster_get_y_scale(raster));
5582 
5583  rt_raster_set_offsets(newrast,
5584  rt_raster_get_x_offset(raster),
5585  rt_raster_get_y_offset(raster));
5586 
5587  rt_raster_set_skews(newrast,
5588  rt_raster_get_x_skew(raster),
5589  rt_raster_get_y_skew(raster));
5590 
5591  rt_raster_set_srid(newrast, rt_raster_get_srid(raster));
5592 
5593 
5598  if (rt_raster_is_empty(newrast))
5599  {
5600  elog(NOTICE, "Raster is empty. Returning an empty raster");
5601  rt_raster_destroy(raster);
5602  PG_FREE_IF_COPY(pgraster, 0);
5603 
5604  pgrtn = rt_raster_serialize(newrast);
5605  rt_raster_destroy(newrast);
5606  if (NULL == pgrtn) {
5607  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5608  PG_RETURN_NULL();
5609  }
5610 
5611  SET_VARSIZE(pgrtn, pgrtn->size);
5612  PG_RETURN_POINTER(pgrtn);
5613  }
5614 
5615  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Getting raster band %d...", nband);
5616 
5621  if (!rt_raster_has_band(raster, nband - 1)) {
5622  elog(NOTICE, "Raster does not have the required band. Returning a raster "
5623  "without a band");
5624  rt_raster_destroy(raster);
5625  PG_FREE_IF_COPY(pgraster, 0);
5626 
5627  pgrtn = rt_raster_serialize(newrast);
5628  rt_raster_destroy(newrast);
5629  if (NULL == pgrtn) {
5630  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5631  PG_RETURN_NULL();
5632  }
5633 
5634  SET_VARSIZE(pgrtn, pgrtn->size);
5635  PG_RETURN_POINTER(pgrtn);
5636  }
5637 
5638  /* Get the raster band */
5639  band = rt_raster_get_band(raster, nband - 1);
5640  if ( NULL == band ) {
5641  elog(NOTICE, "Could not get the required band. Returning a raster "
5642  "without a band");
5643  rt_raster_destroy(raster);
5644  PG_FREE_IF_COPY(pgraster, 0);
5645 
5646  pgrtn = rt_raster_serialize(newrast);
5647  rt_raster_destroy(newrast);
5648  if (NULL == pgrtn) {
5649  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5650  PG_RETURN_NULL();
5651  }
5652 
5653  SET_VARSIZE(pgrtn, pgrtn->size);
5654  PG_RETURN_POINTER(pgrtn);
5655  }
5656 
5657  /*
5658  * Get NODATA value
5659  */
5660  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting NODATA value for band...");
5661 
5662  if (rt_band_get_hasnodata_flag(band)) {
5663  rt_band_get_nodata(band, &newnodatavalue);
5664  }
5665 
5666  else {
5667  newnodatavalue = rt_band_get_min_value(band);
5668  }
5669 
5670  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: NODATA value for band: %f",
5671  newnodatavalue);
5677  newinitialvalue = newnodatavalue;
5678 
5682  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Setting pixeltype...");
5683 
5684  if (PG_ARGISNULL(2)) {
5685  newpixeltype = rt_band_get_pixtype(band);
5686  }
5687 
5688  else {
5689  strFromText = text_to_cstring(PG_GETARG_TEXT_P(2));
5690  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype parameter: %s", strFromText);
5691  newpixeltype = rt_pixtype_index_from_name(strFromText);
5692  pfree(strFromText);
5693  if (newpixeltype == PT_END)
5694  newpixeltype = rt_band_get_pixtype(band);
5695  }
5696 
5697  if (newpixeltype == PT_END) {
5698 
5699  rt_raster_destroy(raster);
5700  PG_FREE_IF_COPY(pgraster, 0);
5701  rt_raster_destroy(newrast);
5702 
5703  elog(ERROR, "RASTER_mapAlgebraFctNgb: Invalid pixeltype");
5704  PG_RETURN_NULL();
5705  }
5706 
5707  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype set to %s (%d)",
5708  rt_pixtype_name(newpixeltype), newpixeltype);
5709 
5710  /* Get the name of the callback userfunction */
5711  if (PG_ARGISNULL(5)) {
5712 
5713  rt_raster_destroy(raster);
5714  PG_FREE_IF_COPY(pgraster, 0);
5715  rt_raster_destroy(newrast);
5716 
5717  elog(ERROR, "RASTER_mapAlgebraFctNgb: Required function is missing");
5718  PG_RETURN_NULL();
5719  }
5720 
5721  oid = PG_GETARG_OID(5);
5722  if (oid == InvalidOid) {
5723 
5724  rt_raster_destroy(raster);
5725  PG_FREE_IF_COPY(pgraster, 0);
5726  rt_raster_destroy(newrast);
5727 
5728  elog(ERROR, "RASTER_mapAlgebraFctNgb: Got invalid function object id");
5729  PG_RETURN_NULL();
5730  }
5731 
5732  fmgr_info(oid, &cbinfo);
5733 
5734  /* function cannot return set */
5735  if (cbinfo.fn_retset) {
5736 
5737  rt_raster_destroy(raster);
5738  PG_FREE_IF_COPY(pgraster, 0);
5739  rt_raster_destroy(newrast);
5740 
5741  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function provided must return double precision not resultset");
5742  PG_RETURN_NULL();
5743  }
5744  /* function should have correct # of args */
5745  else if (cbinfo.fn_nargs != 3) {
5746 
5747  rt_raster_destroy(raster);
5748  PG_FREE_IF_COPY(pgraster, 0);
5749  rt_raster_destroy(newrast);
5750 
5751  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function does not have three input parameters");
5752  PG_RETURN_NULL();
5753  }
5754 
5755  if (func_volatile(oid) == 'v') {
5756  elog(NOTICE, "Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
5757  }
5758 
5759  /* prep function call data */
5760 #if POSTGIS_PGSQL_VERSION <= 90
5761  InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL);
5762 #else
5763  InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL, NULL);
5764 #endif
5765  memset(cbdata.argnull, FALSE, sizeof(bool) * 3);
5766 
5767  /* check that the function isn't strict if the args are null. */
5768  if (PG_ARGISNULL(7)) {
5769  if (cbinfo.fn_strict) {
5770 
5771  rt_raster_destroy(raster);
5772  PG_FREE_IF_COPY(pgraster, 0);
5773  rt_raster_destroy(newrast);
5774 
5775  elog(ERROR, "RASTER_mapAlgebraFctNgb: Strict callback functions cannot have NULL parameters");
5776  PG_RETURN_NULL();
5777  }
5778 
5779  cbdata.arg[2] = (Datum)NULL;
5780  cbdata.argnull[2] = TRUE;
5781  }
5782  else {
5783  cbdata.arg[2] = PG_GETARG_DATUM(7);
5784  }
5785 
5791  if (rt_band_get_isnodata_flag(band)) {
5792 
5793  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Band is a nodata band, returning "
5794  "a raster filled with nodata");
5795 
5796  rt_raster_generate_new_band(newrast, newpixeltype,
5797  newinitialvalue, TRUE, newnodatavalue, 0);
5798 
5799  rt_raster_destroy(raster);
5800  PG_FREE_IF_COPY(pgraster, 0);
5801 
5802  /* Serialize created raster */
5803  pgrtn = rt_raster_serialize(newrast);
5804  rt_raster_destroy(newrast);
5805  if (NULL == pgrtn) {
5806  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5807  PG_RETURN_NULL();
5808  }
5809 
5810  SET_VARSIZE(pgrtn, pgrtn->size);
5811  PG_RETURN_POINTER(pgrtn);
5812  }
5813 
5814 
5819  rt_raster_generate_new_band(newrast, newpixeltype,
5820  newinitialvalue, TRUE, newnodatavalue, 0);
5821 
5822  /* Get the new raster band */
5823  newband = rt_raster_get_band(newrast, 0);
5824  if ( NULL == newband ) {
5825  elog(NOTICE, "Could not modify band for new raster. Returning new "
5826  "raster with the original band");
5827 
5828  rt_raster_destroy(raster);
5829  PG_FREE_IF_COPY(pgraster, 0);
5830 
5831  /* Serialize created raster */
5832  pgrtn = rt_raster_serialize(newrast);
5833  rt_raster_destroy(newrast);
5834  if (NULL == pgrtn) {
5835  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5836  PG_RETURN_NULL();
5837  }
5838 
5839  SET_VARSIZE(pgrtn, pgrtn->size);
5840  PG_RETURN_POINTER(pgrtn);
5841  }
5842 
5843  /* Get the width of the neighborhood */
5844  if (PG_ARGISNULL(3) || PG_GETARG_INT32(3) <= 0) {
5845  elog(NOTICE, "Neighborhood width is NULL or <= 0. Returning new "
5846  "raster with the original band");
5847 
5848  rt_raster_destroy(raster);
5849  PG_FREE_IF_COPY(pgraster, 0);
5850 
5851  /* Serialize created raster */
5852  pgrtn = rt_raster_serialize(newrast);
5853  rt_raster_destroy(newrast);
5854  if (NULL == pgrtn) {
5855  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5856  PG_RETURN_NULL();
5857  }
5858 
5859  SET_VARSIZE(pgrtn, pgrtn->size);
5860  PG_RETURN_POINTER(pgrtn);
5861  }
5862 
5863  ngbwidth = PG_GETARG_INT32(3);
5864  winwidth = ngbwidth * 2 + 1;
5865 
5866  /* Get the height of the neighborhood */
5867  if (PG_ARGISNULL(4) || PG_GETARG_INT32(4) <= 0) {
5868  elog(NOTICE, "Neighborhood height is NULL or <= 0. Returning new "
5869  "raster with the original band");
5870 
5871  rt_raster_destroy(raster);
5872  PG_FREE_IF_COPY(pgraster, 0);
5873 
5874  /* Serialize created raster */
5875  pgrtn = rt_raster_serialize(newrast);
5876  rt_raster_destroy(newrast);
5877  if (NULL == pgrtn) {
5878  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5879  PG_RETURN_NULL();
5880  }
5881 
5882  SET_VARSIZE(pgrtn, pgrtn->size);
5883  PG_RETURN_POINTER(pgrtn);
5884  }
5885 
5886  ngbheight = PG_GETARG_INT32(4);
5887  winheight = ngbheight * 2 + 1;
5888 
5889  /* Get the type of NODATA behavior for the neighborhoods. */
5890  if (PG_ARGISNULL(6)) {
5891  elog(NOTICE, "Neighborhood NODATA behavior defaulting to 'ignore'");
5892  txtNodataMode = cstring_to_text("ignore");
5893  }
5894  else {
5895  txtNodataMode = PG_GETARG_TEXT_P(6);
5896  }
5897 
5898  txtCallbackParam = (text*)palloc(VARSIZE(txtNodataMode));
5899  SET_VARSIZE(txtCallbackParam, VARSIZE(txtNodataMode));
5900  memcpy((void *)VARDATA(txtCallbackParam), (void *)VARDATA(txtNodataMode), VARSIZE(txtNodataMode) - VARHDRSZ);
5901 
5902  /* pass the nodata mode into the user function */
5903  cbdata.arg[1] = CStringGetDatum(txtCallbackParam);
5904 
5905  strFromText = text_to_cstring(txtNodataMode);
5906  strFromText = rtpg_strtoupper(strFromText);
5907 
5908  if (strcmp(strFromText, "VALUE") == 0)
5909  valuereplace = true;
5910  else if (strcmp(strFromText, "IGNORE") != 0 && strcmp(strFromText, "NULL") != 0) {
5911  /* if the text is not "IGNORE" or "NULL", it may be a numerical value */
5912  if (sscanf(strFromText, "%d", &intReplace) <= 0 && sscanf(strFromText, "%f", &fltReplace) <= 0) {
5913  /* the value is NOT an integer NOR a floating point */
5914  elog(NOTICE, "Neighborhood NODATA mode is not recognized. Must be one of 'value', 'ignore', "
5915  "'NULL', or a numeric value. Returning new raster with the original band");
5916 
5917  /* clean up the nodatamode string */
5918  pfree(txtCallbackParam);
5919  pfree(strFromText);
5920 
5921  rt_raster_destroy(raster);
5922  PG_FREE_IF_COPY(pgraster, 0);
5923 
5924  /* Serialize created raster */
5925  pgrtn = rt_raster_serialize(newrast);
5926  rt_raster_destroy(newrast);
5927  if (NULL == pgrtn) {
5928  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5929  PG_RETURN_NULL();
5930  }
5931 
5932  SET_VARSIZE(pgrtn, pgrtn->size);
5933  PG_RETURN_POINTER(pgrtn);
5934  }
5935  }
5936  else if (strcmp(strFromText, "NULL") == 0) {
5937  /* this setting means that the neighborhood should be skipped if any of the values are null */
5938  nNullSkip = true;
5939  }
5940 
5941  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Main computing loop (%d x %d)",
5942  width, height);
5943 
5944  /* Allocate room for the neighborhood. */
5945  neighborData = (Datum *)palloc(winwidth * winheight * sizeof(Datum));
5946  neighborNulls = (bool *)palloc(winwidth * winheight * sizeof(bool));
5947 
5948  /* The dimensions of the neighborhood array, for creating a multi-dimensional array. */
5949  neighborDims[0] = winwidth;
5950  neighborDims[1] = winheight;
5951 
5952  /* The lower bounds for the new multi-dimensional array. */
5953  neighborLbs[0] = 1;
5954  neighborLbs[1] = 1;
5955 
5956  /* Get information about the type of item in the multi-dimensional array (float8). */
5957  get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
5958 
5959  for (x = 0 + ngbwidth; x < width - ngbwidth; x++) {
5960  for(y = 0 + ngbheight; y < height - ngbheight; y++) {
5961  /* populate an array with the pixel values in the neighborhood */
5962  nIndex = 0;
5963  nNullItems = 0;
5964  nNodataOnly = true;
5965  pixelreplace = false;
5966  if (valuereplace) {
5967  ret = rt_band_get_pixel(band, x, y, &rpix, NULL);
5968  if (ret == ES_NONE && FLT_NEQ(rpix, newnodatavalue)) {
5969  pixelreplace = true;
5970  }
5971  }
5972  for (u = x - ngbwidth; u <= x + ngbwidth; u++) {
5973  for (v = y - ngbheight; v <= y + ngbheight; v++) {
5974  ret = rt_band_get_pixel(band, u, v, &r, NULL);
5975  if (ret == ES_NONE) {
5976  if (FLT_NEQ(r, newnodatavalue)) {
5977  /* If the pixel value for this neighbor cell is not NODATA */
5978  neighborData[nIndex] = Float8GetDatum((double)r);
5979  neighborNulls[nIndex] = false;
5980  nNodataOnly = false;
5981  }
5982  else {
5983  /* If the pixel value for this neighbor cell is NODATA */
5984  if (valuereplace && pixelreplace) {
5985  /* Replace the NODATA value with the currently processing pixel. */
5986  neighborData[nIndex] = Float8GetDatum((double)rpix);
5987  neighborNulls[nIndex] = false;
5988  /* do not increment nNullItems, since the user requested that the */
5989  /* neighborhood replace NODATA values with the central pixel value */
5990  }
5991  else {
5992  neighborData[nIndex] = PointerGetDatum(NULL);
5993  neighborNulls[nIndex] = true;
5994  nNullItems++;
5995  }
5996  }
5997  }
5998  else {
5999  /* Fill this will NULL if we can't read the raster pixel. */
6000  neighborData[nIndex] = PointerGetDatum(NULL);
6001  neighborNulls[nIndex] = true;
6002  nNullItems++;
6003  }
6004  /* Next neighbor position */
6005  nIndex++;
6006  }
6007  }
6008 
6013  if (!(nNodataOnly || /* neighborhood only contains NODATA -- OR -- */
6014  (nNullSkip && nNullItems > 0) || /* neighborhood should skip any NODATA cells, and a NODATA cell was detected -- OR -- */
6015  (valuereplace && nNullItems > 0))) { /* neighborhood should replace NODATA cells with the central pixel value, and a NODATA cell was detected */
6016  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: (%dx%d), %dx%d neighborhood",
6017  x, y, winwidth, winheight);
6018 
6019  neighborDatum = construct_md_array((void *)neighborData, neighborNulls, 2, neighborDims, neighborLbs,
6020  FLOAT8OID, typlen, typbyval, typalign);
6021 
6022  /* Assign the neighbor matrix as the first argument to the user function */
6023  cbdata.arg[0] = PointerGetDatum(neighborDatum);
6024 
6025  /* Invoke the user function */
6026  tmpnewval = FunctionCallInvoke(&cbdata);
6027 
6028  /* Get the return value of the user function */
6029  if (cbdata.isnull) {
6030  newval = newnodatavalue;
6031  }
6032  else {
6033  newval = DatumGetFloat8(tmpnewval);
6034  }
6035 
6036  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: new value = %f",
6037  newval);
6038 
6039  rt_band_set_pixel(newband, x, y, newval, NULL);
6040  }
6041 
6042  /* reset the number of null items in the neighborhood */
6043  nNullItems = 0;
6044  }
6045  }
6046 
6047 
6048  /* clean up */
6049  pfree(neighborNulls);
6050  pfree(neighborData);
6051  pfree(strFromText);
6052  pfree(txtCallbackParam);
6053 
6054  rt_raster_destroy(raster);
6055  PG_FREE_IF_COPY(pgraster, 0);
6056 
6057  /* The newrast band has been modified */
6058 
6059  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster modified, serializing it.");
6060  /* Serialize created raster */
6061 
6062  pgrtn = rt_raster_serialize(newrast);
6063  rt_raster_destroy(newrast);
6064  if (NULL == pgrtn)
6065  PG_RETURN_NULL();
6066 
6067  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster serialized");
6068  POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraFctNgb: returning raster");
6069 
6070  SET_VARSIZE(pgrtn, pgrtn->size);
6071  PG_RETURN_POINTER(pgrtn);
6072 }
char * text_to_cstring(const text *textptr)
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
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
char * r
Definition: cu_in_wkt.c:24
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
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
band
Definition: ovdump.py:57
rt_pixtype
Definition: librtcore.h:185
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1338
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1682
nband
Definition: pixval.py:52
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1173
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
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
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_pixel.c:80
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
#define FLT_NEQ(x, y)
Definition: librtcore.h:2213
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:626
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
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:1351
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster&#39;s SRID.
Definition: rt_raster.c:363
int32_t rt_raster_get_srid(rt_raster raster)
Get raster&#39;s SRID.
Definition: rt_raster.c:356
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
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 rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2230
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:1697
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:583
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:666
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
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:61
#define TRUE
Definition: dbfopen.c:169
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
char * rtpg_strtoupper(char *str)
Here is the call graph for this function:
Here is the caller graph for this function: