PostGIS  2.5.1dev-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 5495 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, text_to_cstring(), TRUE, rt_raster_serialized_t::width, pixval::x, and pixval::y.

Referenced by RASTER_mapAlgebraFct().

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