Skip to content

Commit

Permalink
Update NTS to version 2.0 #1137 - remove redundant cast
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Apr 19, 2020
1 parent 85a4382 commit 8c6bec1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions IsraelHiking.API/Controllers/OsmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private LineString ToItmLineString(IEnumerable<GpxWaypoint> waypoints)
nonDuplicates.Add(coordinate);
}
}
return _geometryFactory.CreateLineString(nonDuplicates.ToArray()) as LineString;
return _geometryFactory.CreateLineString(nonDuplicates.ToArray());
}

private LineString ToWgs84LineString(IEnumerable<Coordinate> coordinates)
Expand All @@ -229,7 +229,7 @@ private LineString ToWgs84LineString(IEnumerable<Coordinate> coordinates)
nonDuplicates.Add(coordinate);
}
}
return _geometryFactory.CreateLineString(nonDuplicates.ToArray()) as LineString;
return _geometryFactory.CreateLineString(nonDuplicates.ToArray());
}

private List<LineString> GpxToItmLineStrings(GpxFile gpx)
Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/Converters/GpxGeoJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public FeatureCollection ToGeoJson(GpxFile gpx)
collection.Add(lineStringFeature);
continue;
}
var lineStringList = track.Segments.Select(segment => new LineString(segment.Waypoints.Select(CreateGeoPosition).ToArray()) as LineString).ToArray();
var lineStringList = track.Segments.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
2 changes: 1 addition & 1 deletion IsraelHiking.API/Converters/OsmGeoJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private Feature ConvertRelation(CompleteRelation relation)
return null;
}
var jointLines = geometries.OfType<LineString>().ToList();
jointLines.AddRange(geometries.OfType<Polygon>().Select(p => _geometryFactory.CreateLineString(p.ExteriorRing.Coordinates.ToArray()) as LineString));
jointLines.AddRange(geometries.OfType<Polygon>().Select(p => _geometryFactory.CreateLineString(p.ExteriorRing.Coordinates.ToArray())));
var multiLineString = _geometryFactory.CreateMultiLineString(jointLines.ToArray());
return new Feature(multiLineString, ConvertTags(relation));
}
Expand Down
4 changes: 2 additions & 2 deletions IsraelHiking.API/Executors/GpxLoopsSplitterExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<LineString> SplitSelfLoops(LineString gpxLine, double minimalDistanc
}
AddLineString(lines, reversedGpxLine.Coordinates.Take(indexOfClosingLine).ToArray());
var reminingPoints = reversedGpxLine.Coordinates.Skip(indexOfClosingLine).ToArray();
reversedGpxLine = reminingPoints.Length > 1 ? _geometryFactory.CreateLineString(reminingPoints) as LineString : _geometryFactory.CreateLineString(new Coordinate[0]) as LineString;
reversedGpxLine = reminingPoints.Length > 1 ? _geometryFactory.CreateLineString(reminingPoints) : _geometryFactory.CreateLineString(new Coordinate[0]);
coordinateIndex = 0;
}
AddLineString(lines, reversedGpxLine.Coordinates);
Expand Down Expand Up @@ -99,7 +99,7 @@ private void AddLineString(ICollection<LineString> gpxSplit, Coordinate[] coordi
{
return;
}
gpxSplit.Add(_geometryFactory.CreateLineString(coordinates) as LineString);
gpxSplit.Add(_geometryFactory.CreateLineString(coordinates));
}

private bool IsCloseToALine(Coordinate coordinate, IReadOnlyList<LineString> lineStrings, double minimalDistanceToClosestPoint)
Expand Down
4 changes: 2 additions & 2 deletions IsraelHiking.API/Executors/GpxProlongerExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void HandleTwoLinesCase(GpxProlongerExecutorInput input, SegmentWithLine
.Concat(segment.OriginalCoordinates)
.Concat(segment.End.Line.Coordinates)
.Distinct()
.ToArray()) as LineString);
.ToArray()));
}
else if (!AddSegmentToLine(segment.Start.Line, segment, linesToProlong, input.MinimalDistance))
{
Expand Down Expand Up @@ -260,7 +260,7 @@ private LineString CreateLineString(Coordinate currentCoordinate, Coordinate[] o
{
list.Add(nextCoordinate);
}
return _geometryFactory.CreateLineString(list.ToArray()) as LineString;
return _geometryFactory.CreateLineString(list.ToArray());
}

private SegmentWithLines CreateSegmentWithLines(Coordinate[] segment, LineAndCoordinate current, LineAndCoordinate next)
Expand Down
24 changes: 12 additions & 12 deletions IsraelHiking.API/Services/AddibleGpxLinesFinderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ private List<LineString> SplitGpxLines(List<LineString> gpxItmLines)
if (coordinateIndex > 1)
{
// need to add line only if there's more than 1 coordinate to take.
splitGpxLines.Add(_geometryFactory.CreateLineString(coordinates.Take(coordinateIndex).ToArray()) as LineString);
splitGpxLines.Add(_geometryFactory.CreateLineString(coordinates.Take(coordinateIndex).ToArray()));
}
coordinates = coordinates.Skip(coordinateIndex).ToArray();
coordinateIndex = 1;
}
}
splitGpxLines.Add(_geometryFactory.CreateLineString(coordinates.ToArray()) as LineString);
splitGpxLines.Add(_geometryFactory.CreateLineString(coordinates.ToArray()));
}
return splitGpxLines.Where(l => l.Coordinates.Length > 0).ToList();
}
Expand All @@ -125,7 +125,7 @@ private List<LineString> IncreaseGpxDensity(List<LineString> gpxItmLines)
coordinates.Insert(coordinateIndex + 1, middle);
}
}
denseGpxLines.Add(_geometryFactory.CreateLineString(coordinates.Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1))).ToArray()) as LineString);
denseGpxLines.Add(_geometryFactory.CreateLineString(coordinates.Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1))).ToArray()));
}
return denseGpxLines;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private List<LineString> SplitLine(LineString itmLineSting)
}
var splitLineToAdd = _geometryFactory.CreateLineString(itmLineSting.Coordinates
.Skip(segmentIndex * maxNumberOfPointsPerLine)
.Take(maxNumberOfPointsPerLine + 1).ToArray()) as LineString;
.Take(maxNumberOfPointsPerLine + 1).ToArray());
splitLines.Add(splitLineToAdd);
}
return splitLines;
Expand All @@ -241,7 +241,7 @@ private List<LineString> MergeBackLines(List<LineString> missingLines)
if (currentLineCoordinates.First().Equals2D(previousLineCoordinates.Last()))
{
currentLineCoordinates.RemoveAt(0);
lineToAdd = _geometryFactory.CreateLineString(previousLineCoordinates.Concat(currentLineCoordinates).ToArray()) as LineString;
lineToAdd = _geometryFactory.CreateLineString(previousLineCoordinates.Concat(currentLineCoordinates).ToArray());
}
else
{
Expand All @@ -266,7 +266,7 @@ private List<LineString> MergeLines(List<LineString> missingLines)
{
var index = mergedLines.IndexOf(lineToAddTo);
mergedLines.RemoveAt(index);
var mergedLine = _geometryFactory.CreateLineString(lineToAddTo.Coordinates.Concat(missingLine.Coordinates.Skip(1)).ToArray()) as LineString;
var mergedLine = _geometryFactory.CreateLineString(lineToAddTo.Coordinates.Concat(missingLine.Coordinates.Skip(1)).ToArray());
mergedLines.Insert(index, mergedLine);
continue;
}
Expand All @@ -276,7 +276,7 @@ private List<LineString> MergeLines(List<LineString> missingLines)
{
var index = mergedLines.IndexOf(lineToAddTo);
mergedLines.RemoveAt(index);
var mergedLine = _geometryFactory.CreateLineString(missingLine.Coordinates.Concat(lineToAddTo.Coordinates.Skip(1)).ToArray()) as LineString;
var mergedLine = _geometryFactory.CreateLineString(missingLine.Coordinates.Concat(lineToAddTo.Coordinates.Skip(1)).ToArray());
mergedLines.Insert(index, mergedLine);
continue;
}
Expand All @@ -298,7 +298,7 @@ private LineString ToItmLineString(IEnumerable<Coordinate> coordinates, long id)
var itmCoordinates = coordinates.Select(c => _wgs84ItmMathTransform.Transform(c.X, c.Y))
.Select(c => new Coordinate(Math.Round(c.x, 1), Math.Round(c.y, 1)))
.ToArray();
var line = _geometryFactory.CreateLineString(itmCoordinates) as LineString;
var line = _geometryFactory.CreateLineString(itmCoordinates);
line.SetOsmId(id);
return line;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ private async Task<List<LineString>> ProlongLinesAccordingToOriginalGpx(List<Lin
prolongInputs.Insert(0, new GpxProlongerExecutorInput
{
OriginalCoordinates = coordinates,
ExistingItmHighways = await GetExistingCloseLines(_geometryFactory.CreateLineString(coordinates) as LineString),
ExistingItmHighways = await GetExistingCloseLines(_geometryFactory.CreateLineString(coordinates)),
MinimalDistance = _options.MaxDistanceToExisitngLineForMerge,
MinimalAreaSize = _options.MinimalAreaSize,
MinimalLength = _options.MinimalProlongLineLength
Expand All @@ -338,7 +338,7 @@ private async Task<List<LineString>> ProlongLinesAccordingToOriginalGpx(List<Lin
input.LinesToProlong = linesToProlong;
linesToProlong = _gpxProlongerExecutor.Prolong(input);
}
return linesToProlong.Select(l => _geometryFactory.CreateLineString(l.Coordinates.Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1))).ToArray()) as LineString).ToList();
return linesToProlong.Select(l => _geometryFactory.CreateLineString(l.Coordinates.Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1))).ToArray())).ToList();
}

private List<LineString> AdjustIntersections(List<LineString> gpxItmLines)
Expand All @@ -360,7 +360,7 @@ private List<LineString> AdjustIntersections(List<LineString> gpxItmLines)
var currentCoordinates = currentLine.Coordinates.ToList();
ReplaceEdgeIfNeeded(adjustedLines, currentCoordinates.First(), currentCoordinates);
ReplaceEdgeIfNeeded(adjustedLines, currentCoordinates.Last(), currentCoordinates);
adjustedLines.Add(_geometryFactory.CreateLineString(currentCoordinates.ToArray()) as LineString);
adjustedLines.Add(_geometryFactory.CreateLineString(currentCoordinates.ToArray()));
}
return adjustedLines;
}
Expand All @@ -385,7 +385,7 @@ private LineString GetLineWithExtraPoints(LineString currentLine, Coordinate coo
var projectedLocation = line.Project(coordinateToAddIfNeeded);
var coordinateToAdd = line.ExtractPoint(projectedLocation);
coordinates.Insert(projectedLocation.SegmentIndex + 1, coordinateToAdd);
return _geometryFactory.CreateLineString(coordinates.ToArray()) as LineString;
return _geometryFactory.CreateLineString(coordinates.ToArray());
}

private void ReplaceEdgeIfNeeded(List<LineString> adjustedLines, Coordinate coordinate, List<Coordinate> currentCoordinates)
Expand Down

0 comments on commit 8c6bec1

Please sign in to comment.