PostGIS  2.2.8dev-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 5501 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, TRUE, rt_raster_serialized_t::width, pixval::x, and pixval::y.

Referenced by RASTER_mapAlgebraFct().

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