Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary conditions, check for empty geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed May 6, 2024
1 parent 85fb8e7 commit 33fd7c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
33 changes: 16 additions & 17 deletions src/osm/osmchange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,67 +348,66 @@ OsmChangeFile::buildRelationGeometry(osmobjects::OsmRelation &relation) {
});
}

// Converts all geometries to WKT strings

std::string geometry = "";
int i = 0;

// Inner parts
for (auto pit = parts_outer.begin(); pit != parts_outer.end(); ++pit) {
std::stringstream ss;
std::string geometry_str;
++i;
if (relation.isMultiPolygon()) {
if (bg::num_points(pit->polygon.outer()) > 0) {
if (bg::num_points(pit->polygon.outer()) > 1) {
ss << std::setprecision(12) << bg::wkt(pit->polygon);
geometry_str = ss.str();
// Erase "POLYGON("
geometry_str.erase(0,8);
geometry_str.erase(geometry_str.size() - 1);
if (geometry_str.size() > 0) {
geometry += geometry_str + ",";
}
geometry += geometry_str + ",";
}
} else {
if (bg::num_points(pit->linestring) > 0) {
if (bg::num_points(pit->linestring) > 1) {
ss << std::setprecision(12) << bg::wkt(pit->linestring);
geometry_str = ss.str();
// Erase "LINESTRING("
geometry_str.erase(0,11);
geometry_str.erase(geometry_str.size() - 1);
if (geometry_str.size() > 0) {
geometry += "(" + geometry_str + "),";
}
geometry += "(" + geometry_str + "),";
}
}
}

// Outer parts
for (auto pit = parts_inner.begin(); pit != parts_inner.end(); ++pit) {
std::stringstream ss;
std::string geometry_str;
++i;
if (relation.isMultiPolygon()) {
if (bg::num_points(pit->polygon.outer()) > 0) {
if (bg::num_points(pit->polygon.outer()) > 1) {
ss << std::setprecision(12) << bg::wkt(pit->polygon);
geometry_str = ss.str();
// Erase "POLYGON("
geometry_str.erase(0,8);
geometry_str.erase(geometry_str.size() - 1);
if (geometry_str.size() > 0) {
geometry += geometry_str + ",";
}
geometry += geometry_str + ",";
}
} else {
if (bg::num_points(pit->linestring) > 0) {
if (bg::num_points(pit->linestring) > 1) {
ss << std::setprecision(12) << bg::wkt(pit->linestring);
geometry_str = ss.str();
// Erase "LINESTRING("
geometry_str.erase(0,11);
geometry_str.erase(geometry_str.size() - 1);
if (geometry_str.size() > 0) {
geometry += "(" + geometry_str + "),";
}
geometry += "(" + geometry_str + "),";
}
}
}

if (geometry.size() > 0) {
// Build the final multipolygon or multilinestring to store it as the
// relation's geometry
if (geometry.size() > 1) {
geometry.erase(geometry.size() - 1);
if (relation.isMultiPolygon()) {
bg::read_wkt("POLYGON(" + geometry + ")", relation.multipolygon);
Expand Down
5 changes: 3 additions & 2 deletions src/raw/queryraw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ QueryRaw::applyChange(const OsmRelation &relation) const
}
std::string geostring = ss.str();

// Ignore empty geometries.
if (geostring != "MULTILINESTRING()" && geostring != "POLYGON()") {
// Ignore empty geometries
if (geostring != "MULTILINESTRING()" && geostring != "POLYGON()"
&& geostring != "MULTILINESTRING(())" && geostring != "POLYGON(())") {

// Insert or update the full Relation, including id, tags, refs, geometry, timestamp,
// version, user, uid and changeset
Expand Down

0 comments on commit 33fd7c1

Please sign in to comment.