Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Railway translation issue #5768

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conf/core/RoadCrossingBUARules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"rules":
[
{
"name": "landuse",
"polyCriteriaFilter": "LanduseCriterion"
}
]
}
95 changes: 95 additions & 0 deletions hoot-core/src/main/cpp/hoot/core/criterion/LanduseCriterion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* This file is part of Hootenanny.
*
* Hootenanny is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --------------------------------------------------------------------
*
* The following copyright notices are generated automatically. If you
* have a new notice to add, please use the format:
* " * @copyright Copyright ..."
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2019-2023 Maxar (http://www.maxar.com/)
*/

#include "LanduseCriterion.h"

// hoot
#include <hoot/core/criterion/PolygonWayNodeCriterion.h>
#include <hoot/core/elements/Way.h>
#include <hoot/core/util/Factory.h>

namespace hoot
{

HOOT_FACTORY_REGISTER(ElementCriterion, LanduseCriterion)

LanduseCriterion::LanduseCriterion(ConstOsmMapPtr map)
: ConstOsmMapConsumerBase(map)
{
// Set this to allow any on poly child member to satisfy the crit.
_relationCrit.setAllowMixedChildren(true);
_relationCrit.setOsmMap(map.get());
}

void LanduseCriterion::setOsmMap(const OsmMap* map)
{
ConstOsmMapConsumerBase::setOsmMap(map);
_relationCrit.setOsmMap(map);
}

bool LanduseCriterion::isSatisfied(const ConstElementPtr& e) const
{
LOG_VART(e->getElementId());

// element has landuse tag
const Tags& tags = e->getTags();
auto it = tags.find("landuse");
// Specifically looking for BUAs
std::vector<QString> landuseTypes = {"residential", "commercial", "industrial"};
const bool containsLanduseTag = it != tags.end() && (std::find(landuseTypes.begin(), landuseTypes.end(), it.value()) != landuseTypes.end());
bool result = false;

switch(e->getElementType().getEnum())
{
default:
case ElementType::Node:
return false;
case ElementType::Way:
{
ConstWayPtr way = std::dynamic_pointer_cast<const Way>(e);
LOG_VART(way->isValidPolygon());
LOG_VART(way->isClosedArea());
if (way->isValidPolygon() && way->isClosedArea() && containsLanduseTag)
{
LOG_TRACE("Way is valid closed landuse area; crit satisfied.");
result = true;
LOG_TRACE(e->getElementId() << " result: " << result);
return true;
}
break;
}
}
LOG_TRACE(e->getElementId() << " result: " << result);
return false;
}

QStringList LanduseCriterion::getChildCriteria() const
{
return QStringList(PolygonWayNodeCriterion::className());
}

}
78 changes: 78 additions & 0 deletions hoot-core/src/main/cpp/hoot/core/criterion/LanduseCriterion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of Hootenanny.
*
* Hootenanny is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --------------------------------------------------------------------
*
* The following copyright notices are generated automatically. If you
* have a new notice to add, please use the format:
* " * @copyright Copyright ..."
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2019-2023 Maxar (http://www.maxar.com/)
*/

#ifndef LANDUSE_CRITERION_H
#define LANDUSE_CRITERION_H

// Hoot
#include <hoot/core/criterion/ConflatableElementCriterion.h>
#include <hoot/core/criterion/RelationWithPolygonMembersCriterion.h>
#include <hoot/core/elements/ConstOsmMapConsumer.h>

#include <string>
#include <vector>
#include <algorithm>

namespace hoot
{

/**
* Identifies Landuse polygon features
*/
class LanduseCriterion : public ConflatableElementCriterion, public ConstOsmMapConsumerBase
{
public:

static QString className() { return "LanduseCriterion"; }

LanduseCriterion() = default;
LanduseCriterion(ConstOsmMapPtr map);
~LanduseCriterion() override = default;

bool isSatisfied(const ConstElementPtr& e) const override;
ElementCriterionPtr clone() override { return std::make_shared<LanduseCriterion>(_map); }

void setOsmMap(const OsmMap* map) override;

bool supportsSpecificConflation() const override { return false; }
GeometryType getGeometryType() const override { return GeometryType::Polygon; }
QStringList getChildCriteria() const override;

QString getName() const override { return className(); }
QString getClassName() const override { return className(); }
QString toString() const override { return className(); }
QString getDescription() const override { return "Identifies landuse polygon features"; }

void setAllowMixedChildren(bool allow) { _relationCrit.setAllowMixedChildren(allow); }

private:

RelationWithPolygonMembersCriterion _relationCrit;
};

}
#endif // LANDUSE_CRITERION_H
6 changes: 6 additions & 0 deletions hoot-core/src/main/cpp/hoot/core/ops/FindIntersectionsOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace hoot

HOOT_FACTORY_REGISTER(OsmMapOperation, FindHighwayIntersectionsOp)
HOOT_FACTORY_REGISTER(OsmMapOperation, FindRailwayIntersectionsOp)
HOOT_FACTORY_REGISTER(OsmMapOperation, FindHighwayLanduseIntersectionsOp)

void FindIntersectionsOp::apply(std::shared_ptr<OsmMap>& map)
{
Expand Down Expand Up @@ -115,4 +116,9 @@ std::shared_ptr<FindIntersectionsVisitor> FindRailwayIntersectionsOp::createVisi
return std::make_shared<FindRailwayIntersectionsVisitor>();
}

std::shared_ptr<FindIntersectionsVisitor> FindHighwayLanduseIntersectionsOp::createVisitor()
{
return std::make_shared<FindHighwayLanduseIntersectionsVisitor>();
}

}
18 changes: 18 additions & 0 deletions hoot-core/src/main/cpp/hoot/core/ops/FindIntersectionsOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ class FindRailwayIntersectionsOp : public FindIntersectionsOp
QString getDescription() const override { return "Identifies railway intersections"; }
};

/**
* Op that finds all highway/landuse intersections
*/
class FindHighwayLanduseIntersectionsOp : public FindIntersectionsOp
{
public:
FindHighwayLanduseIntersectionsOp() = default;
~FindHighwayLanduseIntersectionsOp() override = default;

static QString className() { return "FindHighwayLanduseIntersectionsOp"; }

std::shared_ptr<FindIntersectionsVisitor> createVisitor() override;

QString getName() const override { return className(); }
QString getClassName() const override { return className(); }
QString getDescription() const override { return "Identifies highway/landuse intersections"; }
};

}

#endif // FINDHIGHWAYINTERSECTIONSOP_H
Loading