PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 15690 of file rt_pg.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.

15691 {
15692  rt_pgraster *pgraster = NULL;
15693  rt_pgraster *pgrtn = NULL;
15694  rt_raster raster = NULL;
15695  rt_raster newrast = NULL;
15696  rt_band band = NULL;
15697  rt_band newband = NULL;
15698  int x, y, nband, width, height, ngbwidth, ngbheight, winwidth, winheight, u, v, nIndex, nNullItems;
15699  double r, rpix;
15700  double newnodatavalue = 0.0;
15701  double newinitialvalue = 0.0;
15702  double newval = 0.0;
15703  rt_pixtype newpixeltype;
15704  int ret = -1;
15705  Oid oid;
15706  FmgrInfo cbinfo;
15707  FunctionCallInfoData cbdata;
15708  Datum tmpnewval;
15709  ArrayType * neighborDatum;
15710  char * strFromText = NULL;
15711  text * txtNodataMode = NULL;
15712  text * txtCallbackParam = NULL;
15713  int intReplace = 0;
15714  float fltReplace = 0;
15715  bool valuereplace = false, pixelreplace, nNodataOnly = true, nNullSkip = false;
15716  Datum * neighborData = NULL;
15717  bool * neighborNulls = NULL;
15718  int neighborDims[2];
15719  int neighborLbs[2];
15720  int16 typlen;
15721  bool typbyval;
15722  char typalign;
15723 
15724  POSTGIS_RT_DEBUG(2, "RASTER_mapAlgebraFctNgb: STARTING...");
15725 
15726  /* Check raster */
15727  if (PG_ARGISNULL(0)) {
15728  elog(WARNING, "Raster is NULL. Returning NULL");
15729  PG_RETURN_NULL();
15730  }
15731 
15732 
15733  /* Deserialize raster */
15734  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
15735  raster = rt_raster_deserialize(pgraster, FALSE);
15736  if (NULL == raster)
15737  {
15738  PG_FREE_IF_COPY(pgraster, 0);
15739  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not deserialize raster");
15740  PG_RETURN_NULL();
15741  }
15742 
15743  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting arguments...");
15744 
15745  /* Get the rest of the arguments */
15746 
15747  if (PG_ARGISNULL(1))
15748  nband = 1;
15749  else
15750  nband = PG_GETARG_INT32(1);
15751 
15752  if (nband < 1)
15753  nband = 1;
15754 
15755  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Creating new empty raster...");
15756 
15761  width = rt_raster_get_width(raster);
15762  height = rt_raster_get_height(raster);
15763 
15764  newrast = rt_raster_new(width, height);
15765 
15766  if ( NULL == newrast ) {
15767  rt_raster_destroy(raster);
15768  PG_FREE_IF_COPY(pgraster, 0);
15769  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not create a new raster");
15770  PG_RETURN_NULL();
15771  }
15772 
15773  rt_raster_set_scale(newrast,
15774  rt_raster_get_x_scale(raster),
15775  rt_raster_get_y_scale(raster));
15776 
15777  rt_raster_set_offsets(newrast,
15778  rt_raster_get_x_offset(raster),
15779  rt_raster_get_y_offset(raster));
15780 
15781  rt_raster_set_skews(newrast,
15782  rt_raster_get_x_skew(raster),
15783  rt_raster_get_y_skew(raster));
15784 
15785  rt_raster_set_srid(newrast, rt_raster_get_srid(raster));
15786 
15787 
15792  if (rt_raster_is_empty(newrast))
15793  {
15794  elog(NOTICE, "Raster is empty. Returning an empty raster");
15795  rt_raster_destroy(raster);
15796  PG_FREE_IF_COPY(pgraster, 0);
15797 
15798  pgrtn = rt_raster_serialize(newrast);
15799  rt_raster_destroy(newrast);
15800  if (NULL == pgrtn) {
15801  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
15802  PG_RETURN_NULL();
15803  }
15804 
15805  SET_VARSIZE(pgrtn, pgrtn->size);
15806  PG_RETURN_POINTER(pgrtn);
15807  }
15808 
15809  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Getting raster band %d...", nband);
15810 
15815  if (!rt_raster_has_band(raster, nband - 1)) {
15816  elog(NOTICE, "Raster does not have the required band. Returning a raster "
15817  "without a band");
15818  rt_raster_destroy(raster);
15819  PG_FREE_IF_COPY(pgraster, 0);
15820 
15821  pgrtn = rt_raster_serialize(newrast);
15822  rt_raster_destroy(newrast);
15823  if (NULL == pgrtn) {
15824  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
15825  PG_RETURN_NULL();
15826  }
15827 
15828  SET_VARSIZE(pgrtn, pgrtn->size);
15829  PG_RETURN_POINTER(pgrtn);
15830  }
15831 
15832  /* Get the raster band */
15833  band = rt_raster_get_band(raster, nband - 1);
15834  if ( NULL == band ) {
15835  elog(NOTICE, "Could not get the required band. Returning a raster "
15836  "without a band");
15837  rt_raster_destroy(raster);
15838  PG_FREE_IF_COPY(pgraster, 0);
15839 
15840  pgrtn = rt_raster_serialize(newrast);
15841  rt_raster_destroy(newrast);
15842  if (NULL == pgrtn) {
15843  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
15844  PG_RETURN_NULL();
15845  }
15846 
15847  SET_VARSIZE(pgrtn, pgrtn->size);
15848  PG_RETURN_POINTER(pgrtn);
15849  }
15850 
15851  /*
15852  * Get NODATA value
15853  */
15854  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Getting NODATA value for band...");
15855 
15856  if (rt_band_get_hasnodata_flag(band)) {
15857  rt_band_get_nodata(band, &newnodatavalue);
15858  }
15859 
15860  else {
15861  newnodatavalue = rt_band_get_min_value(band);
15862  }
15863 
15864  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: NODATA value for band: %f",
15865  newnodatavalue);
15871  newinitialvalue = newnodatavalue;
15872 
15876  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Setting pixeltype...");
15877 
15878  if (PG_ARGISNULL(2)) {
15879  newpixeltype = rt_band_get_pixtype(band);
15880  }
15881 
15882  else {
15883  strFromText = text_to_cstring(PG_GETARG_TEXT_P(2));
15884  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype parameter: %s", strFromText);
15885  newpixeltype = rt_pixtype_index_from_name(strFromText);
15886  pfree(strFromText);
15887  if (newpixeltype == PT_END)
15888  newpixeltype = rt_band_get_pixtype(band);
15889  }
15890 
15891  if (newpixeltype == PT_END) {
15892 
15893  rt_raster_destroy(raster);
15894  PG_FREE_IF_COPY(pgraster, 0);
15895  rt_raster_destroy(newrast);
15896 
15897  elog(ERROR, "RASTER_mapAlgebraFctNgb: Invalid pixeltype");
15898  PG_RETURN_NULL();
15899  }
15900 
15901  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Pixeltype set to %s (%d)",
15902  rt_pixtype_name(newpixeltype), newpixeltype);
15903 
15904  /* Get the name of the callback userfunction */
15905  if (PG_ARGISNULL(5)) {
15906 
15907  rt_raster_destroy(raster);
15908  PG_FREE_IF_COPY(pgraster, 0);
15909  rt_raster_destroy(newrast);
15910 
15911  elog(ERROR, "RASTER_mapAlgebraFctNgb: Required function is missing");
15912  PG_RETURN_NULL();
15913  }
15914 
15915  oid = PG_GETARG_OID(5);
15916  if (oid == InvalidOid) {
15917 
15918  rt_raster_destroy(raster);
15919  PG_FREE_IF_COPY(pgraster, 0);
15920  rt_raster_destroy(newrast);
15921 
15922  elog(ERROR, "RASTER_mapAlgebraFctNgb: Got invalid function object id");
15923  PG_RETURN_NULL();
15924  }
15925 
15926  fmgr_info(oid, &cbinfo);
15927 
15928  /* function cannot return set */
15929  if (cbinfo.fn_retset) {
15930 
15931  rt_raster_destroy(raster);
15932  PG_FREE_IF_COPY(pgraster, 0);
15933  rt_raster_destroy(newrast);
15934 
15935  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function provided must return double precision not resultset");
15936  PG_RETURN_NULL();
15937  }
15938  /* function should have correct # of args */
15939  else if (cbinfo.fn_nargs != 3) {
15940 
15941  rt_raster_destroy(raster);
15942  PG_FREE_IF_COPY(pgraster, 0);
15943  rt_raster_destroy(newrast);
15944 
15945  elog(ERROR, "RASTER_mapAlgebraFctNgb: Function does not have three input parameters");
15946  PG_RETURN_NULL();
15947  }
15948 
15949  if (func_volatile(oid) == 'v') {
15950  elog(NOTICE, "Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
15951  }
15952 
15953  /* prep function call data */
15954 #if POSTGIS_PGSQL_VERSION <= 90
15955  InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL);
15956 #else
15957  InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL, NULL);
15958 #endif
15959  memset(cbdata.argnull, FALSE, sizeof(bool) * 3);
15960 
15961  /* check that the function isn't strict if the args are null. */
15962  if (PG_ARGISNULL(7)) {
15963  if (cbinfo.fn_strict) {
15964 
15965  rt_raster_destroy(raster);
15966  PG_FREE_IF_COPY(pgraster, 0);
15967  rt_raster_destroy(newrast);
15968 
15969  elog(ERROR, "RASTER_mapAlgebraFctNgb: Strict callback functions cannot have NULL parameters");
15970  PG_RETURN_NULL();
15971  }
15972 
15973  cbdata.arg[2] = (Datum)NULL;
15974  cbdata.argnull[2] = TRUE;
15975  }
15976  else {
15977  cbdata.arg[2] = PG_GETARG_DATUM(7);
15978  }
15979 
15985  if (rt_band_get_isnodata_flag(band)) {
15986 
15987  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: Band is a nodata band, returning "
15988  "a raster filled with nodata");
15989 
15990  rt_raster_generate_new_band(newrast, newpixeltype,
15991  newinitialvalue, TRUE, newnodatavalue, 0);
15992 
15993  rt_raster_destroy(raster);
15994  PG_FREE_IF_COPY(pgraster, 0);
15995 
15996  /* Serialize created raster */
15997  pgrtn = rt_raster_serialize(newrast);
15998  rt_raster_destroy(newrast);
15999  if (NULL == pgrtn) {
16000  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
16001  PG_RETURN_NULL();
16002  }
16003 
16004  SET_VARSIZE(pgrtn, pgrtn->size);
16005  PG_RETURN_POINTER(pgrtn);
16006  }
16007 
16008 
16013  rt_raster_generate_new_band(newrast, newpixeltype,
16014  newinitialvalue, TRUE, newnodatavalue, 0);
16015 
16016  /* Get the new raster band */
16017  newband = rt_raster_get_band(newrast, 0);
16018  if ( NULL == newband ) {
16019  elog(NOTICE, "Could not modify band for new raster. Returning new "
16020  "raster with the original band");
16021 
16022  rt_raster_destroy(raster);
16023  PG_FREE_IF_COPY(pgraster, 0);
16024 
16025  /* Serialize created raster */
16026  pgrtn = rt_raster_serialize(newrast);
16027  rt_raster_destroy(newrast);
16028  if (NULL == pgrtn) {
16029  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
16030  PG_RETURN_NULL();
16031  }
16032 
16033  SET_VARSIZE(pgrtn, pgrtn->size);
16034  PG_RETURN_POINTER(pgrtn);
16035  }
16036 
16037  /* Get the width of the neighborhood */
16038  if (PG_ARGISNULL(3) || PG_GETARG_INT32(3) <= 0) {
16039  elog(NOTICE, "Neighborhood width is NULL or <= 0. Returning new "
16040  "raster with the original band");
16041 
16042  rt_raster_destroy(raster);
16043  PG_FREE_IF_COPY(pgraster, 0);
16044 
16045  /* Serialize created raster */
16046  pgrtn = rt_raster_serialize(newrast);
16047  rt_raster_destroy(newrast);
16048  if (NULL == pgrtn) {
16049  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
16050  PG_RETURN_NULL();
16051  }
16052 
16053  SET_VARSIZE(pgrtn, pgrtn->size);
16054  PG_RETURN_POINTER(pgrtn);
16055  }
16056 
16057  ngbwidth = PG_GETARG_INT32(3);
16058  winwidth = ngbwidth * 2 + 1;
16059 
16060  /* Get the height of the neighborhood */
16061  if (PG_ARGISNULL(4) || PG_GETARG_INT32(4) <= 0) {
16062  elog(NOTICE, "Neighborhood height is NULL or <= 0. Returning new "
16063  "raster with the original band");
16064 
16065  rt_raster_destroy(raster);
16066  PG_FREE_IF_COPY(pgraster, 0);
16067 
16068  /* Serialize created raster */
16069  pgrtn = rt_raster_serialize(newrast);
16070  rt_raster_destroy(newrast);
16071  if (NULL == pgrtn) {
16072  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
16073  PG_RETURN_NULL();
16074  }
16075 
16076  SET_VARSIZE(pgrtn, pgrtn->size);
16077  PG_RETURN_POINTER(pgrtn);
16078  }
16079 
16080  ngbheight = PG_GETARG_INT32(4);
16081  winheight = ngbheight * 2 + 1;
16082 
16083  /* Get the type of NODATA behavior for the neighborhoods. */
16084  if (PG_ARGISNULL(6)) {
16085  elog(NOTICE, "Neighborhood NODATA behavior defaulting to 'ignore'");
16086  txtNodataMode = cstring_to_text("ignore");
16087  }
16088  else {
16089  txtNodataMode = PG_GETARG_TEXT_P(6);
16090  }
16091 
16092  txtCallbackParam = (text*)palloc(VARSIZE(txtNodataMode));
16093  SET_VARSIZE(txtCallbackParam, VARSIZE(txtNodataMode));
16094  memcpy((void *)VARDATA(txtCallbackParam), (void *)VARDATA(txtNodataMode), VARSIZE(txtNodataMode) - VARHDRSZ);
16095 
16096  /* pass the nodata mode into the user function */
16097  cbdata.arg[1] = CStringGetDatum(txtCallbackParam);
16098 
16099  strFromText = text_to_cstring(txtNodataMode);
16100  strFromText = rtpg_strtoupper(strFromText);
16101 
16102  if (strcmp(strFromText, "VALUE") == 0)
16103  valuereplace = true;
16104  else if (strcmp(strFromText, "IGNORE") != 0 && strcmp(strFromText, "NULL") != 0) {
16105  /* if the text is not "IGNORE" or "NULL", it may be a numerical value */
16106  if (sscanf(strFromText, "%d", &intReplace) <= 0 && sscanf(strFromText, "%f", &fltReplace) <= 0) {
16107  /* the value is NOT an integer NOR a floating point */
16108  elog(NOTICE, "Neighborhood NODATA mode is not recognized. Must be one of 'value', 'ignore', "
16109  "'NULL', or a numeric value. Returning new raster with the original band");
16110 
16111  /* clean up the nodatamode string */
16112  pfree(txtCallbackParam);
16113  pfree(strFromText);
16114 
16115  rt_raster_destroy(raster);
16116  PG_FREE_IF_COPY(pgraster, 0);
16117 
16118  /* Serialize created raster */
16119  pgrtn = rt_raster_serialize(newrast);
16120  rt_raster_destroy(newrast);
16121  if (NULL == pgrtn) {
16122  elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster");
16123  PG_RETURN_NULL();
16124  }
16125 
16126  SET_VARSIZE(pgrtn, pgrtn->size);
16127  PG_RETURN_POINTER(pgrtn);
16128  }
16129  }
16130  else if (strcmp(strFromText, "NULL") == 0) {
16131  /* this setting means that the neighborhood should be skipped if any of the values are null */
16132  nNullSkip = true;
16133  }
16134 
16135  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: Main computing loop (%d x %d)",
16136  width, height);
16137 
16138  /* Allocate room for the neighborhood. */
16139  neighborData = (Datum *)palloc(winwidth * winheight * sizeof(Datum));
16140  neighborNulls = (bool *)palloc(winwidth * winheight * sizeof(bool));
16141 
16142  /* The dimensions of the neighborhood array, for creating a multi-dimensional array. */
16143  neighborDims[0] = winwidth;
16144  neighborDims[1] = winheight;
16145 
16146  /* The lower bounds for the new multi-dimensional array. */
16147  neighborLbs[0] = 1;
16148  neighborLbs[1] = 1;
16149 
16150  /* Get information about the type of item in the multi-dimensional array (float8). */
16151  get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
16152 
16153  for (x = 0 + ngbwidth; x < width - ngbwidth; x++) {
16154  for(y = 0 + ngbheight; y < height - ngbheight; y++) {
16155  /* populate an array with the pixel values in the neighborhood */
16156  nIndex = 0;
16157  nNullItems = 0;
16158  nNodataOnly = true;
16159  pixelreplace = false;
16160  if (valuereplace) {
16161  ret = rt_band_get_pixel(band, x, y, &rpix, NULL);
16162  if (ret == ES_NONE && FLT_NEQ(rpix, newnodatavalue)) {
16163  pixelreplace = true;
16164  }
16165  }
16166  for (u = x - ngbwidth; u <= x + ngbwidth; u++) {
16167  for (v = y - ngbheight; v <= y + ngbheight; v++) {
16168  ret = rt_band_get_pixel(band, u, v, &r, NULL);
16169  if (ret == ES_NONE) {
16170  if (FLT_NEQ(r, newnodatavalue)) {
16171  /* If the pixel value for this neighbor cell is not NODATA */
16172  neighborData[nIndex] = Float8GetDatum((double)r);
16173  neighborNulls[nIndex] = false;
16174  nNodataOnly = false;
16175  }
16176  else {
16177  /* If the pixel value for this neighbor cell is NODATA */
16178  if (valuereplace && pixelreplace) {
16179  /* Replace the NODATA value with the currently processing pixel. */
16180  neighborData[nIndex] = Float8GetDatum((double)rpix);
16181  neighborNulls[nIndex] = false;
16182  /* do not increment nNullItems, since the user requested that the */
16183  /* neighborhood replace NODATA values with the central pixel value */
16184  }
16185  else {
16186  neighborData[nIndex] = PointerGetDatum(NULL);
16187  neighborNulls[nIndex] = true;
16188  nNullItems++;
16189  }
16190  }
16191  }
16192  else {
16193  /* Fill this will NULL if we can't read the raster pixel. */
16194  neighborData[nIndex] = PointerGetDatum(NULL);
16195  neighborNulls[nIndex] = true;
16196  nNullItems++;
16197  }
16198  /* Next neighbor position */
16199  nIndex++;
16200  }
16201  }
16202 
16207  if (!(nNodataOnly || /* neighborhood only contains NODATA -- OR -- */
16208  (nNullSkip && nNullItems > 0) || /* neighborhood should skip any NODATA cells, and a NODATA cell was detected -- OR -- */
16209  (valuereplace && nNullItems > 0))) { /* neighborhood should replace NODATA cells with the central pixel value, and a NODATA cell was detected */
16210  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: (%dx%d), %dx%d neighborhood",
16211  x, y, winwidth, winheight);
16212 
16213  neighborDatum = construct_md_array((void *)neighborData, neighborNulls, 2, neighborDims, neighborLbs,
16214  FLOAT8OID, typlen, typbyval, typalign);
16215 
16216  /* Assign the neighbor matrix as the first argument to the user function */
16217  cbdata.arg[0] = PointerGetDatum(neighborDatum);
16218 
16219  /* Invoke the user function */
16220  tmpnewval = FunctionCallInvoke(&cbdata);
16221 
16222  /* Get the return value of the user function */
16223  if (cbdata.isnull) {
16224  newval = newnodatavalue;
16225  }
16226  else {
16227  newval = DatumGetFloat8(tmpnewval);
16228  }
16229 
16230  POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: new value = %f",
16231  newval);
16232 
16233  rt_band_set_pixel(newband, x, y, newval, NULL);
16234  }
16235 
16236  /* reset the number of null items in the neighborhood */
16237  nNullItems = 0;
16238  }
16239  }
16240 
16241 
16242  /* clean up */
16243  pfree(neighborNulls);
16244  pfree(neighborData);
16245  pfree(strFromText);
16246  pfree(txtCallbackParam);
16247 
16248  rt_raster_destroy(raster);
16249  PG_FREE_IF_COPY(pgraster, 0);
16250 
16251  /* The newrast band has been modified */
16252 
16253  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster modified, serializing it.");
16254  /* Serialize created raster */
16255 
16256  pgrtn = rt_raster_serialize(newrast);
16257  rt_raster_destroy(newrast);
16258  if (NULL == pgrtn)
16259  PG_RETURN_NULL();
16260 
16261  POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFctNgb: raster serialized");
16262  POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraFctNgb: returning raster");
16263 
16264  SET_VARSIZE(pgrtn, pgrtn->size);
16265  PG_RETURN_POINTER(pgrtn);
16266 }
static char * rtpg_strtoupper(char *str)
Definition: rt_pg.c:730
#define FLT_NEQ(x, y)
Definition: rt_api.h:2158
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_api.c:8158
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_api.c:5527
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
char * r
Definition: cu_in_wkt.c:25
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_api.c:1168
Definition: rt_api.h:184
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_api.c:1900
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_api.c:5486
tuple band
Definition: ovdump.py:57
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_api.c:8563
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_api.c:5495
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_api.c:5518
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_api.c:5668
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_api.c:2042
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_api.c:5473
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_api.c:5442
rt_pixtype
Definition: rt_api.h:172
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rt_pg.h:58
tuple nband
Definition: pixval.py:52
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_api.c:3073
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_api.c:3058
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_api.c:5455
tuple x
Definition: pixval.py:53
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_api.c:5434
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_api.c:8550
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_api.c:5464
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_api.c:1138
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
#define TRUE
Definition: dbfopen.c:170
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_api.c:2002
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_api.c:5504
tuple y
Definition: pixval.py:54
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_api.c:5426
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_api.c:5784
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function: