Skip to content

Commit

Permalink
Update NTS to version 2.0 #1137
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jan 26, 2020
1 parent 9a54b2f commit d4564ef
Show file tree
Hide file tree
Showing 78 changed files with 232 additions and 296 deletions.
7 changes: 4 additions & 3 deletions IsraelHiking.API/Controllers/CsvController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using IsraelHiking.DataAccessInterfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -50,15 +51,15 @@ public CsvController(IDataContainerConverterService dataContainerConverterServic
public async Task<IActionResult> UploadCsv(IFormFile file, [FromQuery]string idRegExPattern, [FromQuery]string sourceImageUrl, [FromQuery]string icon = "icon-bike", [FromQuery]string iconColor = "black", [FromQuery]string category = Categories.ROUTE_BIKE)
{
var reader = new StreamReader(file.OpenReadStream());
var csvReader = new CsvReader(reader);
var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture);
csvReader.Configuration.HeaderValidated = null;
csvReader.Configuration.MissingFieldFound = null;
var pointsOfInterest = csvReader.GetRecords<CsvPointOfInterestRow>().ToList();

var stream = new MemoryStream();
using (TextWriter writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
{
var csvWriter = new CsvWriter(writer);
var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture);
csvWriter.Configuration.HasHeaderRecord = true;
csvWriter.WriteHeader<CsvPointOfInterestRow>();
csvWriter.NextRecord();
Expand All @@ -70,7 +71,7 @@ public async Task<IActionResult> UploadCsv(IFormFile file, [FromQuery]string idR
var geojsonBytes = await _dataContainerConverterService.Convert(response.Content,
response.FileName, FlowFormats.GEOJSON);
var geoJson = geojsonBytes.ToFeatureCollection();
var coordinate = geoJson.Features.First().Geometry.Coordinate;
var coordinate = geoJson.First().Geometry.Coordinate;
csvRow.Latitude = coordinate.Y;
csvRow.Longitude = coordinate.X;
}
Expand Down
9 changes: 4 additions & 5 deletions IsraelHiking.API/Controllers/ExternalSourcesController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Services.Poi;
using IsraelHiking.Common;
using IsraelHiking.Common.Extensions;
Expand Down Expand Up @@ -91,9 +90,9 @@ public async Task<IActionResult> PostRebuildSource(string source)
var geoLocation = feature.Attributes[FeatureAttributes.POI_GEOLOCATION] as AttributesTable;
var geoLocationCoordinate = new Coordinate((double)geoLocation[FeatureAttributes.LON], (double)geoLocation[FeatureAttributes.LAT]);
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, _elevationDataStorage.GetElevation(geoLocationCoordinate).Result);
var northEast = _wgs84ItmTransform.Transform(geoLocationCoordinate);
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_EAST, (int)northEast.X);
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_NORTH, (int)northEast.Y);
var northEast = _wgs84ItmTransform.Transform(geoLocationCoordinate.X, geoLocationCoordinate.Y);
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_EAST, (int)northEast.x);
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_NORTH, (int)northEast.y);
_elasticSearchGateway.AddExternalPoi(feature);
Interlocked.Increment(ref counter);
if (counter % 100 == 0)
Expand Down
7 changes: 3 additions & 4 deletions IsraelHiking.API/Controllers/ItmGridController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Executors;
using IsraelHiking.Common.Poi;
using Microsoft.AspNetCore.Mvc;
using ProjNet.CoordinateSystems.Transformations;
Expand Down Expand Up @@ -33,8 +32,8 @@ public ItmGridController(IItmWgs84MathTransfromFactory itmWgs84MathTransfromFact
[HttpGet]
public NorthEast GetItmCoordinates(double lat, double lon)
{
var coordiante = _wgs84ItmMathTransform.Transform(new Coordinate(lon, lat));
return new NorthEast { East = (int)coordiante.X, North = (int)coordiante.Y };
var coordiante = _wgs84ItmMathTransform.Transform(lon, lat);
return new NorthEast { East = (int)coordiante.x, North = (int)coordiante.y };
}
}
}
9 changes: 4 additions & 5 deletions IsraelHiking.API/Controllers/OsmController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Gpx;
using IsraelHiking.API.Services;
using IsraelHiking.API.Services.Osm;
Expand Down Expand Up @@ -206,8 +205,8 @@ private string GetHighwayTypeFromWaypoints(IReadOnlyCollection<GpxWaypoint[]> wa

private LineString ToItmLineString(IEnumerable<GpxWaypoint> waypoints)
{
var coordinates = waypoints.Select(waypoint => _wgs84ItmMathTransform.Transform(new Coordinate(waypoint.Longitude, waypoint.Latitude)))
.Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1)));
var coordinates = waypoints.Select(waypoint => _wgs84ItmMathTransform.Transform(waypoint.Longitude, waypoint.Latitude))
.Select(c => new Coordinate(Math.Round(c.x, 1), Math.Round(c.y, 1)));
var nonDuplicates = new List<Coordinate>();
foreach (var coordinate in coordinates)
{
Expand All @@ -221,7 +220,7 @@ private LineString ToItmLineString(IEnumerable<GpxWaypoint> waypoints)

private LineString ToWgs84LineString(IEnumerable<Coordinate> coordinates)
{
var wgs84Coordinates = coordinates.Select(c => _itmWgs84MathTransform.Transform(c));
var wgs84Coordinates = coordinates.Select(c => _itmWgs84MathTransform.Transform(c.X, c.Y)).Select(c => new Coordinate(c.x, c.y));
var nonDuplicates = new List<Coordinate>();
foreach (var coordinate in wgs84Coordinates)
{
Expand Down
15 changes: 7 additions & 8 deletions IsraelHiking.API/Controllers/RoutingController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Executors;
using IsraelHiking.Common;
using IsraelHiking.DataAccessInterfaces;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -89,7 +88,7 @@ public async Task<IActionResult> GetRouting(string from, string to, string type)
{"Creator", "IsraelHikingMap"}
};
var feature = new Feature(lineString, table);
return Ok(new FeatureCollection(new Collection<IFeature> { feature }));
return Ok(new FeatureCollection{ feature });
}

private static ProfileType ConvertProfile(string type)
Expand Down Expand Up @@ -124,7 +123,7 @@ private async Task<Coordinate> GetGeographicPosition(string position)
var lat = double.Parse(splitted.First());
var lng = double.Parse(splitted.Last());
var elevation = await _elevationDataStorage.GetElevation(position.ToCoordinate());
return new Coordinate(lng, lat, elevation);
return new CoordinateZ(lng, lat, elevation);
}

/// <summary>
Expand All @@ -137,14 +136,14 @@ private async Task<Coordinate> GetGeographicPosition(string position)
/// <returns></returns>
private LineString GetDenseStraightLine(Coordinate from, Coordinate to)
{
var itmFrom = _wgs84ItmMathTransform.Transform(from);
var itmTo = _wgs84ItmMathTransform.Transform(to);
var samples = (int)Math.Min((itmFrom).Distance(itmTo) / 30, 30);
var itmFrom = _wgs84ItmMathTransform.Transform(from.X, from.Y);
var itmTo = _wgs84ItmMathTransform.Transform(to.X, to.Y);
var samples = (int)Math.Min(new Point(itmFrom.x, itmFrom.y).Distance(new Point(itmTo.x, itmTo.y)) / 30, 30);
if (samples == 0)
{
return _geometryFactory.CreateLineString(new[] {from, to}) as LineString;
}
var coordinates = Enumerable.Range(0, samples + 1).Select(s => new Coordinate(
var coordinates = Enumerable.Range(0, samples + 1).Select(s => new CoordinateZ(
(to.X - from.X) * s / samples + from.X,
(to.Y - from.Y) * s / samples + from.Y,
0)
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Converters;
using IsraelHiking.API.Converters;
using IsraelHiking.API.Converters.CoordinatesParsers;
using IsraelHiking.Common;
using IsraelHiking.Common.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Text.RegularExpressions;

namespace IsraelHiking.API.Converters.CoordinatesParsers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Text.RegularExpressions;

namespace IsraelHiking.API.Converters.CoordinatesParsers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Text.RegularExpressions;

namespace IsraelHiking.API.Converters.CoordinatesParsers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;

namespace IsraelHiking.API.Converters.CoordinatesParsers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Text.RegularExpressions;

namespace IsraelHiking.API.Converters.CoordinatesParsers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Text.RegularExpressions;

namespace IsraelHiking.API.Converters.CoordinatesParsers
Expand Down
7 changes: 3 additions & 4 deletions IsraelHiking.API/Converters/CoordinatesParsers/UtmParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Executors;
using IsraelHiking.API.Executors;
using NetTopologySuite.Geometries;
using ProjNet.CoordinateSystems.Transformations;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -46,8 +45,8 @@ protected override Coordinate GetCoordinates(Match itmMatch)
}
if (easting >= 100000 && easting <= 300000)
{
var transformed = _itmWgs84MathTransform.Transform(new Coordinate(easting, northing));
return transformed;
var transformed = _itmWgs84MathTransform.Transform(easting, northing);
return new Coordinate(transformed.x, transformed.y);
}
return null;
}
Expand Down
23 changes: 11 additions & 12 deletions IsraelHiking.API/Converters/GpxGeoJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.API.Gpx;
using IsraelHiking.API.Gpx;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
Expand Down Expand Up @@ -48,21 +47,21 @@ public GpxFile ToGpx(FeatureCollection collection)
{
var gpx = new GpxFile
{
Metadata = new GpxMetadata(collection.Features.FirstOrDefault(f => f.Attributes.Exists(CREATOR))
Metadata = new GpxMetadata(collection.FirstOrDefault(f => f.Attributes.Exists(CREATOR))
?.Attributes[CREATOR]?.ToString() ?? GpxDataContainerConverter.ISRAEL_HIKING_MAP + "_geojson")
};
gpx.Waypoints.AddRange(collection.Features.Where(f => f.Geometry is Point)
gpx.Waypoints.AddRange(collection.Where(f => f.Geometry is Point)
.Select(CreateWaypoint)
.Union(collection.Features.Where(f => f.Geometry is MultiPoint)
.Union(collection.Where(f => f.Geometry is MultiPoint)
.SelectMany(CreateWayPointsFromMultiPoint))
.ToList());
gpx.Routes.AddRange(collection.Features.Where(f => f.Geometry is LineString)
gpx.Routes.AddRange(collection.Where(f => f.Geometry is LineString)
.Select(CreateRouteFromLineString)
.Union(collection.Features.Where(f => f.Geometry is Polygon).Select(CreateRouteFromPolygon))
.Union(collection.Features.Where(f => f.Geometry is MultiPolygon)
.Union(collection.Where(f => f.Geometry is Polygon).Select(CreateRouteFromPolygon))
.Union(collection.Where(f => f.Geometry is MultiPolygon)
.SelectMany(CreateRoutesFromMultiPolygon))
.ToList());
gpx.Tracks.AddRange(collection.Features.Where(f => f.Geometry is MultiLineString)
gpx.Tracks.AddRange(collection.Where(f => f.Geometry is MultiLineString)
.SelectMany(CreateTracksFromMultiLineString)
.ToList());
gpx.UpdateBounds();
Expand All @@ -74,8 +73,8 @@ private Coordinate CreateGeoPosition(GpxWaypoint waypoint)
double lat = waypoint.Latitude;
double lon = waypoint.Longitude;
return waypoint.ElevationInMeters.HasValue
? new Coordinate(lon, lat, (double)waypoint.ElevationInMeters)
: new Coordinate(lon, lat, double.NaN);
? new CoordinateZ(lon, lat, (double)waypoint.ElevationInMeters)
: new CoordinateZ(lon, lat, double.NaN);
}

private GpxWaypoint CreateWaypoint(IFeature pointFeature)
Expand Down Expand Up @@ -225,7 +224,7 @@ private IAttributesTable CreateProperties(string name, string description)
private IAttributesTable CreateMultiLineProperties(string name, string creator, string description)
{
var table = CreateProperties(name, description);
table.AddAttribute(CREATOR, creator);
table.Add(CREATOR, creator);
return table;
}

Expand Down
9 changes: 4 additions & 5 deletions IsraelHiking.API/Converters/OsmGeoJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using IsraelHiking.Common;
using IsraelHiking.Common;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.Operation.Union;
Expand Down Expand Up @@ -49,7 +48,7 @@ public Feature ToGeoJson(ICompleteOsmGeo completeOsmGeo)
return null;
}
var properties = ConvertTags(way);
properties.AddAttribute(FeatureAttributes.POI_OSM_NODES, way.Nodes.Select(n => n.Id).ToArray());
properties.Add(FeatureAttributes.POI_OSM_NODES, way.Nodes.Select(n => n.Id).ToArray());
var geometry = GetGeometryFromNodes(way.Nodes);
return new Feature(geometry, properties);
case OsmGeoType.Relation:
Expand Down Expand Up @@ -79,7 +78,7 @@ private IAttributesTable ConvertTags(ICompleteOsmGeo osmObject)

private Coordinate ConvertNode(Node node)
{
return new Coordinate(node.Longitude ?? 0, node.Latitude ?? 0, double.NaN);
return new CoordinateZ(node.Longitude ?? 0, node.Latitude ?? 0, double.NaN);
}

private List<Geometry> GetGeometriesFromWays(IEnumerable<CompleteWay> ways)
Expand Down Expand Up @@ -171,7 +170,7 @@ private List<Polygon> MergePolygons(List<Polygon> polygons)
}
try
{
var merged = UnaryUnionOp.Union(polygons.Cast<IGeometry>().ToList());
var merged = UnaryUnionOp.Union(polygons.Cast<Geometry>().ToList());
if (merged is MultiPolygon multipolygon)
{
return multipolygon.Geometries.Cast<Polygon>().ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static SearchResultsPointOfInterest FromLatlng(LatLng latLng, string disp
References = new Reference[0],
DataContainer = new DataContainer(),
// HN TODO: add elevation?
FeatureCollection = new FeatureCollection(new Collection<IFeature> { new Feature(new Point(latLng.ToCoordinate()), new AttributesTable()) })
FeatureCollection = new FeatureCollection { new Feature(new Point(latLng.ToCoordinate()), new AttributesTable()) }
};
}

Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/Executors/FeaturesMergeExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private void AddAlternativeTitleToNatureReserves(List<Feature> features)
{
index++;
} while (natureReserveFeature.Attributes.Exists(FeatureAttributes.NAME + ":he" + index));
natureReserveFeature.Attributes.AddAttribute(FeatureAttributes.NAME + ":he" + index, alternativeTitle);
natureReserveFeature.Attributes.Add(FeatureAttributes.NAME + ":he" + index, alternativeTitle);
}
natureReserveFeature.SetTitles();
}
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Executors/GpxLoopsSplitterExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using System.Collections.Generic;
using System.Linq;

Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Executors/GpxProlongerExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.LinearReferencing;
using NetTopologySuite.Operation.Distance;
using System.Collections.Generic;
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Executors/ItmWgs84MathTransfromFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeoAPI.CoordinateSystems;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
using System.Collections.Generic;

Expand Down
Loading

0 comments on commit d4564ef

Please sign in to comment.