Skip to content

Commit

Permalink
Make sure null columns in .mid files get a value on import
Browse files Browse the repository at this point in the history
  • Loading branch information
pklampros committed Jul 15, 2020
1 parent 10e1610 commit 924c1c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
37 changes: 32 additions & 5 deletions salaTest/testmapinfodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,38 @@ TEST_CASE("MapInfo MID file with empty column", "")
std::stringstream mifstream(mifdata);
std::stringstream midstream(middata);
REQUIRE(mapinfodata.import(mifstream, midstream, shapeMap) == MINFO_OK);
REQUIRE(shapeMap.getAttributeTable().getNumColumns() == 4);
REQUIRE(shapeMap.getAttributeTable().getColumn(0).getName() == "Id");
REQUIRE(shapeMap.getAttributeTable().getColumn(1).getName() == "Length_M");
REQUIRE(shapeMap.getAttributeTable().getColumn(2).getName() == "Height_M");
REQUIRE(shapeMap.getAttributeTable().getColumn(3).getName() == "Width_M");

AttributeTable& att = shapeMap.getAttributeTable();

REQUIRE(att.getNumColumns() == 4);
REQUIRE(att.getColumn(0).getName() == "Id");
REQUIRE(att.getColumn(1).getName() == "Length_M");
REQUIRE(att.getColumn(2).getName() == "Height_M");
REQUIRE(att.getColumn(3).getName() == "Width_M");

std::map<int, SalaShape> shapes = shapeMap.getAllShapes();
auto shapeRef0 = depthmapX::getMapAtIndex(shapes, 0);
auto shapeRef1 = depthmapX::getMapAtIndex(shapes, 1);
auto shapeRef2 = depthmapX::getMapAtIndex(shapes, 2);

REQUIRE(att.getNumRows() == 3);
auto &row0 = att.getRow(AttributeKey(shapeRef0->first));
auto &row1 = att.getRow(AttributeKey(shapeRef1->first));
auto &row2 = att.getRow(AttributeKey(shapeRef2->first));

REQUIRE(row0.getValue("Id") == 1);
REQUIRE(row1.getValue("Id") == 2);
REQUIRE(row2.getValue("Id") == 3);
REQUIRE(row0.getValue("Length_M") == Approx(1017.81).epsilon(EPSILON));
REQUIRE(row1.getValue("Length_M") == Approx(568.795).epsilon(EPSILON));
REQUIRE(row2.getValue("Length_M") == Approx(216.026).epsilon(EPSILON));
REQUIRE(row0.getValue("Height_M") == -1);
REQUIRE(row1.getValue("Height_M") == -1);
REQUIRE(row2.getValue("Height_M") == -1);
REQUIRE(row0.getValue("Width_M") == -1);
REQUIRE(row1.getValue("Width_M") == -1);
REQUIRE(row2.getValue("Width_M") == -1);

}

TEST_CASE("Complete proper MapInfo file", "")
Expand Down
13 changes: 10 additions & 3 deletions salalib/parsers/mapinfodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,17 @@ int MapInfoData::import(std::istream& miffile, std::istream& midfile, ShapeMap&
int length = (here < line.length()) ? here-first-1 : here-first;
std::string field = line.substr(first,length);
first = here;
if (reading == readable[nextreadable]) {
float val = stof(field);
if (length == 1 && field[0] == m_delimiter) {
// field is empty
row.setValue(colindexes[nextreadable], -1);
nextreadable++; // go to next column
} else if (reading == readable[nextreadable]) {
float val = -1;
if(!field.empty()) {
val = stof(field);
}
row.setValue(colindexes[nextreadable],val);
nextreadable++;
nextreadable++; // go to next column
}
reading++;
}
Expand Down

0 comments on commit 924c1c2

Please sign in to comment.