Home    |    Concepts   |   API   |   Samples
Concepts > Rasters > Basic Principles
Image Statistics

ArcSDE stores image statistics on existing raster bands according to the supplied statistical function parameters. The statistics computed include the minimum and maximum pixel values as well as the mean and standard deviation.

For the C API, the basic workflow to calculate raster band statistics is to retrieve the raster band properties into a raster band info structure, update the raster band statistics properties, then alter the raster band, passing the updated raster band info structure as an argument.

Statistics are calculated according to the statistical bin function specified as well as the optional statistical bin table. The bin functions include:

  • SE_BIN_FUNCTION_NONE
  • SE_BIN_FUNCTION_AUTO
  • SE_BIN_FUNCTION_DIRECT
  • SE_BIN_FUNCTION_LINEAR
  • SE_BIN_FUNCTION_LOGARITHM
  • SE_BIN_FUNCTION_EXPLICIT

Set the bin function type to SE_BIN_FUNCTION_NONE to remove the current bin function and delete any existing raster statistics when the raster band is altered.

Setting the bin function type to SE_BIN_FUNCTION_AUTO allows ArcSDE to automatically select the optimum bin function for the raster’s pixel type. To use the SE_BIN_FUNCTION_AUTO bin function type, the number of bins must be set to 0 and the bin table must be set to NULL.

If the bin function type is set to SE_BIN_FUNCTION_DIRECT, the number of bins must be set to 0. In this case, ArcSDE calculates the actual number of bins based on the image’s pixel values.

The bin table is used when the bin function type is set to SE_BIN_FUNCTION_EXPLICIT. The number of bins must always be one greater than the number of bin table elements.

The boundaries of the lowest bin are the minimum pixel value and the first element of the bin table, while the highest bin is bounded by the last element of the bin table and the maximum pixel value.

Unless you are specifically creating band statistics to support an image analysis program, you should use the SE_BIN_FUNCTION_AUTO bin function.

For a minimal loss of accuracy and a significant time savings, image statistics can be computed from a higher level of a pyramid.

 

void alter_rasterband(SE_CONNECTION connection, CHAR *table, LONG raster_id)
{

LONG rc,
band,
number_of_bands;
SE_RASBANDINFO *rasbandinfo_list;
SE_BIN_FUNCTION_TYPE bin_function_type;
CHAR bandname[24];


/* fetch the raster bands for the raster */

get_rasterbands(connection,
table,
raster_id,
&rasbandinfo_list,
&number_of_bands);

for(band=0; band<number_of_bands; band++) {

bin_function_type = SE_BIN_FUNCTION_AUTO;

/* Set the bin function to automatic complete with bin table. */

rc = SE_rasbandinfo_set_bin_function ( rasbandinfo_list[band],
bin_function_type,
0,
NULL);
check_error (rc, NULL, NULL, "SE_rasbandinfo_set_bin_function");


/* Add the statistics to the rasterband. */

rc = SE_rasterband_alter (connection, rasbandinfo_list[band]);
QA_returncode_check (connection, NULL, ret, "SE_rasterband_alter");

}

for(band=0; band<number_of_bands; band++)
SE_rasbandinfo_free(rasbandinfo_list[band]);

free(rasbandinfo_list);

return;

} /* alter_rasterband */




void get_rasterbands (SE_CONNECTION connection,
CHAR *table,
LONG raster_id,
SE_RASBANDINFO **rasterbands,
LONG *number_of_bands)
{

SE_RASTERATTR raster_attrib;
SE_STREAM stream;
SE_QUERYINFO queryinfo;
CHAR **tables,
**columns,
whereclause[32],
raster_column[] = "RASTER";
LONG rc;
SHORT raster_ind,i;
SE_RASBANDINFO *t_rasbandinfo;

/* Initialize SE_RASATTR structure */

rc = SE_rasterattr_create(&raster_attrib,FALSE);
check_error (rc, NULL, NULL, "SE_rasterattr_create");

rc = SE_stream_create(connection,&stream);
check_error (rc, connection, NULL, "SE_stream_create");

/* Create the queryinfo structure */

rc = SE_queryinfo_create (&queryinfo);
check_error (rc, connection, NULL, "SE_stream_create");

/* Add the raster table to the query info structure */

tables = (CHAR **)malloc(sizeof(CHAR*));
tables[0] = malloc((strlen(table) +1) * sizeof(CHAR));
strcpy(tables[0],table);

rc = SE_queryinfo_set_tables(queryinfo,1,(const CHAR **)tables,NULL);
check_error (rc, connection, NULL, "SE_queryinfo_set_table");

free(tables);

/* Add the raster table's columns to the query info structure */

columns = (CHAR **)malloc(sizeof(CHAR*));
columns[0] = malloc((strlen(raster_column) +1) * sizeof(CHAR));

strcpy(columns[0],raster_column);

rc = SE_queryinfo_set_columns (queryinfo,1,(const CHAR **)columns);
check_error (rc, connection, NULL, "SE_queryinfo_set_table");

free(columns);

sprintf(whereclause,"objectid = %d",raster_id);

rc = SE_queryinfo_set_where_clause(queryinfo,whereclause);
check_error (rc, NULL, NULL, "SE_queryinfo_set_whereclause");

/* Add the queryinfo structure to the stream */

rc = SE_stream_query_with_info (stream, queryinfo);
check_error (rc, NULL, stream, "SE_stream_query_with_info");

/* Free the queryinfo, we are done with it. */

SE_queryinfo_free(queryinfo);

/* Bind the output of the stream the raster column */

rc = SE_stream_bind_output_column (stream, 1, raster_attrib, &raster_ind);
check_error (rc, NULL, stream, "SE_stream_bind_output_column");

/* Execute the query */

rc = SE_stream_execute (stream);
check_error (rc, NULL, stream, "SE_stream_execute");

while (SE_SUCCESS == rc)
{
/* Fetch each record of the business table */

ret = SE_stream_fetch (stream);

if (SE_FINISHED != rc)
{
check_error (rc, NULL, stream, "SE_stream_fetch");

if(raster_ind==SE_IS_NOT_NULL_VALUE) {

rc = SE_rasterattr_get_rasterband_info_list ( raster_attrib,
&t_rasbandinfo,
number_of_bands);
check_error (rc, NULL, NULL,
"SE_rasterattr_get_rasterband_info_list");
}
}
}

*rasterbands = (SE_RASBANDINFO *)malloc (sizeof(SE_RASBANDINFO)*(*number_of_bands));

for(i=0;i<(*number_of_bands);i++) {

rc = SE_rasbandinfo_create(&((*rasterbands)[i]));

rc = SE_rasbandinfo_duplicate(t_rasbandinfo[i],(*rasterbands)[i]);
check_error (rc, NULL, stream, "SE_rasterbandinfo_duplicate");

}

SE_rasterattr_free(raster_attrib);
SE_queryinfo_free(queryinfo);

ret = SE_stream_free(stream);
check_error (rc, NULL, NULL, "SE_stream_free");

return;

}

 
feedback | privacy | legal