Skip to content

Commit

Permalink
Merge pull request #43 from davetimmins/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
davetimmins authored Oct 18, 2018
2 parents d8900f0 + 4411a00 commit 085189c
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solution = "./Anywhere.ArcGIS.sln";

var version = "1.8.0";
var version = "1.8.1";
var versionSuffix = Environment.GetEnvironmentVariable("VERSION_SUFFIX");

//////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 8 additions & 5 deletions src/Anywhere.ArcGIS/Anywhere.ArcGIS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@
<RepositoryUrl>https://github.com/davetimmins/Anywhere.ArcGIS</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>ArcGIS ArcGISServer ArcGISOnline Esri REST netstandard anywhere GIS Mapping Map Location GeoLocation OAuth</PackageTags>
<Version>1.8.0</Version>
<Version>1.8.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;UseAsyncSuffix</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibLog" Version="5.0.0" />
<PackageReference Include="LibLog" Version="5.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.1" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.0" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.0" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.3" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.3" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.3" />
<PackageReference Include="dotMorten.OmdGenerator" Version="0.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
82 changes: 74 additions & 8 deletions src/Anywhere.ArcGIS/Common/IGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,19 @@ public Extent GetExtent()
foreach (PointCollection path in Paths)
{
if (extent == null)
{
extent = path.CalculateExtent(SpatialReference);
}
else
{
extent = extent.Union(path.CalculateExtent(SpatialReference));
}
}

if (extent != null)
{
extent.SpatialReference = SpatialReference;
}
if (extent != null) extent.SpatialReference = SpatialReference;

return extent;
}
Expand Down Expand Up @@ -398,23 +406,43 @@ public Extent CalculateExtent(SpatialReference spatialReference)

foreach (var point in Points.Where(p => p != null))
{
if (point.X < x || double.IsNaN(x)) x = point.X;
if (point.X < x || double.IsNaN(x))
{
x = point.X;
}

if (point.Y < y || double.IsNaN(y)) y = point.Y;
if (point.Y < y || double.IsNaN(y))
{
y = point.Y;
}

if (point.X > x1 || double.IsNaN(x1)) x1 = point.X;
if (point.X > x1 || double.IsNaN(x1))
{
x1 = point.X;
}

if (point.Y > y1 || double.IsNaN(y1)) y1 = point.Y;
if (point.Y > y1 || double.IsNaN(y1))
{
y1 = point.Y;
}
}

if (double.IsNaN(x) || double.IsNaN(y) || double.IsNaN(x1) || double.IsNaN(y1))
{
return null;
}

return new Extent { XMin = x, YMin = y, XMax = x1, YMax = y1, SpatialReference = spatialReference };
}

public List<Point> Points
{
get { return this.Select(point => point != null ? new Point { X = point.First(), Y = point.Last() } : null).ToList(); }
get
{
return this.Select(point => point != null ? new Point { X = point.First(), Y = point.Last() } : null)
.Where(p => p != null)
.ToList();
}
}

public List<double[]> Clone()
Expand Down Expand Up @@ -452,11 +480,19 @@ public Extent GetExtent()
foreach (var ring in Rings.Where(r => r != null))
{
if (extent == null)
{
extent = ring.CalculateExtent(SpatialReference);
}
else
{
extent = extent.Union(ring.CalculateExtent(SpatialReference));
}
}

if (extent != null && extent.SpatialReference == null)
{
extent.SpatialReference = SpatialReference;
}
if (extent != null && extent.SpatialReference == null) extent.SpatialReference = SpatialReference;

return extent;
}
Expand Down Expand Up @@ -540,38 +576,68 @@ public Point GetCenter()

public Extent Union(Extent extent)
{
if (extent == null) extent = this;
if (extent == null)
{
extent = this;
}

if (!SpatialReference.Equals(extent.SpatialReference))
{
throw new ArgumentException("Spatial references must match for union operation.");
}

var envelope = new Extent { SpatialReference = SpatialReference ?? extent.SpatialReference };
if (double.IsNaN(XMin))
{
envelope.XMin = extent.XMin;
}
else if (!double.IsNaN(extent.XMin))
{
envelope.XMin = Math.Min(extent.XMin, XMin);
}
else
{
envelope.XMin = XMin;
}

if (double.IsNaN(XMax))
{
envelope.XMax = extent.XMax;
}
else if (!double.IsNaN(extent.XMax))
{
envelope.XMax = Math.Max(extent.XMax, XMax);
}
else
{
envelope.XMax = XMax;
}

if (double.IsNaN(YMin))
{
envelope.YMin = extent.YMin;
}
else if (!double.IsNaN(extent.YMin))
{
envelope.YMin = Math.Min(extent.YMin, YMin);
}
else
{
envelope.YMin = YMin;
}

if (double.IsNaN(YMax))
{
envelope.YMax = extent.YMax;
}
else if (!double.IsNaN(extent.YMax))
{
envelope.YMax = Math.Max(extent.YMax, YMax);
}
else
{
envelope.YMax = YMax;
}

return envelope;
}
Expand Down
24 changes: 20 additions & 4 deletions src/Anywhere.ArcGIS/Extensions/FeatureCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ public static class FeatureCollectionExtensions
public static List<Feature<IGeometry>> ToFeatures<TGeometry>(this FeatureCollection<TGeometry> featureCollection)
where TGeometry : IGeoJsonGeometry
{
if (featureCollection == null || featureCollection.Features == null || !featureCollection.Features.Any()) return null;
if (featureCollection == null || featureCollection.Features == null || !featureCollection.Features.Any())
{
return null;
}

var features = new List<Feature<IGeometry>>();

foreach (var geoJson in featureCollection.Features)
{
var geometry = geoJson.Geometry.ToGeometry(_typeMap[geoJson.Geometry.Type]());
if (geometry == null) continue;
if (geometry == null)
{
continue;
}

features.Add(new Feature<IGeometry> { Geometry = geometry, Attributes = geoJson.Properties });
}
Expand All @@ -53,15 +59,20 @@ public static List<Feature<IGeometry>> ToFeatures<TGeometry>(this FeatureCollect
public static FeatureCollection<IGeoJsonGeometry> ToFeatureCollection<TGeometry>(this List<Feature<TGeometry>> features)
where TGeometry : IGeometry
{
if (features == null || !features.Any()) return null;
if (features == null || !features.Any())
{
return null;
}

var featureCollection = new FeatureCollection<IGeoJsonGeometry> { Features = new List<GeoJsonFeature<IGeoJsonGeometry>>() };
if (features.First().Geometry.SpatialReference != null)
{
featureCollection.CoordinateReferenceSystem = new Crs
{
Type = "EPSG",
Properties = new CrsProperties { Wkid = (int)features.First().Geometry.SpatialReference.Wkid }
};
}

foreach (var feature in features)
{
Expand Down Expand Up @@ -96,11 +107,16 @@ public static List<Feature<T>> UpdateGeometries<T>(this List<Feature<T>> feature
{
var attr = i < features.Count ? features[i].Attributes : null;
var feature = new Feature<T> { Attributes = attr };
if (i < geometries.Count) feature.Geometry = geometries[i];
if (i < geometries.Count)
{
feature.Geometry = geometries[i];
}
result.Insert(i, feature);
}
if (geometries.Count > features.Count)
{
result.InsertRange(features.Count, geometries.Skip(features.Count).Select(g => new Feature<T> { Geometry = g }));
}

return result;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Anywhere.ArcGIS/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public static string UrlEncode(this string text)
/// <returns>Byte representation of the hex-encoded input</returns>
public static byte[] HexToBytes(this string hex)
{
if (string.IsNullOrWhiteSpace(hex)) return null;
if (string.IsNullOrWhiteSpace(hex))
{
return null;
}

int length = hex.Length;

Expand Down
2 changes: 1 addition & 1 deletion src/Anywhere.ArcGIS/Operation/PortalResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ArcGISError

public override string ToString()
{
return string.Format("Code {0}: {1}.{2}\n{3}", Code, Message, Description, Details == null ? "" : string.Join(" ", Details));
return string.Format("Code {0}: {1}. {2}\n{3}", Code, Message, Description, Details == null ? "" : string.Join(" ", Details));
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/Anywhere.ArcGIS/Operation/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ public string RelativeUrl

public string BuildAbsoluteUrl(string rootUrl)
{
if (string.IsNullOrWhiteSpace(rootUrl)) throw new ArgumentNullException("rootUrl", "rootUrl is null.");
if (string.IsNullOrWhiteSpace(rootUrl))
{
throw new ArgumentNullException("rootUrl", "rootUrl is null.");
}

return IsFederated
? (DontForceHttps ? rootUrl.Replace("sharing/rest/", "").Replace("sharing/", "") + "sharing/rest/" : rootUrl.Replace("http://", "https://").Replace("sharing/rest/", "").Replace("sharing/", "") + "sharing/rest/") + RelativeUrl.Replace("tokens/", "")
Expand Down Expand Up @@ -202,7 +205,10 @@ public string RelativeUrl

public string BuildAbsoluteUrl(string rootUrl)
{
if (string.IsNullOrWhiteSpace(rootUrl)) throw new ArgumentNullException("rootUrl", "rootUrl is null.");
if (string.IsNullOrWhiteSpace(rootUrl))
{
throw new ArgumentNullException("rootUrl", "rootUrl is null.");
}

return (DontForceHttps ?
rootUrl.Replace("sharing/rest/", "").Replace("sharing/", "") + "sharing/rest/" :
Expand Down
2 changes: 1 addition & 1 deletion src/Anywhere.ArcGIS/TokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TokenProvider : ITokenProvider, IDisposable
/// <param name="referer">Referer url to use for the token generation</param>
/// <param name="cryptoProvider">Used to encrypt the token reuqest. If not set it will use the default from CryptoProviderFactory</param>
public TokenProvider(string rootUrl, string username, string password, ISerializer serializer = null, string referer = "", ICryptoProvider cryptoProvider = null, Func<HttpClient> httpClientFunc = null)
: this (() => LogProvider.For<TokenProvider>(), rootUrl, username, password, serializer, referer, cryptoProvider)
: this (() => LogProvider.For<TokenProvider>(), rootUrl, username, password, serializer, referer, cryptoProvider, httpClientFunc)
{ }

internal TokenProvider(Func<ILog> log, string rootUrl, string username, string password, ISerializer serializer = null, string referer = "", ICryptoProvider cryptoProvider = null, Func<HttpClient> httpClientFunc = null)
Expand Down
4 changes: 2 additions & 2 deletions tests/Anywhere.ArcGIS.Test.Integration/ArcGISGatewayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public async Task QueryOrderByIsHonored(string rootUrl, string relativeUrl, stri
}

[Theory]
[InlineData("http://services.arcgis.com/hMYNkrKaydBeWRXE/arcgis", "TestReturnExtentOnly/FeatureServer/0")]
[InlineData("https://services.arcgis.com/hMYNkrKaydBeWRXE/arcgis", "TestReturnExtentOnly/FeatureServer/0")]
public async Task CanQueryExtent(string rootUrl, string relativeUrl)
{
var gateway = new PortalGateway(rootUrl);
Expand All @@ -456,7 +456,7 @@ public async Task CanQueryExtent(string rootUrl, string relativeUrl)
}

[Theory]
[InlineData("http://services.arcgis.com/hMYNkrKaydBeWRXE/arcgis", "TestReturnExtentOnly/FeatureServer/0", 1, 2)]
[InlineData("https://services.arcgis.com/hMYNkrKaydBeWRXE/arcgis", "TestReturnExtentOnly/FeatureServer/0", 1, 2)]
public async Task CanPagePointQuery(string rootUrl, string relativeUrl, int start, int numberToReturn)
{
var gateway = new PortalGateway(rootUrl);
Expand Down

0 comments on commit 085189c

Please sign in to comment.