Skip to content

Commit

Permalink
Modernized codebase and added build action.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivk committed Apr 25, 2024
1 parent bc511be commit 96279cc
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 61 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-and-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: .NET Core

on:
push:
branches: [ develop ]

jobs:
build-and-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Setup .NET Core 6.
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore packages.
run: dotnet restore
- name: Build all projects.
run: dotnet build --configuration Release --no-restore

- name: Unittests.
run: dotnet test
working-directory: ./test/OpenLR.Test/

- name: Nuget Pack
run: dotnet pack -c release
working-directory: ./src/OpenLR/
- name: Nuget Pack
run: dotnet pack -c release
working-directory: ./src/OpenLR.Geo/

# - name: Nuget push
# run: dotnet nuget push **/*.nupkg --skip-duplicate -k ${{ secrets.NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json
# working-directory: ./src/
19 changes: 19 additions & 0 deletions OpenLR.Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!--- Package information, Version -->
<PropertyGroup>
<PackageVersion>1.1.1-pre11=2</PackageVersion>
<NeutralLanguage>en</NeutralLanguage>
<Description>OpenLR library for .NET.</Description>
<Copyright>Itinero BV</Copyright>
<PackageProjectUrl>https://github.com/Itinero/OpenLR</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/itinero/OpenLR/blob/develop/LICENSE.md</PackageLicenseUrl>
<PackageIconUrl>http://www.itinero.tech/logos/openlr_logo64.png</PackageIconUrl>
<RepositoryUrl>https://github.com/Itinero/OpenLR</RepositoryUrl>
<PackageTags>openlr, routing</PackageTags>
<RepositoryType>git</RepositoryType>
<Authors>Itinero Contributors</Authors>
<Company>Itinero BV</Company>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion OpenLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
LICENSE.md = LICENSE.md
README.md = README.md
SharedAssemblyVersion.cs = SharedAssemblyVersion.cs
OpenLR.Common.props = OpenLR.Common.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{082AB082-0910-4B42-AC57-330BE7C57771}"
Expand Down
4 changes: 0 additions & 4 deletions SharedAssemblyVersion.cs

This file was deleted.

13 changes: 6 additions & 7 deletions src/OpenLR.Geo/NtsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using GeoAPI.Geometries;
using Itinero;
using Itinero.Attributes;
using Itinero.Data.Network;
Expand Down Expand Up @@ -207,18 +206,18 @@ public static FeatureCollection ToFeatures(this OpenLR.Model.Locations.PointAlon
var features = new FeatureCollection();

var first = location.First.ToFeature();
first.Attributes.AddAttribute("positive_offset_percentage", location.PositiveOffsetPercentage == null ? string.Empty :
first.Attributes.Add("positive_offset_percentage", location.PositiveOffsetPercentage == null ? string.Empty :
location.PositiveOffsetPercentage.ToInvariantString());
first.Attributes.AddAttribute("orientation", location.Orientation == null ? string.Empty :
first.Attributes.Add("orientation", location.Orientation == null ? string.Empty :
location.Orientation.ToInvariantString());
first.Attributes.AddAttribute("side_of_road", location.SideOfRoad == null ? string.Empty :
first.Attributes.Add("side_of_road", location.SideOfRoad == null ? string.Empty :
location.SideOfRoad.ToInvariantString());
first.Attributes.AddAttribute("type", "first");
first.Attributes.Add("type", "first");
features.Add(first);
var last = location.Last.ToFeature();
last.Attributes.AddAttribute("negative_offset_percentage", location.NegativeOffsetPercentage == null ? string.Empty :
last.Attributes.Add("negative_offset_percentage", location.NegativeOffsetPercentage == null ? string.Empty :
location.NegativeOffsetPercentage.ToInvariantString());
last.Attributes.AddAttribute("type", "last");
last.Attributes.Add("type", "last");
features.Add(last);

return features;
Expand Down
14 changes: 4 additions & 10 deletions src/OpenLR.Geo/OpenLR.Geo.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../OpenLR.Common.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>OpenLR.Geo</AssemblyName>
<PackageId>OpenLR.Geo</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand All @@ -9,22 +11,14 @@
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<LangVersion>default</LangVersion>
<PackageVersion />
<Title>OpenLR.Geo</Title>
<Authors>Itinero BV</Authors>
<Description>OpenLR library for .NET.</Description>
<Copyright>Itinero BV</Copyright>
<PackageProjectUrl>https://github.com/Itinero/OpenLR</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/itinero/OpenLR/blob/develop/LICENSE.md</PackageLicenseUrl>
<PackageIconUrl>http://www.itinero.tech/logos/openlr_logo64.png</PackageIconUrl>
<RepositoryUrl>https://github.com/Itinero/OpenLR</RepositoryUrl>
<PackageTags>openlr, routing, NTS</PackageTags>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OpenLR\OpenLR.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Itinero.Geo" Version="1.6.0-pre025" />
<PackageReference Include="Itinero.Geo" Version="1.6.0-pre037" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLR/LocationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public static void AdjustToValidPoints(this ReferencedLine line, Coder coder)
{ // already valid.
return;
}
if (line.Vertices.Length > 2) { return; } // line was already adjusted.
// if (line.Vertices.Length > 2) { return; } // line was already adjusted.

var vertex1 = line.Vertices[0];
var vertex2 = line.Vertices[1];
Expand Down
17 changes: 4 additions & 13 deletions src/OpenLR/OpenLR.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../OpenLR.Common.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>OpenLR</AssemblyName>
<PackageId>OpenLR</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand All @@ -9,23 +11,12 @@
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<LangVersion>default</LangVersion>
<PackageVersion />
<Title>OpenLR</Title>
<Description>OpenLR library for .NET.</Description>
<Copyright>Itinero BV</Copyright>
<PackageProjectUrl>https://github.com/Itinero/OpenLR</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/itinero/OpenLR/blob/develop/LICENSE.md</PackageLicenseUrl>
<PackageIconUrl>http://www.itinero.tech/logos/openlr_logo64.png</PackageIconUrl>
<RepositoryUrl>https://github.com/Itinero/OpenLR</RepositoryUrl>
<PackageTags>openlr, routing</PackageTags>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\SharedAssemblyVersion.cs" Link="Properties\SharedAssemblyVersion.cs" />
<PackageReference Include="Itinero" Version="1.6.0-pre037" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Itinero" Version="1.6.0-pre025" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion test/OpenLR.Test.Functional/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace OpenLR.Test.Functional
{
public static class Download
{
public static string NetherlandsPbf = "http://files.itinero.tech/data/OSM/planet/europe/netherlands-latest.osm.pbf";
public static string NetherlandsPbf = "http://planet.anyways.eu/planet/europe/netherlands/netherlands-latest.osm.pbf";

/// <summary>
/// Downloads all test-data.
Expand Down
3 changes: 2 additions & 1 deletion test/OpenLR.Test.Functional/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Coordinate = Itinero.LocalGeo.Coordinate;

namespace OpenLR.Test.Functional
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public static Tuple<Coordinate, IAttributesTable>[] PointsFromGeoJsonFile(string
{
var coordinates = new List<Tuple<Coordinate, IAttributesTable>>();
var features = FromGeoJsonFile(geoJsonFile);
foreach(var feature in features.Features)
foreach(var feature in features)
{
if (feature.Geometry is Point)
{
Expand Down
2 changes: 1 addition & 1 deletion test/OpenLR.Test.Functional/NWB/Netherlands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void TestAll(RouterDb routerDb)
public static void TestEncodeDecodeRoutes(RouterDb routerDb)
{
var coder = new Coder(routerDb, new NWBCoderProfile(routerDb.GetSupportedVehicle("nwb.car")));
var features = Extensions.FromGeoJsonFile(Path.Combine(".", "Data", "line_locations.geojson")).Features.ToList();
var features = Extensions.FromGeoJsonFile(Path.Combine(".", "Data", "line_locations.geojson")).ToList();

for (var i = 0; i < features.Count; i++)
{
Expand Down
8 changes: 4 additions & 4 deletions test/OpenLR.Test.Functional/OpenLR.Test.Functional.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>OpenLR.Test.Functional</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>OpenLR.Test.Functional</PackageId>
Expand Down Expand Up @@ -39,9 +39,9 @@
<ProjectReference Include="..\..\src\OpenLR\OpenLR.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Itinero.IO.Osm" Version="1.6.0-pre025" />
<PackageReference Include="Itinero.IO.Shape" Version="1.6.0-pre025" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="1.15.5" />
<PackageReference Include="Itinero.IO.Osm" Version="1.6.0-pre036" />
<PackageReference Include="Itinero.IO.Shape" Version="1.6.0-pre036" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="4.0.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="Serilog">
<Version>2.9.0</Version>
Expand Down
4 changes: 2 additions & 2 deletions test/OpenLR.Test.Functional/Osm/Netherlands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void TestEncodeDecodeRoutes(RouterDb routerDb)
var features = Extensions.FromGeoJsonFile(Path.Combine(".", "Data", "line_locations.geojson"));

var i = 0;
foreach (var feature in features.Features)
foreach (var feature in features)
{
var points = new List<Coordinate>();
var coordinates = (feature.Geometry as NetTopologySuite.Geometries.LineString).Coordinates;
Expand All @@ -102,7 +102,7 @@ public static void TestEncodeDecodeRoutes(RouterDb routerDb)
points.Add(new Coordinate((float)c.Y, (float)c.X));
}

Log.Logger.Verbose($"Testing line location {i + 1}/{features.Features.Count}" +
Log.Logger.Verbose($"Testing line location {i + 1}/{features.Count}" +
$" @ {points[0].ToInvariantString()}->{points[1].ToInvariantString()}");
TestEncodeDecoderRoute(coder, points.ToArray());

Expand Down
14 changes: 7 additions & 7 deletions test/OpenLR.Test/AssertGeo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using GeoAPI.Geometries;
using NetTopologySuite.Algorithm.Distance;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using NUnit.Framework;

Expand All @@ -38,11 +38,11 @@ public static class AssertGeo
/// <param name="expected"></param>
/// <param name="actual"></param>
/// <param name="delta"></param>
public static void AreEqual(IGeometry expected, IGeometry actual, double delta)
public static void AreEqual(Geometry expected, Geometry actual, double delta)
{
if(expected is ILineString && actual is ILineString)
if(expected is LineString && actual is LineString)
{
AssertGeo.AreEqual(expected as ILineString, actual as ILineString, delta);
AssertGeo.AreEqual(expected as LineString, actual as LineString, delta);
}
//else if (expected is ILineString && actual is ILineString)
//{
Expand All @@ -56,7 +56,7 @@ public static void AreEqual(IGeometry expected, IGeometry actual, double delta)
/// <param name="expected"></param>
/// <param name="actual"></param>
/// <param name="delta"></param>
public static void AreEqual(ILineString expected, ILineString actual, double delta)
public static void AreEqual(LineString expected, LineString actual, double delta)
{
var distance = new PointPairDistance();
foreach(Coordinate actualCoordinate in actual.Coordinates)
Expand All @@ -79,8 +79,8 @@ public static void AreEqual(ILineString expected, ILineString actual, double del
public static void AreEqual(string geoJsonActual, string geoJson, double delta)
{
var geoJsonReader = new GeoJsonReader();
var actual = geoJsonReader.Read<IGeometry>(geoJsonActual);
var expected = geoJsonReader.Read<IGeometry>(geoJson);
var actual = geoJsonReader.Read<Geometry>(geoJsonActual);
var expected = geoJsonReader.Read<Geometry>(geoJson);

AssertGeo.AreEqual(actual, expected, delta);
}
Expand Down
3 changes: 2 additions & 1 deletion test/OpenLR.Test/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Coordinate = Itinero.LocalGeo.Coordinate;

namespace OpenLR.Test
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public static Tuple<Coordinate, IAttributesTable>[] PointsFromGeoJsonFile(string
{
var coordinates = new List<Tuple<Coordinate, IAttributesTable>>();
var features = FromGeoJsonFile(geoJsonFile);
foreach(var feature in features.Features)
foreach(var feature in features)
{
if (feature.Geometry is Point)
{
Expand Down
10 changes: 5 additions & 5 deletions test/OpenLR.Test/OpenLR.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>OpenLR.Test</AssemblyName>
<PackageId>OpenLR.Test</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -22,10 +22,10 @@
<EmbeddedResource Include="test-data\networks\network3.geojson" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="1.15.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System.Xml" />
Expand Down
7 changes: 4 additions & 3 deletions test/OpenLR.Test/TestNetworkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Itinero.Geo;
using Itinero.Data.Network.Restrictions;
using Itinero;
using Coordinate = Itinero.LocalGeo.Coordinate;

namespace OpenLR.Test
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public static void LoadTestNetwork(this RouterDb db, string geoJson)
var geoJsonReader = new NetTopologySuite.IO.GeoJsonReader();
var features = geoJsonReader.Read<FeatureCollection>(geoJson);

foreach (var feature in features.Features)
foreach (var feature in features)
{
if (feature.Geometry is Point)
{
Expand All @@ -74,7 +75,7 @@ public static void LoadTestNetwork(this RouterDb db, string geoJson)
}
}

foreach (var feature in features.Features)
foreach (var feature in features)
{
if (feature.Geometry is LineString)
{
Expand Down Expand Up @@ -138,7 +139,7 @@ public static void LoadTestNetwork(this RouterDb db, string geoJson)
}
}

foreach (var feature in features.Features)
foreach (var feature in features)
{
if (feature.Geometry is LineString &&
feature.Attributes.Contains("restriction", "yes"))
Expand Down

0 comments on commit 96279cc

Please sign in to comment.