Skip to content

Commit

Permalink
Added warnings messages for invalid shapes (#15296)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoueraud87 committed Aug 27, 2024
1 parent c09a828 commit b1bc8b8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(netconvertlibs
netwrite netimport netbuild foreign_eulerspiral ${GDAL_LIBRARY} netimport_vissim netimport_vissim_typeloader netimport_vissim_tempstructs ${commonlibs} ${TCMALLOC_LIBRARY})
netwrite netimport netbuild foreign_eulerspiral ${GDAL_LIBRARY} netimport_vissim netimport_vissim_typeloader netimport_vissim_tempstructs ${commonlibs} ${TCMALLOC_LIBRARY} ${GEOS_LIBRARY})

set(sumolibs
traciserver netload microsim_cfmodels microsim_engine microsim_lcmodels microsim_devices microsim_trigger microsim_output microsim_transportables microsim_actions
Expand Down
32 changes: 32 additions & 0 deletions src/netbuild/NBNetBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <string>
#include <fstream>
#include <geos_c.h>
#include <utils/options/OptionsCont.h>
#include <utils/common/MsgHandler.h>
#include <utils/common/UtilExceptions.h>
Expand Down Expand Up @@ -712,6 +713,20 @@ NBNetBuilder::compute(OptionsCont& oc, const std::set<std::string>& explicitTurn
WRITE_WARNING(TL("Network contains very large coordinates and will probably flicker in the GUI. Check for outlying nodes and make sure the network is shifted to the coordinate origin"));
}

for (std::map<std::string, NBNode*>::const_iterator it = myNodeCont.begin(); it != myNodeCont.end(); ++it) {
const PositionVector& junctionShape = it->second->getShape();
if (!isValid(junctionShape)) {
WRITE_WARNINGF(TL("Node % has invalid geometry"), it->second->getID());
}
const std::vector<NBNode::WalkingArea>& walkingAreas = it->second->getWalkingAreas();
for (std::vector<NBNode::WalkingArea>::const_iterator itwa = walkingAreas.begin(); itwa != walkingAreas.end(); ++itwa) {
const PositionVector& walkingAreaShape = itwa->shape;
if (!isValid(walkingAreaShape)) {
WRITE_WARNINGF(TL("Walking area % of node % has invalid geometry"), itwa->id, it->second->getID());
}
}
}

// clean up OSM processing params
if (oc.exists("osm-files") && oc.isSet("osm-files")) {
for (auto item : myEdgeCont) {
Expand Down Expand Up @@ -765,6 +780,23 @@ NBNetBuilder::mirrorX() {
}


bool
NBNetBuilder::isValid(const PositionVector& shape) const {
GEOSCoordSequence* coordinateSequence = GEOSCoordSeq_create((unsigned int)shape.size(), 2);
for (int i = 0; i < (int)shape.size(); i++) {
GEOSCoordSeq_setXY(coordinateSequence, i, shape[i].x(), shape[i].y());
}
GEOSGeometry* geometry = GEOSGeom_createLinearRing(coordinateSequence);
char isValid = GEOSisValid(geometry);
GEOSGeom_destroy(geometry);
if (isValid == 1) {
return true;
} else {
return false;
}
}


bool
NBNetBuilder::transformCoordinate(Position& from, bool includeInBoundary, GeoConvHelper* from_srs) {
Position orig(from);
Expand Down
6 changes: 6 additions & 0 deletions src/netbuild/NBNetBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ class NBNetBuilder {
/// @brief mirror the network along the X-axis
void mirrorX();

/// @brief check if the node is valid according to GEOS
/// @link https://libgeos.org/doxygen/geos__c_8h.html#ae65e55acad28e2b55d793730dd1d4e06
/// @param node a pointer to the NBNode instance to be validated
/// @return whether the node is valid or not
bool isValid(const PositionVector& shape) const;

private:
/// @brief invalidated copy constructor
NBNetBuilder(const NBNetBuilder& s);
Expand Down
2 changes: 1 addition & 1 deletion src/netgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(netgenerate_SRCS
add_executable(netgenerate ${netgenerate_SRCS})
set_target_properties(netgenerate PROPERTIES OUTPUT_NAME netgenerate${BINARY_SUFFIX})
set_target_properties(netgenerate PROPERTIES OUTPUT_NAME_DEBUG netgenerate${BINARY_SUFFIX}D)
target_link_libraries(netgenerate netbuild netimport netwrite ${GDAL_LIBRARY} ${commonlibs} ${TCMALLOC_LIBRARY})
target_link_libraries(netgenerate netbuild netimport netwrite ${GDAL_LIBRARY} ${commonlibs} ${TCMALLOC_LIBRARY} ${GEOS_LIBRARY})
add_dependencies(netgenerate generate-version-h install_dll)

install(TARGETS netgenerate RUNTIME DESTINATION bin)
2 changes: 1 addition & 1 deletion unittest/src/netbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(testnetbuild NBHeightMapperTest.cpp NBTrafficLightLogicTest.cpp)
setTestProperties(testnetbuild netbuild ${GDAL_LIBRARY})
setTestProperties(testnetbuild netbuild ${GDAL_LIBRARY} ${GEOS_LIBRARY})

0 comments on commit b1bc8b8

Please sign in to comment.