Skip to content

Commit

Permalink
Per #1060, fix gen_vx_mask to support the -shape_str metadata matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed May 4, 2023
1 parent 47b4848 commit fca2c7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
10 changes: 4 additions & 6 deletions src/libcode/vx_gis/dbf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,6 @@ const size_t buf_size = 65536;
unsigned char buf[buf_size];
ConcatString cs;
StringArray sa;
int j;

//
// check range
Expand Down Expand Up @@ -1019,15 +1018,14 @@ if ( n_read != bytes ) {

if ( Header.record_length < buf_size) buf[Header.record_length] = 0;

std::string s = (const char *) buf+1; // skip first byte

//
// parse each subrecord value
// parse each subrecord value, skip first byte
//

for (j=0,pos=0; j<(Header.n_subrecs); ++j) {
for (int j=0,pos=1; j<(Header.n_subrecs); ++j) {

cs = s.substr(pos, Header.subrec[j].field_length);
cs << cs_erase;
for (int k=0; k<Header.subrec[j].field_length; ++k) cs << (char) buf[pos+k];
cs.ws_strip();
sa.add(cs);

Expand Down
36 changes: 18 additions & 18 deletions src/tools/other/gen_vx_mask/gen_vx_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,14 @@ void get_shapefile_strings() {

// Get the subrecord names
rec_names = f.subrecord_names();
cout << "JHG n_rec = " << f.header()->n_records << "\n";
cout << "JHG rec_names.n() = " << rec_names.n() << "\n";
rec_names.dump(cout);

// Check each record
for(int i=0; i<f.header()->n_records; i++) {

cout << "JHG1\n";
rec_values = f.subrecord_values(i);

cout << "JHG2\n";
cout << "JHG[" << i << "] rec_values.n() = " << rec_values.n() << "\n";

// Add matching records to the list
if(is_shapefile_match(rec_names, rec_values)) {
if(is_shapefile_match(i, rec_names, rec_values)) {
mlog << Debug(4) << "Record " << i << " is a shapefile match.\n";
if(!shape_numbers.has(i)) shape_numbers.add(i);
}
Expand All @@ -589,7 +582,7 @@ void get_shapefile_records() {
if(shape_numbers.n() == 0) {
mlog << Error << "\nget_shapefile_records() -> "
<< "at least one shape number must be specified using "
<< "the \"-shapeno\" command line option!\n\n";
<< "the \"-shapeno\" or \"-shape_str\" command line options!\n\n";
exit(1);
}

Expand Down Expand Up @@ -643,35 +636,42 @@ void get_shapefile_records() {

////////////////////////////////////////////////////////////////////////

bool is_shapefile_match(const StringArray &names, const StringArray &values) {
bool is_shapefile_match(const int i_shape, const StringArray &names, const StringArray &values) {
bool match = true;
int i;
int i_match;

// Check each map entry
static std::map<string,StringArray> shape_str_map;
map<string,StringArray>::const_iterator it;
for(it = shape_str_map.begin();
it != shape_str_map.end(); ++it) {
it != shape_str_map.end(); it++) {

// The user-specified name must exist in the shapefile
if(!names.has(it->first, i)) {
if(!names.has(it->first, i_match)) {
mlog << Warning << "\nis_shapefile_match() -> "
<< "the \"-shape_str " << it->first
<< "\" name does not appear in the shapefile.\n"
<< "\" name does not appear in the shapefile. "
<< "Run the \"gis_dump_dbf\" utility to see a list "
<< "of valid names.\n\n";
match = false;
break;
}

// The corresponding value must match
if(!it->second.has(values[i])) {
mlog << Debug(4) << "Shapefile \"" << it->first << "\" value ("
<< values[i] << ") was not requested (" << write_css(it->second)
if(!it->second.reg_exp_match(values[i_match].c_str())) {
mlog << Debug(4) << "Shape number " << i_shape << " \""
<< it->first << "\" value (" << values[i_match]
<< ") does not match (" << write_css(it->second)
<< ")\n";
match = false;
break;
}
else {
mlog << Debug(3) << "Shape number " << i_shape << " \""
<< it->first << "\" value (" << values[i_match]
<< ") MATCHES (" << write_css(it->second)
<< ")\n";
}

}

return(match);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/other/gen_vx_mask/gen_vx_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static bool get_gen_vx_mask_config_str(MetNcMetDataFile *,
ConcatString &);
static void get_shapefile_strings();
static void get_shapefile_records();
static bool is_shapefile_match(const StringArray &, const StringArray &);
static bool is_shapefile_match(const int i, const StringArray &, const StringArray &);
static void apply_poly_mask(DataPlane &dp);
static void apply_poly_xy_mask(DataPlane &dp);
static void apply_shape_mask(DataPlane &dp);
Expand Down

0 comments on commit fca2c7a

Please sign in to comment.