Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
packages
bin
obj
obj
.vs
*.user
*.bak
1 change: 1 addition & 0 deletions TurfCS/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down
4 changes: 3 additions & 1 deletion TurfCS/Joins.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GeoJSON.Net;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down Expand Up @@ -36,7 +38,7 @@ static public bool Inside(Feature point, Feature poly)
if (type == GeoJSONObjectType.Polygon)
return Inside_(Turf.GetCoord(point), new List<Polygon>() { (Polygon)poly.Geometry });
else if (type == GeoJSONObjectType.MultiPolygon)
return Inside_(Turf.GetCoord(point), ((MultiPolygon)poly.Geometry).Coordinates);
return Inside_(Turf.GetCoord(point), ((MultiPolygon)poly.Geometry).Coordinates.ToList());
else
throw new Exception("2nd argument must be Polygon or MultiPolygon");
}
Expand Down
7 changes: 4 additions & 3 deletions TurfCS/Measurement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GeoJSON.Net;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down Expand Up @@ -564,7 +565,7 @@ public static double LineDistance(IGeoJSONObject line, string units = "kilometer

if (geometry.Type == GeoJSONObjectType.LineString)
{
return Length(((LineString)geometry).Coordinates, units);
return Length(((LineString)geometry).Coordinates.ToList(), units);
}
else if (geometry.Type == GeoJSONObjectType.Polygon || geometry.Type == GeoJSONObjectType.MultiLineString)
{
Expand All @@ -574,7 +575,7 @@ public static double LineDistance(IGeoJSONObject line, string units = "kilometer
for (var i = 0; i < lines.Count; i++)
{
var points = ((LineString)lines[i]).Coordinates;
d += Length(points, units);
d += Length(points.ToList(), units);
}
return d;
}
Expand All @@ -588,7 +589,7 @@ public static double LineDistance(IGeoJSONObject line, string units = "kilometer
for (var j = 0; j < lines.Count; j++)
{
var points = ((LineString)lines[j]).Coordinates;
d += Length(points, units);
d += Length(points.ToList(), units);
}
}
return d;
Expand Down
5 changes: 3 additions & 2 deletions TurfCS/Meta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GeoJSON.Net;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down Expand Up @@ -110,7 +111,7 @@ static private void CoordEach(IGeometryObject layer, Action<GeographicPosition>
else if (geometry.Type == GeoJSONObjectType.LineString || geometry.Type == GeoJSONObjectType.MultiPoint)
{
var coords = geometry.Type == GeoJSONObjectType.LineString ?
((LineString)layer).Coordinates :
((LineString)layer).Coordinates.ToList() :
((MultiPoint)layer).Coordinates.Select(x => x.Coordinates).ToList();
for (var j = 0; j < coords.Count; j++) callback((GeographicPosition)coords[j]);
}
Expand Down Expand Up @@ -188,7 +189,7 @@ static public object CoordReduce(IGeoJSONObject layer, Func<object, GeographicPo
* // props is equal to { foo: 1}
* });
*/
static public void PropEach(IGeoJSONObject layer, Action<Dictionary<string, object>, int> callback)
static public void PropEach(IGeoJSONObject layer, Action<IDictionary<string, object>, int> callback)
{
if (layer.Type == GeoJSONObjectType.FeatureCollection)
{
Expand Down
5 changes: 2 additions & 3 deletions TurfCS/Misc.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using GeoJSON.Net;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down
26 changes: 0 additions & 26 deletions TurfCS/Properties/AssemblyInfo.cs

This file was deleted.

1 change: 1 addition & 0 deletions TurfCS/Tin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using GeographicPosition= GeoJSON.Net.Geometry.Position;

namespace TurfCS
{
Expand Down
54 changes: 8 additions & 46 deletions TurfCS/TurfCS.csproj
Original file line number Diff line number Diff line change
@@ -1,52 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{95641025-2C48-4B98-9345-97D91AB40BBA}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>TurfCS</RootNamespace>
<AssemblyName>TurfCS</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Meta.cs" />
<Compile Include="Joins.cs" />
<Compile Include="Tin.cs" />
<Compile Include="Measurement.cs" />
<Compile Include="Assertions.cs" />
<Compile Include="Classification.cs" />
<Compile Include="Misc.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="GeoJSON.Net">
<HintPath>..\packages\GeoJSON.Net.0.1.51\lib\portable-net40+sl5+wp80+win8+wpa81\GeoJSON.Net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="GeoJSON.Net" Version="1.4.1" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>

</Project>
5 changes: 0 additions & 5 deletions TurfCS/packages.config

This file was deleted.

72 changes: 36 additions & 36 deletions TurfCSTest/AssertionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
using System;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
using NUnit.Framework;
using TurfCS;
using Assert= NUnit.Framework.Legacy.ClassicAssert;

namespace TurfCSTest
{
[TestFixture()]
public class AssertionsTest
{
[Test()]
public void Bbox()
{
var fc = JsonConvert.DeserializeObject<FeatureCollection>(Tools.GetResource("bbox.FeatureCollection.geojson"));
var pt = JsonConvert.DeserializeObject<Feature>(Tools.GetResource("bbox.Point.geojson"));
var line = JsonConvert.DeserializeObject<LineString>(Tools.GetResource("bbox.LineString.geojson"));
var poly = JsonConvert.DeserializeObject<Feature>(Tools.GetResource("bbox.Polygon.geojson"));
var multiLine = JsonConvert.DeserializeObject<MultiLineString>(Tools.GetResource("bbox.MultiLineString.geojson"));
var multiPoly = JsonConvert.DeserializeObject<MultiPolygon>(Tools.GetResource("bbox.MultiPolygon.geojson"));
public class AssertionsTest
{
[Test()]
public void Bbox()
{
var fc = JsonConvert.DeserializeObject<FeatureCollection>(Tools.GetResource("bbox.FeatureCollection.geojson"));
var pt = JsonConvert.DeserializeObject<Feature>(Tools.GetResource("bbox.Point.geojson"));
var line = JsonConvert.DeserializeObject<LineString>(Tools.GetResource("bbox.LineString.geojson"));
var poly = JsonConvert.DeserializeObject<Feature>(Tools.GetResource("bbox.Polygon.geojson"));
var multiLine = JsonConvert.DeserializeObject<MultiLineString>(Tools.GetResource("bbox.MultiLineString.geojson"));
var multiPoly = JsonConvert.DeserializeObject<MultiPolygon>(Tools.GetResource("bbox.MultiPolygon.geojson"));

// FeatureCollection
// FeatureCollection
var fcExtent = Turf.Bbox(fc);
Assert.AreEqual(fcExtent[0], 20);
Assert.AreEqual(fcExtent[1], -10);
Assert.AreEqual(fcExtent[2], 130);
Assert.AreEqual(fcExtent[3], 4);

// Point
var ptExtent = Turf.Bbox(pt);
// Point
var ptExtent = Turf.Bbox(pt);
Assert.AreEqual(ptExtent[0], 102);
Assert.AreEqual(ptExtent[1], 0.5);
Assert.AreEqual(ptExtent[2], 102);
Assert.AreEqual(ptExtent[3], 0.5);

// Line
var lineExtent = Turf.Bbox(line);
// Line
var lineExtent = Turf.Bbox(line);
Assert.AreEqual(lineExtent[0], 102);
Assert.AreEqual(lineExtent[1], -10);
Assert.AreEqual(lineExtent[2], 130);
Assert.AreEqual(lineExtent[3], 4);

// Polygon
var polyExtent = Turf.Bbox(poly);
// Polygon
var polyExtent = Turf.Bbox(poly);
Assert.AreEqual(polyExtent[0], 100);
Assert.AreEqual(polyExtent[1], 0);
Assert.AreEqual(polyExtent[2], 101);
Assert.AreEqual(polyExtent[3], 1);

// MultiLineString
var multiLineExtent = Turf.Bbox(multiLine);
// MultiLineString
var multiLineExtent = Turf.Bbox(multiLine);
Assert.AreEqual(multiLineExtent[0], 100);
Assert.AreEqual(multiLineExtent[1], 0);
Assert.AreEqual(multiLineExtent[2], 103);
Assert.AreEqual(multiLineExtent[3], 3);

// MultiPolygon
var multiPolyExtent = Turf.Bbox(multiPoly);
// MultiPolygon
var multiPolyExtent = Turf.Bbox(multiPoly);
Assert.AreEqual(multiPolyExtent[0], 100);
Assert.AreEqual(multiPolyExtent[1], 0);
Assert.AreEqual(multiPolyExtent[2], 103);
Assert.AreEqual(multiPolyExtent[3], 3);
}
}

[Test()]
public void Circle()
{
var center = Turf.Point(new double[] { -75.343, 39.984 });
double radius = 5;
int steps = 10;
[Test()]
public void Circle()
{
var center = Turf.Point(new double[] { -75.343, 39.984 });
double radius = 5;
int steps = 10;

var polygon = Turf.Circle(center, radius, steps, "kilometers");
var point1 = Turf.Destination(center, radius - 1, 45, "kilometers");
var point2 = Turf.Destination(center, radius + 1, 135, "kilometers");
var polygon = Turf.Circle(center, radius, steps, "kilometers");
var point1 = Turf.Destination(center, radius - 1, 45, "kilometers");
var point2 = Turf.Destination(center, radius + 1, 135, "kilometers");

Assert.AreEqual(Turf.Inside(point1, polygon), true, "point is inside the polygon");
Assert.AreEqual(Turf.Inside(point2, polygon), false, "point is outside the polygon");
}
}
}
}
}
3 changes: 3 additions & 0 deletions TurfCSTest/ClassificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TurfCS;
using GeographicPosition= GeoJSON.Net.Geometry.Position;
using Assert= NUnit.Framework.Legacy.ClassicAssert;


namespace TurfCSTest
{
Expand Down
2 changes: 2 additions & 0 deletions TurfCSTest/JoinsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using GeoJSON.Net.Feature;
using TurfCS;
using System.Linq;
using GeographicPosition= GeoJSON.Net.Geometry.Position;
using Assert= NUnit.Framework.Legacy.ClassicAssert;

namespace TurfCSTest
{
Expand Down
2 changes: 2 additions & 0 deletions TurfCSTest/MeasurementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TurfCS;
using GeographicPosition= GeoJSON.Net.Geometry.Position;
using Assert= NUnit.Framework.Legacy.ClassicAssert;

namespace TurfCSTest
{
Expand Down
5 changes: 3 additions & 2 deletions TurfCSTest/MetaTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using GeoJSON.Net;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using NUnit.Framework;
using TurfCS;
using GeographicPosition= GeoJSON.Net.Geometry.Position;
using Assert= NUnit.Framework.Legacy.ClassicAssert;

namespace TurfCSTest
{
Expand Down Expand Up @@ -120,7 +121,7 @@ public void CoordEach()
[Test()]
public void PropEach()
{
Action<Dictionary<string, object>, int> callback = (Dictionary<string, object>obj, int i) =>
Action<IDictionary<string, object>, int> callback = (IDictionary<string, object>obj, int i) =>
{
Assert.AreEqual(obj, new Dictionary<string, object>() { { "a", 1 } });
Assert.AreEqual(i, 0);
Expand Down
1 change: 1 addition & 0 deletions TurfCSTest/TinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TurfCS;
using Assert= NUnit.Framework.Legacy.ClassicAssert;

namespace TurfCSTest
{
Expand Down
2 changes: 1 addition & 1 deletion TurfCSTest/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static string GetResource(string resourceName)
{
string path = Names.First(x => x.EndsWith("." + resourceName, StringComparison.CurrentCultureIgnoreCase));
var stream = Assembly.GetManifestResourceStream(path);
using (var reader = new StreamReader(stream, Encoding.UTF8))
using (var reader = new StreamReader(stream!, Encoding.UTF8))
{
return reader.ReadToEnd();
}
Expand Down
Loading