📄 epr_band.c
字号:
{ EPR_SDatasetRef scal_fact; const EPR_SField* field = NULL; EPR_SRecord* record = NULL; float ziff; scal_fact = epr_get_ref_struct(product_id, str); if (scal_fact.dataset_id == NULL) { return (float)(-909.909); } /*'Scaling_Factor_GADS'*/ record = epr_create_record(scal_fact.dataset_id); record = epr_read_record(scal_fact.dataset_id, 0, record); field = epr_get_field_at(record, scal_fact.field_index - 1); ziff = epr_get_field_elem_as_float(field, (uint)(scal_fact.elem_index - 1)); epr_free_record(record); return ziff;}/** * Gets the dataset_id, field_index and elem_index * * @param product_id the the product file identifier * @param str the string with the name, separator ('.') and indexes. * @return the dataset_id, field_index and elem_index (-1 if no). * <code>NULL</code> if correspondent dataset name was not found. */EPR_SDatasetRef epr_get_ref_struct(EPR_SProductId* product_id, const char* str){ EPR_SDatasetRef ref_struct; int pos = 0; char* stopstring; char* token; ref_struct.dataset_id = NULL; ref_struct.field_index = -1; ref_struct.elem_index = -1; token = epr_str_tok(str, ".", &pos); ref_struct.dataset_id = epr_get_dataset_id(product_id, token); if (ref_struct.dataset_id == NULL) { epr_free_and_null_string(&token); return ref_struct; } epr_free_and_null_string(&token); token = epr_str_tok(str, ".", &pos); if (token == NULL) { ref_struct.field_index = -1; } else { ref_struct.field_index = strtol(token, &stopstring, 10); } epr_free_and_null_string(&token); token = epr_str_tok(str, ".", &pos); if (token == NULL) { ref_struct.elem_index = -1; } else { ref_struct.elem_index = strtol(token, &stopstring, 10); } epr_free_and_null_string(&token); return ref_struct;}/** * Converts the given string into a scaling method identifier. * * @param str the string to be converted. * @return the scaling method identifier represented by the given string. * If the string is equal of '*' the value * <code>e_non_smid</code> is returned. */EPR_EScalingMethod epr_str_to_scaling_method(const char* str){ assert(str != NULL); if (epr_equal_names(str, "Linear_Scale")) return e_smid_lin; else if (epr_equal_names(str, "Log_Scale")) return e_smid_log; else return e_smid_non;}/** * Converts the given string into a sample offset identifier. * * @param str the string to be converted. * @return the sample offset identifier represented by the given string. * If the string is equal of '*' the value * <code>e_none_samoff</code> is returned. */EPR_ESampleModel epr_str_to_sample_offset(const char* str){ assert(str != NULL); if (epr_equal_names(str, "1OF2")) return e_smod_1OF2; else if (epr_equal_names(str, "2OF2")) return e_smod_2OF2; else if (epr_equal_names(str, "3TOI")) return e_smod_3TOI; else if (epr_equal_names(str, "2TOF")) return e_smod_2TOF; else return e_smod_1OF1;}/** * Creates a raster to be used for reading bitmasks. The raster returned is always of type <code>byte</code>. * * @param source_width the width (across track dimension) of the source to be read into the raster. See description of epr_create_compatible_raster. * @param source_height the height (along track dimension) of the source to be read into the raster. See description of epr_create_compatible_raster. * @param source_step_x the subsampling step across track of the source when reading into the raster. See description of epr_create_compatible_raster. * @param source_step_y the subsampling step along track of the source when reading into the raster. See description of epr_create_compatible_raster. * @return the new raster instance * or <code>NULL</code> if an error occured. */EPR_SRaster* epr_create_bitmask_raster(uint source_width, uint source_height, uint source_step_x, uint source_step_y) { return epr_create_raster(e_tid_uchar, source_width, source_height, source_step_x, source_step_y);}/** * Creates a raster for the given datatype and dimension. * * @param data_type the data type identifier * @param source_width the source's width * @param source_height the source's height * @param source_step_x the sub-sampling in X * @param source_step_y the sub-sampling in Y * @return the new raster instance * or <code>NULL</code> if an error occured. */EPR_SRaster* epr_create_raster(EPR_EDataTypeId data_type, uint source_width, uint source_height, uint source_step_x, uint source_step_y){ EPR_SRaster* raster = NULL; ulong num_elems; ulong elem_size; epr_clear_err(); if (data_type == e_tid_string || data_type == e_tid_spare || data_type == e_tid_time) { epr_set_err(e_err_illegal_data_type, "epr_create_raster: illegal data type"); return NULL; } raster = (EPR_SRaster*) calloc(1, sizeof (EPR_SRaster)); if (raster == NULL) { epr_set_err(e_err_out_of_memory, "epr_create_raster: out of memory"); return NULL; } raster->magic = EPR_MAGIC_RASTER; raster->data_type = data_type; raster->source_height = source_height; raster->source_width = source_width; raster->source_step_x = source_step_x; raster->source_step_y = source_step_y; raster->raster_width = (source_width - 1) / source_step_x + 1; raster->raster_height = (source_height - 1) / source_step_y + 1; elem_size = epr_get_data_type_size(data_type); num_elems = raster->raster_width * raster->raster_height; raster->buffer = calloc(elem_size, num_elems); if (raster->buffer == NULL) { epr_free_raster(raster); epr_set_err(e_err_out_of_memory, "epr_create_raster: out of memory"); return NULL; } return raster;}/** * Creates a compatible raster for the given band. * * @param dataset_id the dataset identifier, must not be <code>NULL</code> * @return the new raster instance * or <code>NULL</code> if an error occured. */EPR_SRaster* epr_create_compatible_raster(EPR_SBandId* band_id, uint source_width, uint source_height, uint source_step_x, uint source_step_y){ epr_clear_err(); if (band_id == NULL) { epr_set_err(e_err_invalid_band, "epr_create_raster: band_id must not be NULL"); return NULL; } return epr_create_raster(band_id->data_type, source_width, source_height, source_step_x, source_step_y); }void epr_free_raster(EPR_SRaster* raster){ epr_clear_err(); if (raster == NULL) return; raster->data_type = e_tid_unknown; raster->raster_height = 0; raster->raster_width = 0; raster->source_height = 0; raster->source_width = 0; raster->source_step_x = 0; raster->source_step_y = 0; if (raster->buffer != NULL) { free(raster->buffer); raster->buffer = NULL; } free(raster);}int epr_read_band_raster(EPR_SBandId* band_id, int offset_x, int offset_y, EPR_SRaster* raster/*, EPR_SRaster** bitmask_raster*/){ EPR_SProductId* product_id = NULL; EPR_SDatasetId* dataset_id = NULL; char* rec_type; epr_clear_err(); if (band_id->data_type != raster->data_type) { epr_set_err(e_err_illegal_data_type, "epr_read_band_raster: illegal raster data type"); return epr_get_last_err_code(); } if (raster->buffer == NULL) { epr_set_err(e_err_invalid_band, "epr_read_band_raster: band_id must not be NULL"); return epr_get_last_err_code(); } if (band_id == NULL) { epr_set_err(e_err_illegal_arg, "epr_read_band_raster: raster->buffer must not be NULL"); return epr_get_last_err_code(); } if ((offset_x<0) || (offset_y<0) || (raster->raster_width<0) || (raster->raster_height<0) || (raster->source_step_x<0) || (raster->source_step_y<0)) { epr_set_err(e_err_invalid_value, "epr_read_band_raster: all digit parameter must be positive"); return epr_get_last_err_code(); } if ((raster->source_step_x>raster->raster_width) || (raster->source_step_y>raster->raster_height)) { epr_set_err(e_err_invalid_value, "epr_read_band_raster: too small raster sizes or large steps"); return epr_get_last_err_code(); } product_id = band_id->product_id; dataset_id = band_id->dataset_ref.dataset_id; rec_type = dataset_id->dsd->ds_type; if (strcmp(rec_type, "M") == 0) { if (epr_read_band_measurement_data(band_id, offset_x, offset_y, raster) != 0) { epr_set_err(e_err_file_read_error, "epr_read_band_raster: unsuccessfully reading band measurement data"); return epr_get_last_err_code(); } if (band_id->bm_expr != NULL) { EPR_SRaster* bm_raster; int rd_bm; bm_raster = epr_create_raster(e_tid_uchar, /*was char*/ raster->source_width, raster->source_height, raster->source_step_x, raster->source_step_y); rd_bm = epr_read_bitmask_raster(product_id, band_id->bm_expr, offset_x, offset_y, bm_raster); epr_zero_invalid_pixels(raster, bm_raster); epr_free_raster(bm_raster); } } else if (strcmp(rec_type, "A") == 0) { if (epr_read_band_annotation_data (band_id, offset_x, offset_y, raster) == 1) { epr_set_err(e_err_file_read_error, "epr_read_band_raster: unsuccessfully reading band annotation data"); return epr_get_last_err_code(); } } else { epr_set_err(e_err_invalid_value, "epr_read_band_raster: illegat DS-TYPE; 'A' or'M' will be accepted"); return epr_get_last_err_code(); } return e_err_none;}/** * Reads the measurement data and converts its into physical values. * * @param band_id the information about properties and quantities of ENVISAT data. * @param offset_x X-coordinate in pixel co-ordinates (zero-based) of the upper right corner raster to search * @param offset_y Y-coordinate in pixel co-ordinates (zero-based) of the upper right corner raster to search * @param raster the instance to the buffer information was used * * @return zero for success, an error code otherwise */int epr_read_band_measurement_data(EPR_SBandId* band_id, int offset_x, int offset_y, EPR_SRaster* raster){ EPR_SProductId* product_id = NULL; const EPR_SField* field = NULL; EPR_SFieldInfo* field_info = NULL; EPR_SDatasetId* dataset_id = NULL; EPR_SRecord* record = NULL; EPR_SRecord* sph_record = NULL; EPR_EDataTypeId band_datatype, datatype_id;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -