Skip to content

Commit

Permalink
Improve public POI performance and allow offline usage #1169 - Fix pr…
Browse files Browse the repository at this point in the history
…oblem in iNature and geojson conversion
  • Loading branch information
HarelM committed May 26, 2020
1 parent 6223c58 commit 8d09ca2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 6 additions & 2 deletions IsraelHiking.API/Converters/GpxGeoJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override async Task<Feature> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouteData>
{
new RouteData
{
Segments = new List<RouteSegmentData>
{
new RouteSegmentData
{
Latlngs = new List<LatLngTime>
{
new LatLngTime()
}
}
}
}
}
};
var feautreCollection = _converterService.ToAnyFormat(dataContainer, FlowFormats.GEOJSON).Result;
Assert.IsNotNull(feautreCollection);
}
}
}

0 comments on commit 8d09ca2

Please sign in to comment.