diff --git a/IsraelHiking.API/Converters/GpxGeoJsonConverter.cs b/IsraelHiking.API/Converters/GpxGeoJsonConverter.cs index 95ff2ee11..ce55b0ec3 100644 --- a/IsraelHiking.API/Converters/GpxGeoJsonConverter.cs +++ b/IsraelHiking.API/Converters/GpxGeoJsonConverter.cs @@ -31,11 +31,15 @@ public FeatureCollection ToGeoJson(GpxFile gpx) { if (track.Segments.Length == 1) { - var lineStringFeature = new Feature(new LineString(track.Segments[0].Waypoints.Select(CreateGeoPosition).ToArray()), CreateProperties(track.Name, track.Description)); + if (track.Segments.First().Waypoints.Count <= 1) + { + continue; + } + var lineStringFeature = new Feature(new LineString(track.Segments.First().Waypoints.Select(CreateGeoPosition).ToArray()), CreateProperties(track.Name, track.Description)); collection.Add(lineStringFeature); continue; } - var lineStringList = track.Segments.Select(segment => new LineString(segment.Waypoints.Select(CreateGeoPosition).ToArray())).ToArray(); + var lineStringList = track.Segments.Where(s => s.Waypoints.Count > 1).Select(segment => new LineString(segment.Waypoints.Select(CreateGeoPosition).ToArray())).ToArray(); var feature = new Feature(new MultiLineString(lineStringList), CreateMultiLineProperties(track.Name, gpx.Metadata.Creator, track.Description)); collection.Add(feature); } diff --git a/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs index fbc530bd1..dc12d2ae5 100644 --- a/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs @@ -63,7 +63,7 @@ public override async Task GetRawPointOfInterestById(string id) return feature; } var featureBytes = await _dataContainerConverterService.ToAnyFormat(share.DataContainer, FlowFormats.GEOJSON); - var lineFeature = featureBytes.ToFeatureCollection().FirstOrDefault(f => f.Geometry is LineString) as Feature; + var lineFeature = featureBytes.ToFeatureCollection().FirstOrDefault(f => f.Geometry is LineString || f.Geometry is MultiLineString) as Feature; feature.Geometry = lineFeature?.Geometry ?? feature.Geometry; return feature; } diff --git a/Tests/IsraelHiking.API.Tests/Services/DataContainerConverterServiceTests.cs b/Tests/IsraelHiking.API.Tests/Services/DataContainerConverterServiceTests.cs index 1c6f46f67..0d1e9a0a7 100644 --- a/Tests/IsraelHiking.API.Tests/Services/DataContainerConverterServiceTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/DataContainerConverterServiceTests.cs @@ -392,5 +392,31 @@ public void ConvertKmzToGeoJson_ShouldConvert() Assert.AreNotEqual(0, converterd.Length); } + + [TestMethod] + public void ConvertDataContainer_InvalidSinglePointInSegment_ShouldNotFailToConvertToGeoJson() + { + var dataContainer = new DataContainer + { + Routes = new List + { + new RouteData + { + Segments = new List + { + new RouteSegmentData + { + Latlngs = new List + { + new LatLngTime() + } + } + } + } + } + }; + var feautreCollection = _converterService.ToAnyFormat(dataContainer, FlowFormats.GEOJSON).Result; + Assert.IsNotNull(feautreCollection); + } } }