From 580ea72dbd31e05d54f4ca2950f43abb4b552ea3 Mon Sep 17 00:00:00 2001 From: FObermaier Date: Tue, 19 Mar 2024 10:49:15 +0100 Subject: [PATCH] Add extent test for lineal geometries --- .../MapboxTileWriter.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/NetTopologySuite.IO.VectorTiles.Mapbox/MapboxTileWriter.cs b/src/NetTopologySuite.IO.VectorTiles.Mapbox/MapboxTileWriter.cs index 141673b..f66f82b 100644 --- a/src/NetTopologySuite.IO.VectorTiles.Mapbox/MapboxTileWriter.cs +++ b/src/NetTopologySuite.IO.VectorTiles.Mapbox/MapboxTileWriter.cs @@ -240,8 +240,11 @@ private static IEnumerable Encode(ILineal lineal, TileGeometryTransform tg for (int i = 0; i < geometry.NumGeometries; i++) { var lineString = (LineString)geometry.GetGeometryN(i); - foreach (uint encoded in Encode(lineString.CoordinateSequence, tgt, ref currentX, ref currentY, false)) - yield return encoded; + if (tgt.IsGreaterThanOnePixelOfTile(lineString)) + { + foreach (uint encoded in Encode(lineString.CoordinateSequence, tgt, ref currentX, ref currentY, false)) + yield return encoded; + } } } @@ -284,24 +287,25 @@ private static IEnumerable Encode(CoordinateSequence sequence, TileGeometr // skipping the last point for rings since ClosePath is used instead int count = ring ? sequence.Count - 1 : sequence.Count; - // In case we decide to ditch encoded data, we must reset currentX and currentY - int initialCurrentX = currentX; - int initialCurrentY = currentY; - // If the sequence is empty there is nothing we can do with it. if (count == 0) return Array.Empty(); + // In case we decide to ditch encoded data, we must reset currentX and currentY + // or subsequent geometry items will not be positioned correctly. + int initialCurrentX = currentX; + int initialCurrentY = currentY; + // if we have a ring we need to check orientation if (ring) { if (ccw != Algorithm.Orientation.IsCCW(sequence)) - { - sequence = sequence.Copy(); - CoordinateSequences.Reverse(sequence); - } + sequence = sequence.Reversed(); } - var encoded = new List + + // provide encoded data buffer: + // 1 command + 2 parameter = 3 elements per coordinate + var encoded = new List(3 * count + (ring ? 1 : 0)) { // Start point GenerateCommandInteger(MapboxCommandType.MoveTo, 1)