PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_mapAlgebraExpr()

Datum RASTER_mapAlgebraExpr ( 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 a nodataval is provided, use it for newinitialvalue. Then, we can initialize the raster with this value and skip the computation of nodata values one by one in the main computing loop

Optimization: If the raster is only filled with nodata values return right now a raster filled with the newinitialvalue TODO: Call rt_band_check_isnodata instead?

Optimization: If expression resume to 'RAST' and hasnodataval is zero, we can just return the band from the original raster

Optimization: If expression resume to a constant (it does not contain [rast)

Compute the new value, set it and we will return after creating the new raster

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

Optimization: If expression is NULL, or all the pixels could be set in one step, return the initialized raster now

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

Definition at line 4577 of file rtpg_mapalgebra.c.

4578{
4579 rt_pgraster *pgraster = NULL;
4580 rt_pgraster *pgrtn = NULL;
4581 rt_raster raster = NULL;
4582 rt_raster newrast = NULL;
4583 rt_band band = NULL;
4584 rt_band newband = NULL;
4585 int x, y, nband, width, height;
4586 double r;
4587 double newnodatavalue = 0.0;
4588 double newinitialvalue = 0.0;
4589 double newval = 0.0;
4590 char *newexpr = NULL;
4591 char *initexpr = NULL;
4592 char *expression = NULL;
4593 int hasnodataval = 0;
4594 double nodataval = 0.;
4595 rt_pixtype newpixeltype;
4596 int skipcomputation = 0;
4597 int len = 0;
4598 const int argkwcount = 3;
4599 enum KEYWORDS { kVAL=0, kX=1, kY=2 };
4600 char *argkw[] = {"[rast]", "[rast.x]", "[rast.y]"};
4601 Oid argkwtypes[] = { FLOAT8OID, INT4OID, INT4OID };
4602 int argcount = 0;
4603 Oid argtype[] = { FLOAT8OID, INT4OID, INT4OID };
4604 uint8_t argpos[3] = {0};
4605 char place[12];
4606 int idx = 0;
4607 int ret = -1;
4608 TupleDesc tupdesc;
4609 SPIPlanPtr spi_plan = NULL;
4610 SPITupleTable * tuptable = NULL;
4611 HeapTuple tuple;
4612 char * strFromText = NULL;
4613 Datum *values = NULL;
4614 Datum datum = (Datum)NULL;
4615 char *nulls = NULL;
4616 bool isnull = FALSE;
4617 int i = 0;
4618 int j = 0;
4619
4620 POSTGIS_RT_DEBUG(2, "RASTER_mapAlgebraExpr: Starting...");
4621
4622 /* Check raster */
4623 if (PG_ARGISNULL(0)) {
4624 elog(NOTICE, "Raster is NULL. Returning NULL");
4625 PG_RETURN_NULL();
4626 }
4627
4628
4629 /* Deserialize raster */
4630 pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4631 raster = rt_raster_deserialize(pgraster, FALSE);
4632 if (NULL == raster) {
4633 PG_FREE_IF_COPY(pgraster, 0);
4634 elog(ERROR, "RASTER_mapAlgebraExpr: Could not deserialize raster");
4635 PG_RETURN_NULL();
4636 }
4637
4638 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Getting arguments...");
4639
4640 if (PG_ARGISNULL(1))
4641 nband = 1;
4642 else
4643 nband = PG_GETARG_INT32(1);
4644
4645 if (nband < 1)
4646 nband = 1;
4647
4648
4649 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Creating new empty raster...");
4650
4655 width = rt_raster_get_width(raster);
4656 height = rt_raster_get_height(raster);
4657
4658 newrast = rt_raster_new(width, height);
4659
4660 if ( NULL == newrast ) {
4661 PG_FREE_IF_COPY(pgraster, 0);
4662 elog(ERROR, "RASTER_mapAlgebraExpr: Could not create a new raster");
4663 PG_RETURN_NULL();
4664 }
4665
4666 rt_raster_set_scale(newrast,
4667 rt_raster_get_x_scale(raster),
4668 rt_raster_get_y_scale(raster));
4669
4670 rt_raster_set_offsets(newrast,
4671 rt_raster_get_x_offset(raster),
4672 rt_raster_get_y_offset(raster));
4673
4674 rt_raster_set_skews(newrast,
4675 rt_raster_get_x_skew(raster),
4676 rt_raster_get_y_skew(raster));
4677
4678 rt_raster_set_srid(newrast, rt_raster_get_srid(raster));
4679
4680
4685 if (rt_raster_is_empty(newrast))
4686 {
4687 elog(NOTICE, "Raster is empty. Returning an empty raster");
4688 rt_raster_destroy(raster);
4689 PG_FREE_IF_COPY(pgraster, 0);
4690
4691 pgrtn = rt_raster_serialize(newrast);
4692 rt_raster_destroy(newrast);
4693 if (NULL == pgrtn) {
4694
4695 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4696 PG_RETURN_NULL();
4697 }
4698
4699 SET_VARSIZE(pgrtn, pgrtn->size);
4700 PG_RETURN_POINTER(pgrtn);
4701 }
4702
4703
4704 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Getting raster band %d...", nband);
4705
4710 if (!rt_raster_has_band(raster, nband - 1)) {
4711 elog(NOTICE, "Raster does not have the required band. Returning a raster "
4712 "without a band");
4713 rt_raster_destroy(raster);
4714 PG_FREE_IF_COPY(pgraster, 0);
4715
4716 pgrtn = rt_raster_serialize(newrast);
4717 rt_raster_destroy(newrast);
4718 if (NULL == pgrtn) {
4719 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4720 PG_RETURN_NULL();
4721 }
4722
4723 SET_VARSIZE(pgrtn, pgrtn->size);
4724 PG_RETURN_POINTER(pgrtn);
4725 }
4726
4727 /* Get the raster band */
4728 band = rt_raster_get_band(raster, nband - 1);
4729 if ( NULL == band ) {
4730 elog(NOTICE, "Could not get the required band. Returning a raster "
4731 "without a band");
4732 rt_raster_destroy(raster);
4733 PG_FREE_IF_COPY(pgraster, 0);
4734
4735 pgrtn = rt_raster_serialize(newrast);
4736 rt_raster_destroy(newrast);
4737 if (NULL == pgrtn) {
4738 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4739 PG_RETURN_NULL();
4740 }
4741
4742 SET_VARSIZE(pgrtn, pgrtn->size);
4743 PG_RETURN_POINTER(pgrtn);
4744 }
4745
4746 /*
4747 * Get NODATA value
4748 */
4749 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Getting NODATA value for band...");
4750
4751 if (rt_band_get_hasnodata_flag(band)) {
4752 rt_band_get_nodata(band, &newnodatavalue);
4753 }
4754
4755 else {
4756 newnodatavalue = rt_band_get_min_value(band);
4757 }
4758
4759 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: NODATA value for band: = %f",
4760 newnodatavalue);
4761
4767 newinitialvalue = newnodatavalue;
4768
4772 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Setting pixeltype...");
4773
4774 if (PG_ARGISNULL(2)) {
4775 newpixeltype = rt_band_get_pixtype(band);
4776 }
4777
4778 else {
4779 strFromText = text_to_cstring(PG_GETARG_TEXT_P(2));
4780 newpixeltype = rt_pixtype_index_from_name(strFromText);
4781 pfree(strFromText);
4782 if (newpixeltype == PT_END)
4783 newpixeltype = rt_band_get_pixtype(band);
4784 }
4785
4786 if (newpixeltype == PT_END) {
4787 PG_FREE_IF_COPY(pgraster, 0);
4788 elog(ERROR, "RASTER_mapAlgebraExpr: Invalid pixeltype");
4789 PG_RETURN_NULL();
4790 }
4791
4792 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Pixeltype set to %s",
4793 rt_pixtype_name(newpixeltype));
4794
4795
4796 /* Construct expression for raster values */
4797 if (!PG_ARGISNULL(3)) {
4798 expression = text_to_cstring(PG_GETARG_TEXT_P(3));
4799 len = strlen("SELECT (") + strlen(expression) + strlen(")::double precision");
4800 initexpr = (char *)palloc(len + 1);
4801
4802 memcpy(initexpr, "SELECT (", strlen("SELECT ("));
4803 memcpy(initexpr + strlen("SELECT ("), expression, strlen(expression));
4804 memcpy(initexpr + strlen("SELECT (") + strlen(expression), ")::double precision", strlen(")::double precision"));
4805 initexpr[len] = '\0';
4806
4807 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Expression is %s", initexpr);
4808
4809 /* We don't need this memory */
4810 /*
4811 pfree(expression);
4812 expression = NULL;
4813 */
4814 }
4815
4816
4817
4823 if (!PG_ARGISNULL(4)) {
4824 hasnodataval = 1;
4825 nodataval = PG_GETARG_FLOAT8(4);
4826 newinitialvalue = nodataval;
4827
4828 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: new initial value = %f",
4829 newinitialvalue);
4830 }
4831 else
4832 hasnodataval = 0;
4833
4834
4835
4841 if (rt_band_get_isnodata_flag(band)) {
4842
4843 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: Band is a nodata band, returning "
4844 "a raster filled with nodata");
4845
4846 ret = rt_raster_generate_new_band(newrast, newpixeltype,
4847 newinitialvalue, TRUE, newnodatavalue, 0);
4848
4849 /* Free memory */
4850 if (initexpr)
4851 pfree(initexpr);
4852 rt_raster_destroy(raster);
4853 PG_FREE_IF_COPY(pgraster, 0);
4854
4855 /* Serialize created raster */
4856 pgrtn = rt_raster_serialize(newrast);
4857 rt_raster_destroy(newrast);
4858 if (NULL == pgrtn) {
4859 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4860 PG_RETURN_NULL();
4861 }
4862
4863 SET_VARSIZE(pgrtn, pgrtn->size);
4864 PG_RETURN_POINTER(pgrtn);
4865 }
4866
4867
4872 if (initexpr != NULL && ( !strcmp(initexpr, "SELECT [rast]") || !strcmp(initexpr, "SELECT [rast.val]") ) && !hasnodataval) {
4873
4874 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Expression resumes to RAST. "
4875 "Returning raster with band %d from original raster", nband);
4876
4877 POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster has %d bands",
4878 rt_raster_get_num_bands(newrast));
4879
4880 rt_raster_copy_band(newrast, raster, nband - 1, 0);
4881
4882 POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
4883 rt_raster_get_num_bands(newrast));
4884
4885 pfree(initexpr);
4886 rt_raster_destroy(raster);
4887 PG_FREE_IF_COPY(pgraster, 0);
4888
4889 /* Serialize created raster */
4890 pgrtn = rt_raster_serialize(newrast);
4891 rt_raster_destroy(newrast);
4892 if (NULL == pgrtn) {
4893 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4894 PG_RETURN_NULL();
4895 }
4896
4897 SET_VARSIZE(pgrtn, pgrtn->size);
4898 PG_RETURN_POINTER(pgrtn);
4899 }
4900
4905 if (initexpr != NULL && strstr(initexpr, "[rast") == NULL) {
4906 ret = SPI_connect();
4907 if (ret != SPI_OK_CONNECT) {
4908 PG_FREE_IF_COPY(pgraster, 0);
4909 elog(ERROR, "RASTER_mapAlgebraExpr: Could not connect to the SPI manager");
4910 PG_RETURN_NULL();
4911 };
4912
4913 /* Execute the expression into newval */
4914 ret = SPI_execute(initexpr, FALSE, 0);
4915
4916 if (ret != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
4917
4918 /* Free memory allocated out of the current context */
4919 if (SPI_tuptable)
4920 SPI_freetuptable(tuptable);
4921 PG_FREE_IF_COPY(pgraster, 0);
4922
4923 SPI_finish();
4924 elog(ERROR, "RASTER_mapAlgebraExpr: Invalid construction for expression");
4925 PG_RETURN_NULL();
4926 }
4927
4928 tupdesc = SPI_tuptable->tupdesc;
4929 tuptable = SPI_tuptable;
4930
4931 tuple = tuptable->vals[0];
4932 newexpr = SPI_getvalue(tuple, tupdesc, 1);
4933 if ( ! newexpr ) {
4934 POSTGIS_RT_DEBUG(3, "Constant expression evaluated to NULL, keeping initvalue");
4935 newval = newinitialvalue;
4936 } else {
4937 newval = atof(newexpr);
4938 }
4939
4940 SPI_freetuptable(tuptable);
4941
4942 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: New raster value = %f",
4943 newval);
4944
4945 SPI_finish();
4946
4947 skipcomputation = 1;
4948
4953 if (!hasnodataval) {
4954 newinitialvalue = newval;
4955 skipcomputation = 2;
4956 }
4957
4958 /* Return the new raster as it will be before computing pixel by pixel */
4959 else if (FLT_NEQ(newval, newinitialvalue)) {
4960 skipcomputation = 2;
4961 }
4962 }
4963
4968 ret = rt_raster_generate_new_band(newrast, newpixeltype,
4969 newinitialvalue, TRUE, newnodatavalue, 0);
4970
4975 /*if (initexpr == NULL || skipcomputation == 2) {*/
4976 if (expression == NULL || skipcomputation == 2) {
4977
4978 /* Free memory */
4979 if (initexpr)
4980 pfree(initexpr);
4981 rt_raster_destroy(raster);
4982 PG_FREE_IF_COPY(pgraster, 0);
4983
4984 /* Serialize created raster */
4985 pgrtn = rt_raster_serialize(newrast);
4986 rt_raster_destroy(newrast);
4987 if (NULL == pgrtn) {
4988 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
4989 PG_RETURN_NULL();
4990 }
4991
4992 SET_VARSIZE(pgrtn, pgrtn->size);
4993 PG_RETURN_POINTER(pgrtn);
4994 }
4995
4996 RASTER_DEBUG(3, "RASTER_mapAlgebraExpr: Creating new raster band...");
4997
4998 /* Get the new raster band */
4999 newband = rt_raster_get_band(newrast, 0);
5000 if ( NULL == newband ) {
5001 elog(NOTICE, "Could not modify band for new raster. Returning new "
5002 "raster with the original band");
5003
5004 if (initexpr)
5005 pfree(initexpr);
5006 rt_raster_destroy(raster);
5007 PG_FREE_IF_COPY(pgraster, 0);
5008
5009 /* Serialize created raster */
5010 pgrtn = rt_raster_serialize(newrast);
5011 rt_raster_destroy(newrast);
5012 if (NULL == pgrtn) {
5013 elog(ERROR, "RASTER_mapAlgebraExpr: Could not serialize raster");
5014 PG_RETURN_NULL();
5015 }
5016
5017 SET_VARSIZE(pgrtn, pgrtn->size);
5018 PG_RETURN_POINTER(pgrtn);
5019 }
5020
5021 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: Main computing loop (%d x %d)",
5022 width, height);
5023
5024 if (initexpr != NULL) {
5025 /* Convert [rast.val] to [rast] */
5026 newexpr = rtpg_strreplace(initexpr, "[rast.val]", "[rast]", NULL);
5027 pfree(initexpr); initexpr=newexpr;
5028
5029 sprintf(place,"$1");
5030 for (i = 0, j = 1; i < argkwcount; i++) {
5031 len = 0;
5032 newexpr = rtpg_strreplace(initexpr, argkw[i], place, &len);
5033 pfree(initexpr); initexpr=newexpr;
5034 if (len > 0) {
5035 argtype[argcount] = argkwtypes[i];
5036 argcount++;
5037 argpos[i] = j++;
5038
5039 sprintf(place, "$%d", j);
5040 }
5041 else {
5042 argpos[i] = 0;
5043 }
5044 }
5045
5046 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: initexpr = %s", initexpr);
5047
5048 /* define values */
5049 values = (Datum *) palloc(sizeof(Datum) * argcount);
5050 if (values == NULL) {
5051
5052 SPI_finish();
5053
5054 rt_raster_destroy(raster);
5055 PG_FREE_IF_COPY(pgraster, 0);
5056 rt_raster_destroy(newrast);
5057
5058 elog(ERROR, "RASTER_mapAlgebraExpr: Could not allocate memory for value parameters of prepared statement");
5059 PG_RETURN_NULL();
5060 }
5061
5062 /* define nulls */
5063 nulls = (char *)palloc(argcount);
5064 if (nulls == NULL) {
5065
5066 SPI_finish();
5067
5068 rt_raster_destroy(raster);
5069 PG_FREE_IF_COPY(pgraster, 0);
5070 rt_raster_destroy(newrast);
5071
5072 elog(ERROR, "RASTER_mapAlgebraExpr: Could not allocate memory for null parameters of prepared statement");
5073 PG_RETURN_NULL();
5074 }
5075
5076 /* Connect to SPI and prepare the expression */
5077 ret = SPI_connect();
5078 if (ret != SPI_OK_CONNECT) {
5079
5080 if (initexpr)
5081 pfree(initexpr);
5082 rt_raster_destroy(raster);
5083 PG_FREE_IF_COPY(pgraster, 0);
5084 rt_raster_destroy(newrast);
5085
5086 elog(ERROR, "RASTER_mapAlgebraExpr: Could not connect to the SPI manager");
5087 PG_RETURN_NULL();
5088 };
5089
5090 /* Type of all arguments is FLOAT8OID */
5091 spi_plan = SPI_prepare(initexpr, argcount, argtype);
5092
5093 if (spi_plan == NULL) {
5094
5095 rt_raster_destroy(raster);
5096 PG_FREE_IF_COPY(pgraster, 0);
5097 rt_raster_destroy(newrast);
5098
5099 SPI_finish();
5100
5101 pfree(initexpr);
5102
5103 elog(ERROR, "RASTER_mapAlgebraExpr: Could not prepare expression");
5104 PG_RETURN_NULL();
5105 }
5106 }
5107
5108 for (x = 0; x < width; x++) {
5109 for(y = 0; y < height; y++) {
5110 ret = rt_band_get_pixel(band, x, y, &r, NULL);
5111
5116 if (ret == ES_NONE && FLT_NEQ(r, newnodatavalue)) {
5117 if (skipcomputation == 0) {
5118 if (initexpr != NULL) {
5119 /* Reset the null arg flags. */
5120 memset(nulls, 'n', argcount);
5121
5122 for (i = 0; i < argkwcount; i++) {
5123 idx = argpos[i];
5124 if (idx < 1) continue;
5125 idx--;
5126
5127 if (i == kX ) {
5128 /* x is 0 based index, but SQL expects 1 based index */
5129 values[idx] = Int32GetDatum(x+1);
5130 nulls[idx] = ' ';
5131 }
5132 else if (i == kY) {
5133 /* y is 0 based index, but SQL expects 1 based index */
5134 values[idx] = Int32GetDatum(y+1);
5135 nulls[idx] = ' ';
5136 }
5137 else if (i == kVAL ) {
5138 values[idx] = Float8GetDatum(r);
5139 nulls[idx] = ' ';
5140 }
5141
5142 }
5143
5144 ret = SPI_execute_plan(spi_plan, values, nulls, FALSE, 0);
5145 if (ret != SPI_OK_SELECT || SPI_tuptable == NULL ||
5146 SPI_processed != 1) {
5147 if (SPI_tuptable)
5148 SPI_freetuptable(tuptable);
5149
5150 SPI_freeplan(spi_plan);
5151 SPI_finish();
5152
5153 pfree(values);
5154 pfree(nulls);
5155 pfree(initexpr);
5156
5157 rt_raster_destroy(raster);
5158 PG_FREE_IF_COPY(pgraster, 0);
5159 rt_raster_destroy(newrast);
5160
5161 elog(ERROR, "RASTER_mapAlgebraExpr: Error executing prepared plan");
5162
5163 PG_RETURN_NULL();
5164 }
5165
5166 tupdesc = SPI_tuptable->tupdesc;
5167 tuptable = SPI_tuptable;
5168
5169 tuple = tuptable->vals[0];
5170 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
5171 if ( SPI_result == SPI_ERROR_NOATTRIBUTE ) {
5172 POSTGIS_RT_DEBUGF(3, "Expression for pixel %d,%d (value %g) errored, skip setting", x+1,y+1,r);
5173 newval = newinitialvalue;
5174 }
5175 else if ( isnull ) {
5176 POSTGIS_RT_DEBUGF(3, "Expression for pixel %d,%d (value %g) evaluated to NULL, skip setting", x+1,y+1,r);
5177 newval = newinitialvalue;
5178 } else {
5179 newval = DatumGetFloat8(datum);
5180 }
5181
5182 SPI_freetuptable(tuptable);
5183 }
5184
5185 else
5186 newval = newinitialvalue;
5187
5188 POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: new value = %f",
5189 newval);
5190 }
5191
5192
5193 rt_band_set_pixel(newband, x, y, newval, NULL);
5194 }
5195
5196 }
5197 }
5198
5199 if (initexpr != NULL) {
5200 SPI_freeplan(spi_plan);
5201 SPI_finish();
5202
5203 pfree(values);
5204 pfree(nulls);
5205 pfree(initexpr);
5206 }
5207 else {
5208 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: no SPI cleanup");
5209 }
5210
5211
5212 /* The newrast band has been modified */
5213
5214 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster modified, serializing it.");
5215 /* Serialize created raster */
5216
5217 rt_raster_destroy(raster);
5218 PG_FREE_IF_COPY(pgraster, 0);
5219
5220 pgrtn = rt_raster_serialize(newrast);
5221 rt_raster_destroy(newrast);
5222 if (NULL == pgrtn)
5223 PG_RETURN_NULL();
5224
5225 SET_VARSIZE(pgrtn, pgrtn->size);
5226
5227 POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraExpr: raster serialized");
5228
5229
5230 POSTGIS_RT_DEBUG(4, "RASTER_mapAlgebraExpr: returning raster");
5231
5232
5233 PG_RETURN_POINTER(pgrtn);
5234}
char * r
Definition cu_in_wkt.c:24
#define TRUE
Definition dbfopen.c:73
#define FALSE
Definition dbfopen.c:72
#define FLT_NEQ(x, y)
Definition librtcore.h:2435
#define RASTER_DEBUG(level, msg)
Definition librtcore.h:304
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition rt_raster.c:360
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition rt_raster.c:185
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition rt_raster.c:217
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:489
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition rt_raster.c:141
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition rt_band.c:833
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition rt_pixel.c:82
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition rt_raster.c:86
rt_pixtype
Definition librtcore.h:188
@ PT_END
Definition librtcore.h:201
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition rt_raster.c:172
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition rt_band.c:873
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:52
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:1253
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition rt_raster.c:154
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition rt_pixel.c:114
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:2082
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition rt_band.c:1140
@ ES_NONE
Definition librtcore.h:182
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:376
uint16_t rt_raster_get_height(rt_raster raster)
Definition rt_raster.c:133
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition rt_raster.c:367
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition rt_band.c:790
uint16_t rt_raster_get_width(rt_raster raster)
Definition rt_raster.c:125
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
Definition rt_raster.c:1276
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition rt_raster.c:163
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition rt_raster.c:194
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:203
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition rt_raster.c:226
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition rt_raster.c:1240
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition rt_raster.c:385
nband
Definition pixval.py:56
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition rtrowdump.py:125
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
#define POSTGIS_RT_DEBUG(level, msg)
Definition rtpostgis.h:65
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition rtpostgis.h:69
Struct definitions.
Definition librtcore.h:2452

References ES_NONE, FALSE, FLT_NEQ, POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, PT_END, r, RASTER_DEBUG, 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_copy_band(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_generate_new_band(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_num_bands(), 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_strreplace(), rt_raster_serialized_t::size, and TRUE.

Here is the call graph for this function: