Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Spatial / DbGeography.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="DbGeography.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  willa
7 // @backupOwner Microsoft
8 //------------------------------------------------------------------------------
9
10 using System.Data.Common.Internal;
11 using System.ComponentModel.DataAnnotations;
12 using System.Data.Spatial.Internal;
13 using System.Diagnostics;
14 using System.Globalization;
15 using System.Runtime.Serialization;
16
17 namespace System.Data.Spatial
18 {
19     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
20     [DataContract]
21     [Serializable]
22     [BindableType]
23     public class DbGeography
24     {
25         private DbSpatialServices spatialSvcs;
26         private object providerValue;
27
28         internal DbGeography(DbSpatialServices spatialServices, object spatialProviderValue)
29         {
30             Debug.Assert(spatialServices != null, "Spatial services are required");
31             Debug.Assert(spatialProviderValue != null, "Provider value is required");
32
33             this.spatialSvcs = spatialServices;
34             this.providerValue = spatialProviderValue;
35         }
36
37         /// <summary>
38         /// Gets the default coordinate system id (SRID) for geography values (WGS 84)
39         /// </summary>
40         public static int DefaultCoordinateSystemId { get { return 4326; /* WGS 84 */ } }
41
42         /// <summary>
43         /// Gets a representation of this DbGeography value that is specific to the underlying provider that constructed it.
44         /// </summary>
45         public object ProviderValue { get { return this.providerValue; } }
46
47         /// <summary>
48         /// Gets or sets a data contract serializable well known representation of this DbGeography value.
49         /// </summary>
50         [DataMember(Name = "Geography")]
51         public DbGeographyWellKnownValue WellKnownValue
52         {
53             get { return this.spatialSvcs.CreateWellKnownValue(this); }
54             set
55             {
56                 if (this.spatialSvcs != null)
57                 {
58                     throw SpatialExceptions.WellKnownValueSerializationPropertyNotDirectlySettable();
59                 }
60
61                 DbSpatialServices resolvedServices = DbSpatialServices.Default;
62                 this.providerValue = resolvedServices.CreateProviderValue(value);
63                 this.spatialSvcs = resolvedServices;
64             }
65         }
66
67         #region Well Known Binary Static Constructors
68
69         /// <summary>
70         /// Creates a new <see cref="DbGeography"/> value based on the specified well known binary value. 
71         /// </summary>
72         /// <param name="wellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
73         /// <returns>A new DbGeography value as defined by the well known binary value with the default geography coordinate system identifier (SRID)(<see cref="DbGeography.DefaultCoordinateSystemId"/>).</returns>
74         /// <exception cref="ArgumentNullException"><paramref name="wellKnownBinary"/> is null.</exception>
75         public static DbGeography FromBinary(byte[] wellKnownBinary)
76         {
77             wellKnownBinary.CheckNull("wellKnownBinary");
78             return DbSpatialServices.Default.GeographyFromBinary(wellKnownBinary);
79         }
80
81         /// <summary>
82         /// Creates a new <see cref="DbGeography"/> value based on the specified well known binary value and coordinate system identifier (SRID).
83         /// </summary>
84         /// <param name="wellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
85         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
86         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
87         /// <exception cref="ArgumentNullException"><paramref name="wellKnownBinary"/> is null.</exception>
88         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
89         public static DbGeography FromBinary(byte[] wellKnownBinary, int coordinateSystemId)
90         {
91             wellKnownBinary.CheckNull("wellKnownBinary");
92             return DbSpatialServices.Default.GeographyFromBinary(wellKnownBinary, coordinateSystemId);
93         }
94
95         /// <summary>
96         /// Creates a new <see cref="DbGeography"/> line value based on the specified well known binary value and coordinate system identifier (SRID). 
97         /// </summary>
98         /// <param name="lineWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
99         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
100         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
101         /// <exception cref="ArgumentNullException"><paramref name="lineWellKnownBinary"/> is null.</exception>
102         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
103         public static DbGeography LineFromBinary(byte[] lineWellKnownBinary, int coordinateSystemId)
104         {
105             lineWellKnownBinary.CheckNull("lineWellKnownBinary");
106             return DbSpatialServices.Default.GeographyLineFromBinary(lineWellKnownBinary, coordinateSystemId);
107         }
108
109         /// <summary>
110         /// Creates a new <see cref="DbGeography"/> point value based on the specified well known binary value and coordinate system identifier (SRID).
111         /// </summary>
112         /// <param name="pointWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
113         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
114         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
115         /// <exception cref="ArgumentNullException"><paramref name="pointWellKnownBinary"/> is null.</exception>
116         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
117         public static DbGeography PointFromBinary(byte[] pointWellKnownBinary, int coordinateSystemId)
118         {
119             pointWellKnownBinary.CheckNull("pointWellKnownBinary");
120             return DbSpatialServices.Default.GeographyPointFromBinary(pointWellKnownBinary, coordinateSystemId);
121         }
122
123         /// <summary>
124         /// Creates a new <see cref="DbGeography"/> polygon value based on the specified well known binary value and coordinate system identifier (SRID).
125         /// </summary>
126         /// <param name="polygonWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
127         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
128         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
129         /// <exception cref="ArgumentNullException"><paramref name="polygonWellKnownBinary"/> is null.</exception>
130         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
131         public static DbGeography PolygonFromBinary(byte[] polygonWellKnownBinary, int coordinateSystemId)
132         {
133             polygonWellKnownBinary.CheckNull("polygonWellKnownBinary");
134             return DbSpatialServices.Default.GeographyPolygonFromBinary(polygonWellKnownBinary, coordinateSystemId);
135         }
136
137         /// <summary>
138         /// Creates a new <see cref="DbGeography"/> MultiLine value based on the specified well known binary value and coordinate system identifier (SRID).
139         /// </summary>
140         /// <param name="multiLineWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
141         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
142         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
143         /// <exception cref="ArgumentNullException"><paramref name="multiLineWellKnownBinary"/> is null.</exception>
144         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
145         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "MultiLine", Justification = "Match OGC, EDM")]
146         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
147         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "multiLine", Justification = "Match OGC, EDM")]
148         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
149         public static DbGeography MultiLineFromBinary(byte[] multiLineWellKnownBinary, int coordinateSystemId)
150         {
151             multiLineWellKnownBinary.CheckNull("multiLineWellKnownBinary");
152             return DbSpatialServices.Default.GeographyMultiLineFromBinary(multiLineWellKnownBinary, coordinateSystemId);
153         }
154
155         /// <summary>
156         /// Creates a new <see cref="DbGeography"/> MultiPoint value based on the specified well known binary value and coordinate system identifier (SRID). 
157         /// </summary>
158         /// <param name="multiPointWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
159         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
160         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
161         /// <exception cref="ArgumentNullException"><paramref name="multiPointWellKnownBinary"/> is null.</exception>
162         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
163         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "MultiPoint", Justification = "Match OGC, EDM")]
164         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
165         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "multiPoint", Justification = "Match OGC, EDM")]
166         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
167         public static DbGeography MultiPointFromBinary(byte[] multiPointWellKnownBinary, int coordinateSystemId)
168         {
169             multiPointWellKnownBinary.CheckNull("multiPointWellKnownBinary");
170             return DbSpatialServices.Default.GeographyMultiPointFromBinary(multiPointWellKnownBinary, coordinateSystemId);
171         }
172
173         /// <summary>
174         /// Creates a new <see cref="DbGeography"/> MultiPolygon value based on the specified well known binary value and coordinate system identifier (SRID).
175         /// </summary>
176         /// <param name="multiPolygonWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
177         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
178         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
179         /// <exception cref="ArgumentNullException"><paramref name="multiPolygonWellKnownBinary"/> is null.</exception>
180         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
181         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
182         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
183         public static DbGeography MultiPolygonFromBinary(byte[] multiPolygonWellKnownBinary, int coordinateSystemId)
184         {
185             multiPolygonWellKnownBinary.CheckNull("multiPolygonWellKnownBinary");
186             return DbSpatialServices.Default.GeographyMultiPolygonFromBinary(multiPolygonWellKnownBinary, coordinateSystemId);
187         }
188
189         /// <summary>
190         /// Creates a new <see cref="DbGeography"/> collection value based on the specified well known binary value and coordinate system identifier (SRID).
191         /// </summary>
192         /// <param name="geographyCollectionWellKnownBinary">A byte array that contains a well known binary representation of the geography value.</param>
193         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
194         /// <returns>A new DbGeography value as defined by the well known binary value with the specified coordinate system identifier.</returns>
195         /// <exception cref="ArgumentNullException"><paramref name="geographyCollectionWellKnownBinary"/> is null.</exception>
196         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
197         public static DbGeography GeographyCollectionFromBinary(byte[] geographyCollectionWellKnownBinary, int coordinateSystemId)
198         {
199             geographyCollectionWellKnownBinary.CheckNull("geographyCollectionWellKnownBinary");
200             return DbSpatialServices.Default.GeographyCollectionFromBinary(geographyCollectionWellKnownBinary, coordinateSystemId);
201         }
202
203         #endregion
204
205         #region GML Static Constructors
206
207         /// <summary>
208         /// Creates a new <see cref="DbGeography"/> value based on the specified Geography Markup Language (GML) value.
209         /// </summary>
210         /// <param name="geographyMarkup">A string that contains a Geography Markup Language (GML) representation of the geography value.</param>
211         /// <returns>A new DbGeography value as defined by the GML value with the default geography coordinate system identifier (SRID) (<see cref="DbGeography.DefaultCoordinateSystemId"/>).</returns>
212         /// <exception cref="ArgumentNullException"><paramref name="geographyMarkup"/> is null.</exception>
213         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gml")]
214         public static DbGeography FromGml(string geographyMarkup)
215         {
216             geographyMarkup.CheckNull("geographyMarkup");
217             return DbSpatialServices.Default.GeographyFromGml(geographyMarkup);
218         }
219
220         /// <summary>
221         /// Creates a new <see cref="DbGeography"/> value based on the specified Geography Markup Language (GML) value and coordinate system identifier (SRID).
222         /// </summary>
223         /// <param name="geographyMarkup">A string that contains a Geography Markup Language (GML) representation of the geography value.</param>
224         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
225         /// <returns>A new DbGeography value as defined by the GML value with the specified coordinate system identifier.</returns>
226         /// <exception cref="ArgumentNullException"><paramref name="geographyMarkup"/> is null.</exception>
227         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
228         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gml")]
229         public static DbGeography FromGml(string geographyMarkup, int coordinateSystemId)
230         {
231             geographyMarkup.CheckNull("geographyMarkup");
232             return DbSpatialServices.Default.GeographyFromGml(geographyMarkup, coordinateSystemId);
233         }
234
235         #endregion
236
237         #region Well Known Text Static Constructors
238
239         /// <summary>
240         /// Creates a new <see cref="DbGeography"/> value based on the specified well known text value. 
241         /// </summary>
242         /// <param name="wellKnownText">A string that contains a well known text representation of the geography value.</param>
243         /// <returns>A new DbGeography value as defined by the well known text value with the default geography coordinate system identifier (SRID) (<see cref="DbGeography.DefaultCoordinateSystemId"/>).</returns>
244         /// <exception cref="ArgumentNullException"><paramref name="wellKnownText"/> is null.</exception>
245         public static DbGeography FromText(string wellKnownText)
246         {
247             wellKnownText.CheckNull("wellKnownText");
248             return DbSpatialServices.Default.GeographyFromText(wellKnownText);
249         }
250
251         /// <summary>
252         /// Creates a new <see cref="DbGeography"/> value based on the specified well known text value and coordinate system identifier (SRID).
253         /// </summary>
254         /// <param name="wellKnownText">A string that contains a well known text representation of the geography value.</param>
255         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
256         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
257         /// <exception cref="ArgumentNullException"><paramref name="wellKnownText"/> is null.</exception>
258         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
259         public static DbGeography FromText(string wellKnownText, int coordinateSystemId)
260         {
261             wellKnownText.CheckNull("wellKnownText");
262             return DbSpatialServices.Default.GeographyFromText(wellKnownText, coordinateSystemId);
263         }
264
265         /// <summary>
266         /// Creates a new <see cref="DbGeography"/> line value based on the specified well known text value and coordinate system identifier (SRID). 
267         /// </summary>
268         /// <param name="lineWellKnownText">A string that contains a well known text representation of the geography value.</param>
269         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
270         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
271         /// <exception cref="ArgumentNullException"><paramref name="lineWellKnownText"/> is null.</exception>
272         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
273         public static DbGeography LineFromText(string lineWellKnownText, int coordinateSystemId)
274         {
275             lineWellKnownText.CheckNull("lineWellKnownText");
276             return DbSpatialServices.Default.GeographyLineFromText(lineWellKnownText, coordinateSystemId);
277         }
278
279         /// <summary>
280         /// Creates a new <see cref="DbGeography"/> point value based on the specified well known text value and coordinate system identifier (SRID).
281         /// </summary>
282         /// <param name="pointWellKnownText">A string that contains a well known text representation of the geography value.</param>
283         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
284         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
285         /// <exception cref="ArgumentNullException"><paramref name="pointWellKnownText"/> is null.</exception>
286         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
287         public static DbGeography PointFromText(string pointWellKnownText, int coordinateSystemId)
288         {
289             pointWellKnownText.CheckNull("pointWellKnownText");
290             return DbSpatialServices.Default.GeographyPointFromText(pointWellKnownText, coordinateSystemId);
291         }
292
293         /// <summary>
294         /// Creates a new <see cref="DbGeography"/> polygon value based on the specified well known text value and coordinate system identifier (SRID).
295         /// </summary>
296         /// <param name="polygonWellKnownText">A string that contains a well known text representation of the geography value.</param>
297         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
298         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
299         /// <exception cref="ArgumentNullException"><paramref name="polygonWellKnownText"/> is null.</exception>
300         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
301         public static DbGeography PolygonFromText(string polygonWellKnownText, int coordinateSystemId)
302         {
303             polygonWellKnownText.CheckNull("polygonWellKnownText");
304             return DbSpatialServices.Default.GeographyPolygonFromText(polygonWellKnownText, coordinateSystemId);
305         }
306
307         /// <summary>
308         /// Creates a new <see cref="DbGeography"/> MultiLine value based on the specified well known text value and coordinate system identifier (SRID). 
309         /// </summary>
310         /// <param name="multiLineWellKnownText">A string that contains a well known text representation of the geography value.</param>
311         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
312         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
313         /// <exception cref="ArgumentNullException"><paramref name="multiLineWellKnownText"/> is null.</exception>
314         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
315         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "MultiLine", Justification = "Match OGC, EDM")]
316         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
317         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "multiLine", Justification = "Match OGC, EDM")]
318         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
319         public static DbGeography MultiLineFromText(string multiLineWellKnownText, int coordinateSystemId)
320         {
321             multiLineWellKnownText.CheckNull("multiLineWellKnownText");
322             return DbSpatialServices.Default.GeographyMultiLineFromText(multiLineWellKnownText, coordinateSystemId);
323         }
324
325         /// <summary>
326         /// Creates a new <see cref="DbGeography"/> MultiPoint value based on the specified well known text value and coordinate system identifier (SRID).
327         /// </summary>
328         /// <param name="multiPointWellKnownText">A string that contains a well known text representation of the geography value.</param>
329         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
330         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
331         /// <exception cref="ArgumentNullException"><paramref name="multiPointWellKnownText"/> is null.</exception>
332         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
333         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "MultiPoint", Justification = "Match OGC, EDM")]
334         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
335         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "multiPoint", Justification = "Match OGC, EDM")]
336         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
337         public static DbGeography MultiPointFromText(string multiPointWellKnownText, int coordinateSystemId)
338         {
339             multiPointWellKnownText.CheckNull("multiPointWellKnownText");
340             return DbSpatialServices.Default.GeographyMultiPointFromText(multiPointWellKnownText, coordinateSystemId);
341         }
342
343         /// <summary>
344         /// Creates a new <see cref="DbGeography"/> MultiPolygon value based on the specified well known text value and coordinate system identifier (SRID). 
345         /// </summary>
346         /// <param name="multiPolygonWellKnownText">A string that contains a well known text representation of the geography value.</param>
347         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
348         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
349         /// <exception cref="ArgumentNullException"><paramref name="multiPolygonWellKnownText"/> is null.</exception>
350         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
351         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Justification = "Match OGC, EDM")]
352         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "multi", Justification = "Match OGC, EDM")]
353         public static DbGeography MultiPolygonFromText(string multiPolygonWellKnownText, int coordinateSystemId)
354         {
355             multiPolygonWellKnownText.CheckNull("multiPolygonWellKnownText");
356             return DbSpatialServices.Default.GeographyMultiPolygonFromText(multiPolygonWellKnownText, coordinateSystemId);
357         }
358
359         /// <summary>
360         /// Creates a new <see cref="DbGeography"/> collection value based on the specified well known text value and coordinate system identifier (SRID). 
361         /// </summary>
362         /// <param name="geographyCollectionWellKnownText">A string that contains a well known text representation of the geography value.</param>
363         /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param>
364         /// <returns>A new DbGeography value as defined by the well known text value with the specified coordinate system identifier.</returns>
365         /// <exception cref="ArgumentNullException"><paramref name="geographyCollectionWellKnownText"/> is null.</exception>
366         /// <exception cref="ArgumentException"><paramref name="coordinateSystemId"/> is not valid.</exception>
367         public static DbGeography GeographyCollectionFromText(string geographyCollectionWellKnownText, int coordinateSystemId)
368         {
369             geographyCollectionWellKnownText.CheckNull("geographyCollectionWellKnownText");
370             return DbSpatialServices.Default.GeographyCollectionFromText(geographyCollectionWellKnownText, coordinateSystemId);
371         }
372
373         #endregion
374
375         #region Geography Instance Properties
376
377         /// </summary>
378         /// Gets the Spatial Reference System Identifier (Coordinate System Id) of the spatial reference system used by this DbGeography value.
379         /// </summary>
380         public int CoordinateSystemId { get { return this.spatialSvcs.GetCoordinateSystemId(this); } }
381
382         /// <summary>
383         /// Gets the dimension of the given <see cref="DbGeography"/> value or, if the value is a collections, the largest element dimension.
384         /// </summary>
385         public int Dimension { get { return this.spatialSvcs.GetDimension(this); } }
386
387         /// </summary>
388         /// Gets the spatial type name, as a string, of this DbGeography value.
389         /// </summary>
390         public string SpatialTypeName { get { return this.spatialSvcs.GetSpatialTypeName(this); } }
391
392         /// </summary>
393         /// Gets a Boolean value indicating whether this DbGeography value represents the empty geography.
394         /// </summary>
395         public bool   IsEmpty { get { return this.spatialSvcs.GetIsEmpty(this); } }
396                 
397         #endregion
398
399         #region Geography Well Known Format Conversion
400
401         /// <summary>
402         /// Generates the well known text representation of this DbGeography value.  Includes only Longitude and Latitude for points.
403         /// </summary>
404         /// <returns>A string containing the well known text representation of this DbGeography value.</returns>
405         public string AsText() { return this.spatialSvcs.AsText(this); }
406
407         /// <summary>
408         /// Generates the well known text representation of this DbGeography value.  Includes Longitude, Latitude, Elevation (Z) and Measure (M) for points.
409         /// </summary>
410         /// <returns>A string containing the well known text representation of this DbGeography value.</returns>
411         internal string AsTextIncludingElevationAndMeasure() { return this.spatialSvcs.AsTextIncludingElevationAndMeasure(this); }
412
413         /// <summary>
414         /// Generates the well known binary representation of this DbGeography value.
415         /// </summary>
416         /// <returns>A byte array containing the well known binary representation of this DbGeography value.</returns>
417         public byte[] AsBinary() { return this.spatialSvcs.AsBinary(this); }
418         
419         // Non-OGC
420         /// <summary>
421         /// Generates the Geography Markup Language (GML) representation of this DbGeography value.
422         /// </summary>
423         /// <returns>A string containing the GML representation of this DbGeography value.</returns>
424         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gml")]
425         public string AsGml() { return this.spatialSvcs.AsGml(this); }
426
427         #endregion
428
429         #region Geography Operations - Spatial Relation
430
431         /// <summary>
432         /// Determines whether this DbGeography is spatially equal to the specified DbGeography argument.
433         /// </summary>
434         /// <param name="other">The geography value that should be compared with this geography value for equality.</param>
435         /// <returns><c>true</c> if <paramref name="other"/> is spatially equal to this geography value; otherwise <c>false</c>.</returns>
436         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
437         public bool SpatialEquals(DbGeography other)
438         {
439             other.CheckNull("other");
440             return this.spatialSvcs.SpatialEquals(this, other);
441         }
442
443         /// <summary>
444         /// Determines whether this DbGeography is spatially disjoint from the specified DbGeography argument.
445         /// </summary>
446         /// <param name="other">The geography value that should be compared with this geography value for disjointness.</param>
447         /// <returns><c>true</c> if <paramref name="other"/> is disjoint from this geography value; otherwise <c>false</c>.</returns>
448         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
449         public bool Disjoint(DbGeography other)
450         {
451             other.CheckNull("other");
452             return this.spatialSvcs.Disjoint(this, other);
453         }
454
455         /// <summary>
456         /// Determines whether this DbGeography value spatially intersects the specified DbGeography argument.
457         /// </summary>
458         /// <param name="other">The geography value that should be compared with this geography value for intersection.</param>
459         /// <returns><c>true</c> if <paramref name="other"/> intersects this geography value; otherwise <c>false</c>.</returns>
460         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
461         public bool Intersects(DbGeography other)
462         {
463             other.CheckNull("other");
464             return this.spatialSvcs.Intersects(this, other);
465         }
466
467         #endregion
468
469         #region Geography Operations - Spatial Analysis
470
471         /// <summary>
472         /// Creates a geography value representing all points less than or equal to <paramref name="distance"/> from this DbGeography value.
473         /// </summary>
474         /// <param name="distance">A double value specifying how far from this geography value to buffer.</param>
475         /// <returns>A new DbGeography value representing all points less than or equal to <paramref name="distance"/> from this geography value.</returns>
476         /// <exception cref="ArgumentNullException"><paramref name="distance"/> is null.</exception>
477         public DbGeography Buffer(double? distance)
478         {
479             if (!distance.HasValue)
480             {
481                 throw EntityUtil.ArgumentNull("distance");
482             } 
483             return this.spatialSvcs.Buffer(this, distance.Value);
484         }
485
486         /// <summary>
487         /// Computes the distance between the closest points in this DbGeography value and another DbGeography value.
488         /// </summary>
489         /// <param name="other">The geography value for which the distance from this value should be computed.</param>
490         /// <returns>A double value that specifies the distance between the two closest points in this geography value and <paramref name="other"/>.</returns>
491         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
492         public double? Distance(DbGeography other)
493         {
494             other.CheckNull("other");
495             return this.spatialSvcs.Distance(this, other);
496         }
497
498         /// <summary>
499         /// Computes the intersection of this DbGeography value and another DbGeography value.
500         /// </summary>
501         /// <param name="other">The geography value for which the intersection with this value should be computed.</param>
502         /// <returns>A new DbGeography value representing the intersection between this geography value and <paramref name="other"/>.</returns>
503         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
504         public DbGeography Intersection(DbGeography other)
505         {
506             other.CheckNull("other");
507             return this.spatialSvcs.Intersection(this, other);
508         }
509
510         /// <summary>
511         /// Computes the union of this DbGeography value and another DbGeography value.
512         /// </summary>
513         /// <param name="other">The geography value for which the union with this value should be computed.</param>
514         /// <returns>A new DbGeography value representing the union between this geography value and <paramref name="other"/>.</returns>
515         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
516         public DbGeography Union(DbGeography other)
517         {
518             other.CheckNull("other");
519             return this.spatialSvcs.Union(this, other);
520         }
521
522         /// <summary>
523         /// Computes the difference of this DbGeography value and another DbGeography value.
524         /// </summary>
525         /// <param name="other">The geography value for which the difference with this value should be computed.</param>
526         /// <returns>A new DbGeography value representing the difference between this geography value and <paramref name="other"/>.</returns>
527         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
528         public DbGeography Difference(DbGeography other)
529         {
530             other.CheckNull("other");
531             return this.spatialSvcs.Difference(this, other);
532         }
533
534         /// <summary>
535         /// Computes the symmetric difference of this DbGeography value and another DbGeography value.
536         /// </summary>
537         /// <param name="other">The geography value for which the symmetric difference with this value should be computed.</param>
538         /// <returns>A new DbGeography value representing the symmetric difference between this geography value and <paramref name="other"/>.</returns>
539         /// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>
540         public DbGeography SymmetricDifference(DbGeography other)
541         {
542             other.CheckNull("other");
543             return this.spatialSvcs.SymmetricDifference(this, other);
544         }
545
546         #endregion
547
548         #region Geography Collection
549
550         /// <summary>
551         /// Gets the number of elements in this DbGeography value, if it represents a geography collection.
552         /// <returns>The number of elements in this geography value, if it represents a collection of other geography values; otherwise <c>null</c>.</returns>
553         /// </summary>
554         public int? ElementCount { get { return this.spatialSvcs.GetElementCount(this); } }
555
556         /// <summary>
557         /// Returns an element of this DbGeography value from a specific position, if it represents a geography collection.
558         /// <param name="index">The position within this geography value from which the element should be taken.</param>
559         /// <returns>The element in this geography value at the specified position, if it represents a collection of other geography values; otherwise <c>null</c>.</returns>
560         /// </summary>
561         public DbGeography ElementAt(int index)
562         {
563             return this.spatialSvcs.ElementAt(this, index);
564         }
565
566         #endregion
567
568         #region Point
569
570         /// <summary>
571         /// Gets the Latitude coordinate of this DbGeography value, if it represents a point.
572         /// <returns>The Latitude coordinate value of this geography value, if it represents a point; otherwise <c>null</c>.</returns>
573         /// </summary>
574         public double? Latitude { get { return this.spatialSvcs.GetLatitude(this); } }
575
576         /// <summary>
577         /// Gets the Longitude coordinate of this DbGeography value, if it represents a point.
578         /// <returns>The Longitude coordinate value of this geography value, if it represents a point; otherwise <c>null</c>.</returns>
579         /// </summary>
580         public double? Longitude { get { return this.spatialSvcs.GetLongitude(this); } }
581
582         /// <summary>
583         /// Gets the elevation (Z coordinate) of this DbGeography value, if it represents a point.
584         /// <returns>The elevation (Z coordinate) value of this geography value, if it represents a point; otherwise <c>null</c>.</returns>
585         /// </summary>
586          public double? Elevation { get { return this.spatialSvcs.GetElevation(this); } }
587
588         /// <summary>
589         /// Gets the M (Measure) coordinate of this DbGeography value, if it represents a point.
590         /// <returns>The M (Measure) coordinate value of this geography value, if it represents a point; otherwise <c>null</c>.</returns>
591         /// </summary>
592         public double? Measure { get { return this.spatialSvcs.GetMeasure(this); } }
593
594         #endregion
595
596         #region Curve
597
598         /// <summary>
599         /// Gets a nullable double value that indicates the length of this DbGeography value, which may be null if this value does not represent a curve.
600         /// </summary>
601         public double? Length { get { return this.spatialSvcs.GetLength(this); } }
602
603         /// <summary>
604         /// Gets a DbGeography value representing the start point of this value, which may be null if this DbGeography value does not represent a curve.
605         /// </summary>
606         public DbGeography StartPoint { get { return this.spatialSvcs.GetStartPoint(this); } }
607
608         /// <summary>
609         /// Gets a DbGeography value representing the start point of this value, which may be null if this DbGeography value does not represent a curve.
610         /// </summary>
611         public DbGeography EndPoint { get { return this.spatialSvcs.GetEndPoint(this); } }
612
613         /// <summary>
614         /// Gets a nullable Boolean value indicating whether this DbGeography value is closed, which may be null if this value does not represent a curve.
615         /// </summary>
616         public bool? IsClosed { get { return this.spatialSvcs.GetIsClosed(this); } }
617
618         #endregion
619
620         #region LineString, Line, LinearRing
621
622         /// <summary>
623         /// Gets the number of points in this DbGeography value, if it represents a linestring or linear ring.
624         /// <returns>The number of elements in this geography value, if it represents a linestring or linear ring; otherwise <c>null</c>.</returns>
625         /// </summary>
626         public int? PointCount { get { return this.spatialSvcs.GetPointCount(this); } }
627
628         /// <summary>
629         /// Returns an element of this DbGeography value from a specific position, if it represents a linestring or linear ring.
630         /// <param name="index">The position within this geography value from which the element should be taken.</param>
631         /// <returns>The element in this geography value at the specified position, if it represents a linestring or linear ring; otherwise <c>null</c>.</returns>
632         /// </summary>
633         public DbGeography PointAt(int index)
634         {
635             return this.spatialSvcs.PointAt(this, index);
636         }
637
638         #endregion
639
640         #region Surface
641
642         /// <summary>
643         /// Gets a nullable double value that indicates the area of this DbGeography value, which may be null if this value does not represent a surface.
644         /// </summary>
645         public double? Area { get { return this.spatialSvcs.GetArea(this); } }
646
647         #endregion
648
649         #region ToString
650         /// <summary>
651         /// Returns a string representation of the geography value.
652         /// </summary>
653         public override string ToString()
654         {
655             return string.Format(CultureInfo.InvariantCulture, "SRID={1};{0}", this.WellKnownValue.WellKnownText ?? base.ToString(), this.CoordinateSystemId);
656         }
657         #endregion
658     }
659 }