Skip to content

Commit 32058de

Browse files
author
Jörg Battermann
committed
Making big steps towards being finished
1 parent 5dc03f0 commit 32058de

26 files changed

Lines changed: 490 additions & 297 deletions

src/GeoJSON.Net/Converters/GeometryConverter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace GeoJSON.Net.Converters
2525
using SimpleGeo.Net.Helpers.Json.Converters;
2626

2727
/// <summary>
28-
/// Defines the Geometry type. Converts to/from a SimpleGeo 'geometry' field
28+
/// Defines the GeometryObject type. Converts to/from a SimpleGeo 'geometry' field
2929
/// </summary>
3030
public class GeometryConverter : JsonConverter
3131
{
@@ -88,7 +88,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
8888

8989
if (parsingErrors.Any())
9090
{
91-
throw new AggregateException("Error Parsing Geometry.", parsingErrors);
91+
throw new AggregateException("Error Parsing GeometryObject.", parsingErrors);
9292
}
9393

9494
return point;
@@ -108,7 +108,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
108108

109109
if (parsingErrors.Any())
110110
{
111-
throw new AggregateException("Error parsing Geometry.", parsingErrors);
111+
throw new AggregateException("Error parsing GeometryObject.", parsingErrors);
112112
}
113113

114114
return polygon;
@@ -129,7 +129,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
129129

130130
if (parsingErrors.Any())
131131
{
132-
throw new AggregateException("Error parsing Geometry.", parsingErrors);
132+
throw new AggregateException("Error parsing GeometryObject.", parsingErrors);
133133
}
134134

135135
return multiPolygon;
@@ -149,10 +149,10 @@ public override bool CanConvert(Type objectType)
149149
{
150150
if (objectType.IsInterface)
151151
{
152-
return objectType == typeof(IGeometry);
152+
return objectType == typeof(IGeometryObject);
153153
}
154154

155-
return objectType.GetInterface(typeof(IGeometry).Name, true) != null;
155+
return objectType.GetInterface(typeof(IGeometryObject).Name, true) != null;
156156
}
157157
}
158158
}

src/GeoJSON.Net/Converters/MultiPolygonConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace SimpleGeo.Net.Helpers.Json.Converters
1616
using GeoJSON.Net;
1717
using GeoJSON.Net.Converters;
1818
using GeoJSON.Net.Exceptions;
19+
using GeoJSON.Net.Geometry;
1920

2021
using Newtonsoft.Json;
2122
using Newtonsoft.Json.Linq;
@@ -69,7 +70,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
6970

7071
if (parsingErrors.Any())
7172
{
72-
throw new AggregateException("Error parsing Geometry.", parsingErrors);
73+
throw new AggregateException("Error parsing GeometryObject.", parsingErrors);
7374
}
7475

7576
return new MultiPolygon(polygons);

src/GeoJSON.Net/Converters/PointsConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace GeoJSON.Net.Converters
1313

1414
using GeoJSON.Net;
1515
using GeoJSON.Net.Exceptions;
16+
using GeoJSON.Net.Geometry;
1617

1718
using Newtonsoft.Json;
1819
using Newtonsoft.Json.Linq;

src/GeoJSON.Net/Converters/PolygonConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace GeoJSON.Net.Converters
1515

1616
using GeoJSON.Net;
1717
using GeoJSON.Net.Exceptions;
18+
using GeoJSON.Net.Geometry;
1819

1920
using Newtonsoft.Json;
2021
using Newtonsoft.Json.Linq;
@@ -71,7 +72,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
7172

7273
if (parsingErrors.Any())
7374
{
74-
throw new AggregateException("Error parsing Geometry.", parsingErrors);
75+
throw new AggregateException("Error parsing GeometryObject.", parsingErrors);
7576
}
7677

7778
return new Polygon(points);

src/GeoJSON.Net/Converters/PositionConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace GeoJSON.Net.Converters
1313

1414
using GeoJSON.Net;
1515
using GeoJSON.Net.Exceptions;
16+
using GeoJSON.Net.Geometry;
1617

1718
using Newtonsoft.Json;
1819
using Newtonsoft.Json.Linq;

src/GeoJSON.Net/Converters/TimestampConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace SimpleGeo.Net.Helpers.Json.Converters
1313

1414
using GeoJSON.Net;
1515
using GeoJSON.Net.Exceptions;
16+
using GeoJSON.Net.Geometry;
1617

1718
using Newtonsoft.Json;
1819

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="CRSBase.cs" company="Jörg Battermann">
3+
// Copyright © Jörg Battermann 2011
4+
// </copyright>
5+
// <summary>
6+
// Defines the CRSBase type.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
namespace GeoJSON.Net.CoordinateReferenceSystem
11+
{
12+
using System.Collections.Generic;
13+
14+
using Newtonsoft.Json;
15+
16+
/// <summary>
17+
/// Base class for all IGeometryObject implementing types
18+
/// </summary>
19+
[JsonObject(MemberSerialization.OptIn)]
20+
public abstract class CRSBase
21+
{
22+
/// <summary>
23+
/// Gets the type of the GeometryObject object.
24+
/// </summary>
25+
[JsonProperty(PropertyName = "type", Required = Required.Always)]
26+
public CRSType Type { get; internal set; }
27+
28+
/// <summary>
29+
/// Gets the properties.
30+
/// </summary>
31+
[JsonProperty(PropertyName = "properties", Required = Required.Always)]
32+
public Dictionary<string, object> Properties { get; internal set; }
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="CRSType.cs" company="Jörg Battermann">
3+
// Copyright © Jörg Battermann 2011
4+
// </copyright>
5+
// <summary>
6+
// Defines the GeoJSON Coordinate Reference System Objects (CRS) types as defined in the <see cref="http://geojson.org/geojson-spec.html#coordinate-reference-system-objects">geojson.org v1.0 spec</see>.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
namespace GeoJSON.Net.CoordinateReferenceSystem
11+
{
12+
using System;
13+
14+
/// <summary>
15+
/// Defines the GeoJSON Coordinate Reference System Objects (CRS) types as defined in the <see cref="http://geojson.org/geojson-spec.html#coordinate-reference-system-objects">geojson.org v1.0 spec</see>.
16+
/// </summary>
17+
[Flags]
18+
public enum CRSType
19+
{
20+
/// <summary>
21+
/// Defines the <see cref="http://geojson.org/geojson-spec.html#named-crs">Named</see> CRS type.
22+
/// </summary>
23+
Name,
24+
25+
/// <summary>
26+
/// Defines the <see cref="http://geojson.org/geojson-spec.html#linked-crs">Linked</see> CRS type.
27+
/// </summary>
28+
Link
29+
}
30+
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
// --------------------------------------------------------------------------------------------------------------------
2-
// <copyright file="IGeometry.cs" company="Jörg Battermann">
2+
// <copyright file="ICRSObject.cs" company="Jörg Battermann">
33
// Copyright © Jörg Battermann 2011
44
// </copyright>
55
// <summary>
6-
// Defines the IGeometry type.
6+
// Base Interface for CRSBase Object types.
77
// </summary>
88
// --------------------------------------------------------------------------------------------------------------------
99

10-
namespace GeoJSON.Net.Geometry
10+
namespace GeoJSON.Net.CoordinateReferenceSystem
1111
{
12-
using Newtonsoft.Json;
13-
1412
/// <summary>
15-
/// Base Interface for Geometry types.
13+
/// Base Interface for CRSBase Object types.
1614
/// </summary>
17-
[JsonObject(MemberSerialization.OptIn)]
18-
public interface IGeometry
15+
public interface ICRSObject
1916
{
2017
/// <summary>
21-
/// Gets the type of the Geometry object.
18+
/// Gets the CRS type.
2219
/// </summary>
23-
[JsonProperty(PropertyName = "type")]
24-
GeometryType Type { get; }
20+
CRSType Type { get; }
2521
}
2622
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="LinkedCRS.cs" company="Jörg Battermann">
3+
// Copyright © Jörg Battermann 2011
4+
// </copyright>
5+
// <summary>
6+
// Defines the <see cref="http://geojson.org/geojson-spec.html#named-crs">Linked CRS type</see>.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
namespace GeoJSON.Net.CoordinateReferenceSystem
11+
{
12+
using System;
13+
using System.Collections.Generic;
14+
15+
/// <summary>
16+
/// Defines the <see cref="http://geojson.org/geojson-spec.html#linked-crs">Linked CRS type</see>.
17+
/// </summary>
18+
public class LinkedCRS : CRSBase
19+
{
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="LinkedCRS"/> class.
22+
/// </summary>
23+
/// <param name="href">The mandatory <see cref="http://geojson.org/geojson-spec.html#linked-crs">href</see> member must be a dereferenceable URI.</param>
24+
/// <param name="type">The optional type member will be put in the properties Dictionary as specified in the <see cref="http://geojson.org/geojson-spec.html#linked-crs">GeoJSON spec</see>.</param>
25+
public LinkedCRS(string href, string type = "")
26+
{
27+
if (href == null)
28+
{
29+
throw new ArgumentNullException("href");
30+
}
31+
32+
if (string.IsNullOrWhiteSpace(href))
33+
{
34+
throw new ArgumentOutOfRangeException("href", "May not be empty");
35+
}
36+
37+
this.Properties = new Dictionary<string, object> { { "href", href } };
38+
39+
if (!string.IsNullOrWhiteSpace(type))
40+
{
41+
this.Properties.Add("type", type);
42+
}
43+
44+
this.Type = CRSType.Link;
45+
}
46+
47+
/// <summary>
48+
/// Initializes a new instance of the <see cref="LinkedCRS"/> class.
49+
/// </summary>
50+
/// <param name="href">The mandatory <see cref="http://geojson.org/geojson-spec.html#linked-crs">href</see> member must be a dereferenceable URI.</param>
51+
/// <param name="type">The optional type member will be put in the properties Dictionary as specified in the <see cref="http://geojson.org/geojson-spec.html#linked-crs">GeoJSON spec</see>.</param>
52+
public LinkedCRS(Uri href, string type = "") : this(href.ToString(), type)
53+
{
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)