Skip to content

Commit

Permalink
Catch unparsable point coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
kenohori committed Nov 11, 2016
1 parent 66f2a4f commit 92c66c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions azul.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "src/Azul-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
Expand Down
2 changes: 2 additions & 0 deletions src/CityGMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void CityGMLParser::parse(const char *filePath) {
pugi::xml_document doc;
doc.load_file(filePath);

std::cout << "Loaded XML file" << std::endl;

// With single traversal
ObjectsWalker objectsWalker;
doc.traverse(objectsWalker);
Expand Down
11 changes: 8 additions & 3 deletions src/CityGMLParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ struct PointsWalker: pugi::xml_tree_walker {
iss >> substring;
if (substring.length() > 0) {
if (currentCoordinate == 0) points.push_back(CityGMLPoint());
points.back().coordinates[currentCoordinate] = std::stof(substring);
currentCoordinate = (currentCoordinate+1)%3;
try {
points.back().coordinates[currentCoordinate] = std::stof(substring);
} catch (const std::invalid_argument& ia) {
std::cout << "Invalid point: " << substring << ". Skipping..." << std::endl;
points.clear();
return true;
} currentCoordinate = (currentCoordinate+1)%3;
}
} while (iss);
if (currentCoordinate != 0) {
std::cout << "Wrong number of coordinates: not divisible by 3" << std::endl;
points.pop_back();
points.clear();
} //std::cout << "Created " << points.size() << " points" << std::endl;
} return true;
}
Expand Down

0 comments on commit 92c66c2

Please sign in to comment.