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

Require valid polygons for AreaStop #5915

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

leonardehrenfried
Copy link
Member

Summary

For Netex it is required that the imported polygons for AreaStops are valid and not (for example) self-intersecting.

So far GTFS allowed you to import invalid polygons, which mostly worked, but sometimes didn't. As it was not spelled out in the GTFS spec, I am currently proposing a clarification in the spec to change this: google/transit#476
It contains also a good example why invalid polygons are problematic.

For this reason I'm proposing that all AreaStop geometries be valid and the check can happen in the constructor.

This PR also renames the GTFS mapper since the entity it is mapping to has been renamed quite a while ago. I'm also removing an old integration test that contained an invalid polygon.

Issue

#5457

Unit tests

Added.

@leonardehrenfried leonardehrenfried added Technical Debt bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR labels Jun 17, 2024
@leonardehrenfried leonardehrenfried requested a review from a team as a code owner June 17, 2024 09:04
Copy link

codecov bot commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.43%. Comparing base (67e6510) to head (ccbce81).
Report is 50 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5915      +/-   ##
=============================================
- Coverage      69.46%   69.43%   -0.03%     
+ Complexity     17068    17059       -9     
=============================================
  Files           1928     1934       +6     
  Lines          73580    73620      +40     
  Branches        7550     7541       -9     
=============================================
+ Hits           51109    51117       +8     
- Misses         19847    19874      +27     
- Partials        2624     2629       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vpaturet
Copy link
Contributor

what happens when the polygon is not closed? In this case a Polygon instance cannot even be created.

  public static final Polygon NON_CLOSED = FAC.createPolygon(
    new Coordinate[] {
      Coordinates.of(59.62575084033623, 6.3023991052849),
      Coordinates.of(59.62883380609349, 6.289718020117876),
      Coordinates.of(59.6346950024935, 6.293494451572027),
    }
  );

I assume this gets caught in the OneBusAway code. Does it get mapped to an issue as well?

@leonardehrenfried
Copy link
Member Author

@vpaturet I've now added that adds an issue and returns null when the polygon is not a closed ring. That will probably fail with a confusing NPE elsewhere.

@vpaturet
Copy link
Contributor

Indeed that will fail with NPE here for instance:


and in other places.
Trading an IllegalArgumentException for a NullPointerException does not really help.

} catch (UnsupportedGeometryException e) {
LOG.error("Unsupported geometry type for {}", gtfsLocation.getId());
var geometry = GeometryUtils.convertGeoJsonToJtsGeometry(gtfsLocation.getGeometry());
var isValidOp = new IsValidOp(geometry);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class has weird naming but I guess that's not our fault.

Comment on lines +46 to +59
if (!isValidOp.isValid()) {
var error = isValidOp.getValidationError();
issueStore.add(
Issue.issue(
"InvalidFlexAreaGeometry",
"GTFS flex location %s has an invalid geometry: %s at (lat: %s, lon: %s)",
id,
error.getMessage(),
error.getCoordinate().y,
error.getCoordinate().x
)
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are there some geometries which don't throw an exception but are still considered invalid by the validator? Do these cause issues during runtime?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The routing sometimes (mostly?) works anyway but the vector tiles library refuses to serialise these geometries.

}

@Test
void nonClosedPolygon() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be called open polygons? I tried quickly reading about this and maybe the open is a bit vague so lets stick with nonClosed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this last week and the handling of the incomplete polygons was removed from this PR.

@leonardehrenfried leonardehrenfried merged commit 67947c6 into opentripplanner:dev-2.x Jul 3, 2024
10 checks passed
@leonardehrenfried leonardehrenfried deleted the flex-polygons branch July 3, 2024 07:48
t2gran pushed a commit that referenced this pull request Jul 3, 2024
t2gran pushed a commit that referenced this pull request Jul 3, 2024
@t2gran t2gran added this to the 2.6 (next release) milestone Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR Technical Debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants