Skip to content

[0.4.1] configurable geometry vertex limit - #59

Merged
sujata-m merged 1 commit into
mainfrom
develop
Aug 12, 2026
Merged

[0.4.1] configurable geometry vertex limit#59
sujata-m merged 1 commit into
mainfrom
develop

Conversation

@sujata-m

Copy link
Copy Markdown
Contributor

Changes

Adds max_geometry_vertices to FormatterConfig, defaulting to 2000 to match python-osw-validation. One setting drives both places the limit matters.

Validation. The limit reaches the validator for OSW input and for the OSW generated by OSM → OSW, so a line or polygon feature carrying more vertices is reported with the validator's own message:

Feature 'e1' in 'edges.geojson' contains 2001 geometry vertices. Maximum allowed is 2000.

Scope and counting are the validator's: edges, lines, polygons and zones; points and nodes unaffected; polygon vertices summed across exterior and interior rings with the closing coordinate excluded.

Way splitting. The same setting is passed to ogr2osm as max_points_in_way, raising its split point from the 1800 default. A run of coordinates too long for a single OSM way becomes several ways sharing a node, so the pieces stay joined.

Splitting still applies to input the validator accepts, because the two count different things: the validator counts unique vertices and ignores a ring's closing coordinate, while an OSM way counts every node reference. A ring of exactly 2000 unique vertices is valid, yet needs 2001 references and cannot be one way. max_vertices_ok.zip is exactly this case — valid input that still splits.

Lowering the limit tightens both at once: input validation gets stricter and ways split sooner.

Notes for review

Two things were already implemented and are not reimplemented here:

  • python-osw-validation already enforces the whole rule — counting, ring-closure exclusion, multipart summation, dataset scope, message text, errors + issues, max_errors. All of it already held at the default; the only gap was that it was not reachable from FormatterConfig.
  • ogr2osm already splits long ways with the same shared-node algorithm, and handles ways inside relations. An earlier hand-rolled splitter was removed in favour of configuring the library.

Behaviour change

Ways now split at 2000 nodes rather than ogr2osm's 1800, so conversions produce slightly fewer, longer ways than before. No API removed.

Testing

340 tests pass. 24 new tests cover the boundary (1999 / 2000 / 2001), lines, polygons, interior rings, closing-coordinate exclusion, point datasets being unaffected, issue contents, max_errors, configurability, and splitting.

End-to-end, with every conversion output handed back to the validator:

  • All 19 fixtures round-tripped; every one that converts produces valid OSW, and the five intended-failure fixtures are rejected as expected.
  • The split round trip preserves the data — 1 edge, 1 line, 1 zone, 1 polygon in and out, validator clean.
  • Real datasets validate: wa.microsoft.osm.pbf (4369 edges), test_roundtrip.zip (451 edges), osw.zip (4407 edges), dataset_with_incline.zip.

Four fixtures added — max_vertices_ok.zip, max_vertices_exceeded.zip, max_vertices_way_ok.xml, max_vertices_way_exceeded.xml.

## Changes

Adds `max_geometry_vertices` to `FormatterConfig`, defaulting to 2000 to match
`python-osw-validation`. One setting drives both places the limit matters.

**Validation.** The limit reaches the validator for OSW input and for the OSW
generated by OSM → OSW, so a line or polygon feature carrying more vertices is
reported with the validator's own message:

```
Feature 'e1' in 'edges.geojson' contains 2001 geometry vertices. Maximum allowed is 2000.
```

Scope and counting are the validator's: `edges`, `lines`, `polygons` and `zones`;
points and nodes unaffected; polygon vertices summed across exterior and interior
rings with the closing coordinate excluded.

**Way splitting.** The same setting is passed to `ogr2osm` as `max_points_in_way`,
raising its split point from the 1800 default. A run of coordinates too long for a
single OSM way becomes several ways sharing a node, so the pieces stay joined.

Splitting still applies to input the validator accepts, because the two count
different things: the validator counts unique vertices and ignores a ring's
closing coordinate, while an OSM way counts every node reference. A ring of
exactly 2000 unique vertices is valid, yet needs 2001 references and cannot be one
way. `max_vertices_ok.zip` is exactly this case — valid input that still splits.

Lowering the limit tightens both at once: input validation gets stricter and ways
split sooner.

## Notes for review

Two things were already implemented and are not reimplemented here:

- `python-osw-validation` already enforces the whole rule — counting, ring-closure
  exclusion, multipart summation, dataset scope, message text, `errors` +
  `issues`, `max_errors`. All of it already held at the default; the only gap was
  that it was not reachable from `FormatterConfig`.
- `ogr2osm` already splits long ways with the same shared-node algorithm, and
  handles ways inside relations. An earlier hand-rolled splitter was removed in
  favour of configuring the library.

## Behaviour change

Ways now split at 2000 nodes rather than ogr2osm's 1800, so conversions produce
slightly fewer, longer ways than before. No API removed.

## Testing

340 tests pass. 24 new tests cover the boundary (1999 / 2000 / 2001), lines,
polygons, interior rings, closing-coordinate exclusion, point datasets being
unaffected, issue contents, `max_errors`, configurability, and splitting.

End-to-end, with every conversion output handed back to the validator:

- All 19 fixtures round-tripped; every one that converts produces **valid** OSW,
  and the five intended-failure fixtures are rejected as expected.
- The split round trip preserves the data — 1 edge, 1 line, 1 zone, 1 polygon in
  and out, validator clean.
- Real datasets validate: `wa.microsoft.osm.pbf` (4369 edges), `test_roundtrip.zip`
  (451 edges), `osw.zip` (4407 edges), `dataset_with_incline.zip`.

Four fixtures added — `max_vertices_ok.zip`, `max_vertices_exceeded.zip`,
`max_vertices_way_ok.xml`, `max_vertices_way_exceeded.xml`.
@sujata-m
sujata-m requested review from MashB and susrisha August 12, 2026 18:01
@sujata-m
sujata-m merged commit f0139e6 into main Aug 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants