PostGIS  2.4.9dev-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 5595 of file rtpg_mapalgebra.c.

References ovdump::band, ES_NONE, FALSE, FLT_NEQ, rt_raster_serialized_t::height, pixval::nband, POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, PT_END, r, rtrowdump::raster, 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, TRUE, rt_raster_serialized_t::width, pixval::x, and pixval::y.

Referenced by RASTER_mapAlgebraFct().

5596 {
5597  rt_pgraster *pgraster = NULL;
5598  rt_pgraster *pgrtn = NULL;
5599  rt_raster raster = NULL;
5600  rt_raster newrast = NULL;
5601  rt_band band = NULL;
5602  rt_band newband = NULL;
5603  int x, y, nband, width, height, ngbwidth, ngbheight, winwidth, winheight, u, v, nIndex, nNullItems;
5604  double r, rpix;
5605  double newnodatavalue = 0.0;
5606  double newinitialvalue = 0.0;
5607  double newval = 0.0;
5608  rt_pixtype newpixeltype;
5609  int ret = -1;
5610  Oid oid;
5611  FmgrInfo cbinfo;
5612 #if POSTGIS_PGSQL_VERSION < 120
5613  FunctionCallInfoData cbdata;
5614 #else
5615  LOCAL_FCINFO(cbdata, FUNC_MAX_ARGS); /* Could be optimized */
5616 #endif
5617  Datum tmpnewval;
5618  ArrayType * neighborDatum;
5619  char * strFromText = NULL;
5620  text * txtNodataMode = NULL;
5621  text * txtCallbackParam = NULL;
5622  int intReplace = 0;
5623  float fltReplace = 0;
5624  bool valuereplace = false, pixelreplace, nNodataOnly = true, nNullSkip = false;
5625  Datum * neighborData = NULL;
5626  bool * neighborNulls = NULL;
5627  int neighborDims[2];
5628  int neighborLbs[2];
5629  int16 typlen;
5630  bool typbyval;
5631  char typalign;
5632 
5633  POSTGIS_RT_DEBUG(2, "RASTER_mapAlgebraFctNgb: STARTING...");
5634 
5635  /* Check raster */
5636  if (PG_ARGISNULL(0)) {
5637  elog(WARNING, "Raster is NULL. Returning NULL");
5638  PG_RETURN_NULL();
5639  }
5640 
5641 
5642  /* Deserialize raster */
5643  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
5644  raster = rt_raster_deserialize(pgraster, FALSE);
5645  if (NULL == raster)
5646  {
5647  PG_FREE_IF_COPY(pgraster, 0);
5648  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not deserialize raster");
5649  PG_RETURN_NULL();
5650  }
5651 
5652  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting arguments...");
5653 
5654  /* Get the rest of the arguments */
5655 
5656  if (PG_ARGISNULL(1))
5657  nband = 1;
5658  else
5659  nband = PG_GETARG_INT32(1);
5660 
5661  if (nband < 1)
5662  nband = 1;
5663 
5664  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Creating new empty raster...");
5665 
5670  width = rt_raster_get_width(raster);
5671  height = rt_raster_get_height(raster);
5672 
5673  newrast = rt_raster_new(width, height);
5674 
5675  if ( NULL == newrast ) {
5676  rt_raster_destroy(raster);
5677  PG_FREE_IF_COPY(pgraster, 0);
5678  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not create a new raster");
5679  PG_RETURN_NULL();
5680  }
5681 
5682  rt_raster_set_scale(newrast,
5683  rt_raster_get_x_scale(raster),
5684  rt_raster_get_y_scale(raster));
5685 
5686  rt_raster_set_offsets(newrast,
5687  rt_raster_get_x_offset(raster),
5688  rt_raster_get_y_offset(raster));
5689 
5690  rt_raster_set_skews(newrast,
5691  rt_raster_get_x_skew(raster),
5692  rt_raster_get_y_skew(raster));
5693 
5694  rt_raster_set_srid(newrast, rt_raster_get_srid(raster));
5695 
5696 
5701  if (rt_raster_is_empty(newrast))
5702  {
5703  elog(NOTICE, "Raster is empty. Returning an empty raster");
5704  rt_raster_destroy(raster);
5705  PG_FREE_IF_COPY(pgraster, 0);
5706 
5707  pgrtn = rt_raster_serialize(newrast);
5708  rt_raster_destroy(newrast);
5709  if (NULL == pgrtn) {
5710  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5711  PG_RETURN_NULL();
5712  }
5713 
5714  SET_VARSIZE(pgrtn, pgrtn->size);
5715  PG_RETURN_POINTER(pgrtn);
5716  }
5717 
5718  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Getting raster band %d...", nband);
5719 
5724  if (!rt_raster_has_band(raster, nband - 1)) {
5725  elog(NOTICE, "Raster does not have the required band. Returning a raster "
5726  "without a band");
5727  rt_raster_destroy(raster);
5728  PG_FREE_IF_COPY(pgraster, 0);
5729 
5730  pgrtn = rt_raster_serialize(newrast);
5731  rt_raster_destroy(newrast);
5732  if (NULL == pgrtn) {
5733  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5734  PG_RETURN_NULL();
5735  }
5736 
5737  SET_VARSIZE(pgrtn, pgrtn->size);
5738  PG_RETURN_POINTER(pgrtn);
5739  }
5740 
5741  /* Get the raster band */
5742  band = rt_raster_get_band(raster, nband - 1);
5743  if ( NULL == band ) {
5744  elog(NOTICE, "Could not get the required band. Returning a raster "
5745  "without a band");
5746  rt_raster_destroy(raster);
5747  PG_FREE_IF_COPY(pgraster, 0);
5748 
5749  pgrtn = rt_raster_serialize(newrast);
5750  rt_raster_destroy(newrast);
5751  if (NULL == pgrtn) {
5752  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5753  PG_RETURN_NULL();
5754  }
5755 
5756  SET_VARSIZE(pgrtn, pgrtn->size);
5757  PG_RETURN_POINTER(pgrtn);
5758  }
5759 
5760  /*
5761  * Get NODATA value
5762  */
5763  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting NODATA value for band...");
5764 
5765  if (rt_band_get_hasnodata_flag(band)) {
5766  rt_band_get_nodata(band, &newnodatavalue);
5767  }
5768 
5769  else {
5770  newnodatavalue = rt_band_get_min_value(band);
5771  }
5772 
5773  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: NODATA value for band: %f",
5774  newnodatavalue);
5780  newinitialvalue = newnodatavalue;
5781 
5785  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Setting pixeltype...");
5786 
5787  if (PG_ARGISNULL(2)) {
5788  newpixeltype = rt_band_get_pixtype(band);
5789  }
5790 
5791  else {
5792  strFromText = text_to_cstring(PG_GETARG_TEXT_P(2));
5793  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype parameter: %s", strFromText);
5794  newpixeltype = rt_pixtype_index_from_name(strFromText);
5795  pfree(strFromText);
5796  if (newpixeltype == PT_END)
5797  newpixeltype = rt_band_get_pixtype(band);
5798  }
5799 
5800  if (newpixeltype == PT_END) {
5801 
5802  rt_raster_destroy(raster);
5803  PG_FREE_IF_COPY(pgraster, 0);
5804  rt_raster_destroy(newrast);
5805 
5806  elog(ERROR, "RASTER_mapAlgebraFctNgb: Invalid pixeltype");
5807  PG_RETURN_NULL();
5808  }
5809 
5810  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype set to %s (%d)",
5811  rt_pixtype_name(newpixeltype), newpixeltype);
5812 
5813  /* Get the name of the callback userfunction */
5814  if (PG_ARGISNULL(5)) {
5815 
5816  rt_raster_destroy(raster);
5817  PG_FREE_IF_COPY(pgraster, 0);
5818  rt_raster_destroy(newrast);
5819 
5820  elog(ERROR, "RASTER_mapAlgebraFctNgb: Required function is missing");
5821  PG_RETURN_NULL();
5822  }
5823 
5824  oid = PG_GETARG_OID(5);
5825  if (oid == InvalidOid) {
5826 
5827  rt_raster_destroy(raster);
5828  PG_FREE_IF_COPY(pgraster, 0);
5829  rt_raster_destroy(newrast);
5830 
5831  elog(ERROR, "RASTER_mapAlgebraFctNgb: Got invalid function object id");
5832  PG_RETURN_NULL();
5833  }
5834 
5835  fmgr_info(oid, &cbinfo);
5836 
5837  /* function cannot return set */
5838  if (cbinfo.fn_retset) {
5839 
5840  rt_raster_destroy(raster);
5841  PG_FREE_IF_COPY(pgraster, 0);
5842  rt_raster_destroy(newrast);
5843 
5844  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function provided must return double precision not resultset");
5845  PG_RETURN_NULL();
5846  }
5847  /* function should have correct # of args */
5848  else if (cbinfo.fn_nargs != 3) {
5849 
5850  rt_raster_destroy(raster);
5851  PG_FREE_IF_COPY(pgraster, 0);
5852  rt_raster_destroy(newrast);
5853 
5854  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function does not have three input parameters");
5855  PG_RETURN_NULL();
5856  }
5857 
5858  if (func_volatile(oid) == 'v') {
5859  elog(NOTICE, "Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
5860  }
5861 
5862  /* prep function call data */
5863 #if POSTGIS_PGSQL_VERSION < 120
5864  InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL, NULL);
5865  memset(cbdata.argnull, FALSE, sizeof(bool) * 3);
5866 #else
5867  InitFunctionCallInfoData(*cbdata, &cbinfo, 3, InvalidOid, NULL, NULL);
5868  cbdata->args[0].isnull = FALSE;
5869  cbdata->args[1].isnull = FALSE;
5870  cbdata->args[2].isnull = FALSE;
5871 #endif
5872 
5873  /* check that the function isn't strict if the args are null. */
5874  if (PG_ARGISNULL(7)) {
5875  if (cbinfo.fn_strict) {
5876 
5877  rt_raster_destroy(raster);
5878  PG_FREE_IF_COPY(pgraster, 0);
5879  rt_raster_destroy(newrast);
5880 
5881  elog(ERROR, "RASTER_mapAlgebraFctNgb: Strict callback functions cannot have NULL parameters");
5882  PG_RETURN_NULL();
5883  }
5884 
5885 #if POSTGIS_PGSQL_VERSION < 120
5886  cbdata.arg[2] = (Datum)NULL;
5887  cbdata.argnull[2] = TRUE;
5888 #else
5889  cbdata->args[2].value = (Datum)NULL;
5890  cbdata->args[2].isnull = TRUE;
5891 #endif
5892  }
5893  else {
5894 #if POSTGIS_PGSQL_VERSION < 120
5895  cbdata.arg[2] = PG_GETARG_DATUM(7);
5896 #else
5897  cbdata->args[2].value = PG_GETARG_DATUM(7);
5898 #endif
5899  }
5900 
5906  if (rt_band_get_isnodata_flag(band)) {
5907 
5908  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Band is a nodata band, returning "
5909  "a raster filled with nodata");
5910 
5911  rt_raster_generate_new_band(newrast, newpixeltype,
5912  newinitialvalue, TRUE, newnodatavalue, 0);
5913 
5914  rt_raster_destroy(raster);
5915  PG_FREE_IF_COPY(pgraster, 0);
5916 
5917  /* Serialize created raster */
5918  pgrtn = rt_raster_serialize(newrast);
5919  rt_raster_destroy(newrast);
5920  if (NULL == pgrtn) {
5921  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5922  PG_RETURN_NULL();
5923  }
5924 
5925  SET_VARSIZE(pgrtn, pgrtn->size);
5926  PG_RETURN_POINTER(pgrtn);
5927  }
5928 
5929 
5934  rt_raster_generate_new_band(newrast, newpixeltype,
5935  newinitialvalue, TRUE, newnodatavalue, 0);
5936 
5937  /* Get the new raster band */
5938  newband = rt_raster_get_band(newrast, 0);
5939  if ( NULL == newband ) {
5940  elog(NOTICE, "Could not modify band for new raster. Returning new "
5941  "raster with the original band");
5942 
5943  rt_raster_destroy(raster);
5944  PG_FREE_IF_COPY(pgraster, 0);
5945 
5946  /* Serialize created raster */
5947  pgrtn = rt_raster_serialize(newrast);
5948  rt_raster_destroy(newrast);
5949  if (NULL == pgrtn) {
5950  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5951  PG_RETURN_NULL();
5952  }
5953 
5954  SET_VARSIZE(pgrtn, pgrtn->size);
5955  PG_RETURN_POINTER(pgrtn);
5956  }
5957 
5958  /* Get the width of the neighborhood */
5959  if (PG_ARGISNULL(3) || PG_GETARG_INT32(3) <= 0) {
5960  elog(NOTICE, "Neighborhood width is NULL or <= 0. Returning new "
5961  "raster with the original band");
5962 
5963  rt_raster_destroy(raster);
5964  PG_FREE_IF_COPY(pgraster, 0);
5965 
5966  /* Serialize created raster */
5967  pgrtn = rt_raster_serialize(newrast);
5968  rt_raster_destroy(newrast);
5969  if (NULL == pgrtn) {
5970  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5971  PG_RETURN_NULL();
5972  }
5973 
5974  SET_VARSIZE(pgrtn, pgrtn->size);
5975  PG_RETURN_POINTER(pgrtn);
5976  }
5977 
5978  ngbwidth = PG_GETARG_INT32(3);
5979  winwidth = ngbwidth * 2 + 1;
5980 
5981  /* Get the height of the neighborhood */
5982  if (PG_ARGISNULL(4) || PG_GETARG_INT32(4) <= 0) {
5983  elog(NOTICE, "Neighborhood height is NULL or <= 0. Returning new "
5984  "raster with the original band");
5985 
5986  rt_raster_destroy(raster);
5987  PG_FREE_IF_COPY(pgraster, 0);
5988 
5989  /* Serialize created raster */
5990  pgrtn = rt_raster_serialize(newrast);
5991  rt_raster_destroy(newrast);
5992  if (NULL == pgrtn) {
5993  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
5994  PG_RETURN_NULL();
5995  }
5996 
5997  SET_VARSIZE(pgrtn, pgrtn->size);
5998  PG_RETURN_POINTER(pgrtn);
5999  }
6000 
6001  ngbheight = PG_GETARG_INT32(4);
6002  winheight = ngbheight * 2 + 1;
6003 
6004  /* Get the type of NODATA behavior for the neighborhoods. */
6005  if (PG_ARGISNULL(6)) {
6006  elog(NOTICE, "Neighborhood NODATA behavior defaulting to 'ignore'");
6007  txtNodataMode = cstring_to_text("ignore");
6008  }
6009  else {
6010  txtNodataMode = PG_GETARG_TEXT_P(6);
6011  }
6012 
6013  txtCallbackParam = (text*)palloc(VARSIZE(txtNodataMode));
6014  SET_VARSIZE(txtCallbackParam, VARSIZE(txtNodataMode));
6015  memcpy((void *)VARDATA(txtCallbackParam), (void *)VARDATA(txtNodataMode), VARSIZE(txtNodataMode) - VARHDRSZ);
6016 
6017  /* pass the nodata mode into the user function */
6018 #if POSTGIS_PGSQL_VERSION < 120
6019  cbdata.arg[1] = CStringGetDatum(txtCallbackParam);
6020 #else
6021  cbdata->args[1].value = CStringGetDatum(txtCallbackParam);
6022 #endif
6023 
6024  strFromText = text_to_cstring(txtNodataMode);
6025  strFromText = rtpg_strtoupper(strFromText);
6026 
6027  if (strcmp(strFromText, "VALUE") == 0)
6028  valuereplace = true;
6029  else if (strcmp(strFromText, "IGNORE") != 0 && strcmp(strFromText, "NULL") != 0) {
6030  /* if the text is not "IGNORE" or "NULL", it may be a numerical value */
6031  if (sscanf(strFromText, "%d", &intReplace) <= 0 && sscanf(strFromText, "%f", &fltReplace) <= 0) {
6032  /* the value is NOT an integer NOR a floating point */
6033  elog(NOTICE, "Neighborhood NODATA mode is not recognized. Must be one of 'value', 'ignore', "
6034  "'NULL', or a numeric value. Returning new raster with the original band");
6035 
6036  /* clean up the nodatamode string */
6037  pfree(txtCallbackParam);
6038  pfree(strFromText);
6039 
6040  rt_raster_destroy(raster);
6041  PG_FREE_IF_COPY(pgraster, 0);
6042 
6043  /* Serialize created raster */
6044  pgrtn = rt_raster_serialize(newrast);
6045  rt_raster_destroy(newrast);
6046  if (NULL == pgrtn) {
6047  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
6048  PG_RETURN_NULL();
6049  }
6050 
6051  SET_VARSIZE(pgrtn, pgrtn->size);
6052  PG_RETURN_POINTER(pgrtn);
6053  }
6054  }
6055  else if (strcmp(strFromText, "NULL") == 0) {
6056  /* this setting means that the neighborhood should be skipped if any of the values are null */
6057  nNullSkip = true;
6058  }
6059 
6060  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Main computing loop (%d x %d)",
6061  width, height);
6062 
6063  /* Allocate room for the neighborhood. */
6064  neighborData = (Datum *)palloc(winwidth * winheight * sizeof(Datum));
6065  neighborNulls = (bool *)palloc(winwidth * winheight * sizeof(bool));
6066 
6067  /* The dimensions of the neighborhood array, for creating a multi-dimensional array. */
6068  neighborDims[0] = winwidth;
6069  neighborDims[1] = winheight;
6070 
6071  /* The lower bounds for the new multi-dimensional array. */
6072  neighborLbs[0] = 1;
6073  neighborLbs[1] = 1;
6074 
6075  /* Get information about the type of item in the multi-dimensional array (float8). */
6076  get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
6077 
6078  for (x = 0 + ngbwidth; x < width - ngbwidth; x++) {
6079  for(y = 0 + ngbheight; y < height - ngbheight; y++) {
6080  /* populate an array with the pixel values in the neighborhood */
6081  nIndex = 0;
6082  nNullItems = 0;
6083  nNodataOnly = true;
6084  pixelreplace = false;
6085  if (valuereplace) {
6086  ret = rt_band_get_pixel(band, x, y, &rpix, NULL);
6087  if (ret == ES_NONE && FLT_NEQ(rpix, newnodatavalue)) {
6088  pixelreplace = true;
6089  }
6090  }
6091  for (u = x - ngbwidth; u <= x + ngbwidth; u++) {
6092  for (v = y - ngbheight; v <= y + ngbheight; v++) {
6093  ret = rt_band_get_pixel(band, u, v, &r, NULL);
6094  if (ret == ES_NONE) {
6095  if (FLT_NEQ(r, newnodatavalue)) {
6096  /* If the pixel value for this neighbor cell is not NODATA */
6097  neighborData[nIndex] = Float8GetDatum((double)r);
6098  neighborNulls[nIndex] = false;
6099  nNodataOnly = false;
6100  }
6101  else {
6102  /* If the pixel value for this neighbor cell is NODATA */
6103  if (valuereplace && pixelreplace) {
6104  /* Replace the NODATA value with the currently processing pixel. */
6105  neighborData[nIndex] = Float8GetDatum((double)rpix);
6106  neighborNulls[nIndex] = false;
6107  /* do not increment nNullItems, since the user requested that the */
6108  /* neighborhood replace NODATA values with the central pixel value */
6109  }
6110  else {
6111  neighborData[nIndex] = PointerGetDatum(NULL);
6112  neighborNulls[nIndex] = true;
6113  nNullItems++;
6114  }
6115  }
6116  }
6117  else {
6118  /* Fill this will NULL if we can't read the raster pixel. */
6119  neighborData[nIndex] = PointerGetDatum(NULL);
6120  neighborNulls[nIndex] = true;
6121  nNullItems++;
6122  }
6123  /* Next neighbor position */
6124  nIndex++;
6125  }
6126  }
6127 
6132  if (!(nNodataOnly || /* neighborhood only contains NODATA -- OR -- */
6133  (nNullSkip && nNullItems > 0) || /* neighborhood should skip any NODATA cells, and a NODATA cell was detected -- OR -- */
6134  (valuereplace && nNullItems > 0))) { /* neighborhood should replace NODATA cells with the central pixel value, and a NODATA cell was detected */
6135  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: (%dx%d), %dx%d neighborhood",
6136  x, y, winwidth, winheight);
6137 
6138  neighborDatum = construct_md_array((void *)neighborData, neighborNulls, 2, neighborDims, neighborLbs,
6139  FLOAT8OID, typlen, typbyval, typalign);
6140 
6141 #if POSTGIS_PGSQL_VERSION < 120
6142  /* Assign the neighbor matrix as the first argument to the user function */
6143  cbdata.arg[0] = PointerGetDatum(neighborDatum);
6144 
6145  /* Invoke the user function */
6146  tmpnewval = FunctionCallInvoke(&cbdata);
6147 
6148  /* Get the return value of the user function */
6149  if (cbdata.isnull) {
6150  newval = newnodatavalue;
6151  }
6152 #else
6153  /* Assign the neighbor matrix as the first argument to the user function */
6154  cbdata->args[0].value = PointerGetDatum(neighborDatum);
6155 
6156  /* Invoke the user function */
6157  tmpnewval = FunctionCallInvoke(cbdata);
6158 
6159  /* Get the return value of the user function */
6160  if (cbdata->isnull)
6161  {
6162  newval = newnodatavalue;
6163  }
6164 #endif
6165  else {
6166  newval = DatumGetFloat8(tmpnewval);
6167  }
6168 
6169  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: new value = %f",
6170  newval);
6171 
6172  rt_band_set_pixel(newband, x, y, newval, NULL);
6173  }
6174 
6175  /* reset the number of null items in the neighborhood */
6176  nNullItems = 0;
6177  }
6178  }
6179 
6180 
6181  /* clean up */
6182  pfree(neighborNulls);
6183  pfree(neighborData);
6184  pfree(strFromText);
6185  pfree(txtCallbackParam);
6186 
6187  rt_raster_destroy(raster);
6188  PG_FREE_IF_COPY(pgraster, 0);
6189 
6190  /* The newrast band has been modified */
6191 
6192  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster modified, serializing it.");
6193  /* Serialize created raster */
6194 
6195  pgrtn = rt_raster_serialize(newrast);
6196  rt_raster_destroy(newrast);
6197  if (NULL == pgrtn)
6198  PG_RETURN_NULL();
6199 
6200  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster serialized");
6201  POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraFctNgb: returning raster");
6202 
6203  SET_VARSIZE(pgrtn, pgrtn->size);
6204  PG_RETURN_POINTER(pgrtn);
6205 }
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:1597
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:1088
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:2184
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
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:2201
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:1612
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:498
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:581
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:841
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: