1 //------------------------------------------------------------------------------
2 // <copyright file="DbGeography.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
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;
17 namespace System.Data.Spatial
19 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
23 public class DbGeography
25 private DbSpatialServices spatialSvcs;
26 private object providerValue;
28 internal DbGeography(DbSpatialServices spatialServices, object spatialProviderValue)
30 Debug.Assert(spatialServices != null, "Spatial services are required");
31 Debug.Assert(spatialProviderValue != null, "Provider value is required");
33 this.spatialSvcs = spatialServices;
34 this.providerValue = spatialProviderValue;
38 /// Gets the default coordinate system id (SRID) for geography values (WGS 84)
40 public static int DefaultCoordinateSystemId { get { return 4326; /* WGS 84 */ } }
43 /// Gets a representation of this DbGeography value that is specific to the underlying provider that constructed it.
45 public object ProviderValue { get { return this.providerValue; } }
48 /// Gets or sets a data contract serializable well known representation of this DbGeography value.
50 [DataMember(Name = "Geography")]
51 public DbGeographyWellKnownValue WellKnownValue
53 get { return this.spatialSvcs.CreateWellKnownValue(this); }
56 if (this.spatialSvcs != null)
58 throw SpatialExceptions.WellKnownValueSerializationPropertyNotDirectlySettable();
61 DbSpatialServices resolvedServices = DbSpatialServices.Default;
62 this.providerValue = resolvedServices.CreateProviderValue(value);
63 this.spatialSvcs = resolvedServices;
67 #region Well Known Binary Static Constructors
70 /// Creates a new <see cref="DbGeography"/> value based on the specified well known binary value.
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)
77 wellKnownBinary.CheckNull("wellKnownBinary");
78 return DbSpatialServices.Default.GeographyFromBinary(wellKnownBinary);
82 /// Creates a new <see cref="DbGeography"/> value based on the specified well known binary value and coordinate system identifier (SRID).
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)
91 wellKnownBinary.CheckNull("wellKnownBinary");
92 return DbSpatialServices.Default.GeographyFromBinary(wellKnownBinary, coordinateSystemId);
96 /// Creates a new <see cref="DbGeography"/> line value based on the specified well known binary value and coordinate system identifier (SRID).
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)
105 lineWellKnownBinary.CheckNull("lineWellKnownBinary");
106 return DbSpatialServices.Default.GeographyLineFromBinary(lineWellKnownBinary, coordinateSystemId);
110 /// Creates a new <see cref="DbGeography"/> point value based on the specified well known binary value and coordinate system identifier (SRID).
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)
119 pointWellKnownBinary.CheckNull("pointWellKnownBinary");
120 return DbSpatialServices.Default.GeographyPointFromBinary(pointWellKnownBinary, coordinateSystemId);
124 /// Creates a new <see cref="DbGeography"/> polygon value based on the specified well known binary value and coordinate system identifier (SRID).
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)
133 polygonWellKnownBinary.CheckNull("polygonWellKnownBinary");
134 return DbSpatialServices.Default.GeographyPolygonFromBinary(polygonWellKnownBinary, coordinateSystemId);
138 /// Creates a new <see cref="DbGeography"/> MultiLine value based on the specified well known binary value and coordinate system identifier (SRID).
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)
151 multiLineWellKnownBinary.CheckNull("multiLineWellKnownBinary");
152 return DbSpatialServices.Default.GeographyMultiLineFromBinary(multiLineWellKnownBinary, coordinateSystemId);
156 /// Creates a new <see cref="DbGeography"/> MultiPoint value based on the specified well known binary value and coordinate system identifier (SRID).
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)
169 multiPointWellKnownBinary.CheckNull("multiPointWellKnownBinary");
170 return DbSpatialServices.Default.GeographyMultiPointFromBinary(multiPointWellKnownBinary, coordinateSystemId);
174 /// Creates a new <see cref="DbGeography"/> MultiPolygon value based on the specified well known binary value and coordinate system identifier (SRID).
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)
185 multiPolygonWellKnownBinary.CheckNull("multiPolygonWellKnownBinary");
186 return DbSpatialServices.Default.GeographyMultiPolygonFromBinary(multiPolygonWellKnownBinary, coordinateSystemId);
190 /// Creates a new <see cref="DbGeography"/> collection value based on the specified well known binary value and coordinate system identifier (SRID).
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)
199 geographyCollectionWellKnownBinary.CheckNull("geographyCollectionWellKnownBinary");
200 return DbSpatialServices.Default.GeographyCollectionFromBinary(geographyCollectionWellKnownBinary, coordinateSystemId);
205 #region GML Static Constructors
208 /// Creates a new <see cref="DbGeography"/> value based on the specified Geography Markup Language (GML) value.
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)
216 geographyMarkup.CheckNull("geographyMarkup");
217 return DbSpatialServices.Default.GeographyFromGml(geographyMarkup);
221 /// Creates a new <see cref="DbGeography"/> value based on the specified Geography Markup Language (GML) value and coordinate system identifier (SRID).
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)
231 geographyMarkup.CheckNull("geographyMarkup");
232 return DbSpatialServices.Default.GeographyFromGml(geographyMarkup, coordinateSystemId);
237 #region Well Known Text Static Constructors
240 /// Creates a new <see cref="DbGeography"/> value based on the specified well known text value.
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)
247 wellKnownText.CheckNull("wellKnownText");
248 return DbSpatialServices.Default.GeographyFromText(wellKnownText);
252 /// Creates a new <see cref="DbGeography"/> value based on the specified well known text value and coordinate system identifier (SRID).
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)
261 wellKnownText.CheckNull("wellKnownText");
262 return DbSpatialServices.Default.GeographyFromText(wellKnownText, coordinateSystemId);
266 /// Creates a new <see cref="DbGeography"/> line value based on the specified well known text value and coordinate system identifier (SRID).
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)
275 lineWellKnownText.CheckNull("lineWellKnownText");
276 return DbSpatialServices.Default.GeographyLineFromText(lineWellKnownText, coordinateSystemId);
280 /// Creates a new <see cref="DbGeography"/> point value based on the specified well known text value and coordinate system identifier (SRID).
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)
289 pointWellKnownText.CheckNull("pointWellKnownText");
290 return DbSpatialServices.Default.GeographyPointFromText(pointWellKnownText, coordinateSystemId);
294 /// Creates a new <see cref="DbGeography"/> polygon value based on the specified well known text value and coordinate system identifier (SRID).
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)
303 polygonWellKnownText.CheckNull("polygonWellKnownText");
304 return DbSpatialServices.Default.GeographyPolygonFromText(polygonWellKnownText, coordinateSystemId);
308 /// Creates a new <see cref="DbGeography"/> MultiLine value based on the specified well known text value and coordinate system identifier (SRID).
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)
321 multiLineWellKnownText.CheckNull("multiLineWellKnownText");
322 return DbSpatialServices.Default.GeographyMultiLineFromText(multiLineWellKnownText, coordinateSystemId);
326 /// Creates a new <see cref="DbGeography"/> MultiPoint value based on the specified well known text value and coordinate system identifier (SRID).
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)
339 multiPointWellKnownText.CheckNull("multiPointWellKnownText");
340 return DbSpatialServices.Default.GeographyMultiPointFromText(multiPointWellKnownText, coordinateSystemId);
344 /// Creates a new <see cref="DbGeography"/> MultiPolygon value based on the specified well known text value and coordinate system identifier (SRID).
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)
355 multiPolygonWellKnownText.CheckNull("multiPolygonWellKnownText");
356 return DbSpatialServices.Default.GeographyMultiPolygonFromText(multiPolygonWellKnownText, coordinateSystemId);
360 /// Creates a new <see cref="DbGeography"/> collection value based on the specified well known text value and coordinate system identifier (SRID).
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)
369 geographyCollectionWellKnownText.CheckNull("geographyCollectionWellKnownText");
370 return DbSpatialServices.Default.GeographyCollectionFromText(geographyCollectionWellKnownText, coordinateSystemId);
375 #region Geography Instance Properties
378 /// Gets the Spatial Reference System Identifier (Coordinate System Id) of the spatial reference system used by this DbGeography value.
380 public int CoordinateSystemId { get { return this.spatialSvcs.GetCoordinateSystemId(this); } }
383 /// Gets the dimension of the given <see cref="DbGeography"/> value or, if the value is a collections, the largest element dimension.
385 public int Dimension { get { return this.spatialSvcs.GetDimension(this); } }
388 /// Gets the spatial type name, as a string, of this DbGeography value.
390 public string SpatialTypeName { get { return this.spatialSvcs.GetSpatialTypeName(this); } }
393 /// Gets a Boolean value indicating whether this DbGeography value represents the empty geography.
395 public bool IsEmpty { get { return this.spatialSvcs.GetIsEmpty(this); } }
399 #region Geography Well Known Format Conversion
402 /// Generates the well known text representation of this DbGeography value. Includes only Longitude and Latitude for points.
404 /// <returns>A string containing the well known text representation of this DbGeography value.</returns>
405 public string AsText() { return this.spatialSvcs.AsText(this); }
408 /// Generates the well known text representation of this DbGeography value. Includes Longitude, Latitude, Elevation (Z) and Measure (M) for points.
410 /// <returns>A string containing the well known text representation of this DbGeography value.</returns>
411 internal string AsTextIncludingElevationAndMeasure() { return this.spatialSvcs.AsTextIncludingElevationAndMeasure(this); }
414 /// Generates the well known binary representation of this DbGeography value.
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); }
421 /// Generates the Geography Markup Language (GML) representation of this DbGeography value.
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); }
429 #region Geography Operations - Spatial Relation
432 /// Determines whether this DbGeography is spatially equal to the specified DbGeography argument.
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)
439 other.CheckNull("other");
440 return this.spatialSvcs.SpatialEquals(this, other);
444 /// Determines whether this DbGeography is spatially disjoint from the specified DbGeography argument.
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)
451 other.CheckNull("other");
452 return this.spatialSvcs.Disjoint(this, other);
456 /// Determines whether this DbGeography value spatially intersects the specified DbGeography argument.
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)
463 other.CheckNull("other");
464 return this.spatialSvcs.Intersects(this, other);
469 #region Geography Operations - Spatial Analysis
472 /// Creates a geography value representing all points less than or equal to <paramref name="distance"/> from this DbGeography value.
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)
479 if (!distance.HasValue)
481 throw EntityUtil.ArgumentNull("distance");
483 return this.spatialSvcs.Buffer(this, distance.Value);
487 /// Computes the distance between the closest points in this DbGeography value and another DbGeography value.
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)
494 other.CheckNull("other");
495 return this.spatialSvcs.Distance(this, other);
499 /// Computes the intersection of this DbGeography value and another DbGeography value.
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)
506 other.CheckNull("other");
507 return this.spatialSvcs.Intersection(this, other);
511 /// Computes the union of this DbGeography value and another DbGeography value.
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)
518 other.CheckNull("other");
519 return this.spatialSvcs.Union(this, other);
523 /// Computes the difference of this DbGeography value and another DbGeography value.
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)
530 other.CheckNull("other");
531 return this.spatialSvcs.Difference(this, other);
535 /// Computes the symmetric difference of this DbGeography value and another DbGeography value.
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)
542 other.CheckNull("other");
543 return this.spatialSvcs.SymmetricDifference(this, other);
548 #region Geography Collection
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>
554 public int? ElementCount { get { return this.spatialSvcs.GetElementCount(this); } }
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>
561 public DbGeography ElementAt(int index)
563 return this.spatialSvcs.ElementAt(this, index);
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>
574 public double? Latitude { get { return this.spatialSvcs.GetLatitude(this); } }
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>
580 public double? Longitude { get { return this.spatialSvcs.GetLongitude(this); } }
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>
586 public double? Elevation { get { return this.spatialSvcs.GetElevation(this); } }
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>
592 public double? Measure { get { return this.spatialSvcs.GetMeasure(this); } }
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.
601 public double? Length { get { return this.spatialSvcs.GetLength(this); } }
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.
606 public DbGeography StartPoint { get { return this.spatialSvcs.GetStartPoint(this); } }
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.
611 public DbGeography EndPoint { get { return this.spatialSvcs.GetEndPoint(this); } }
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.
616 public bool? IsClosed { get { return this.spatialSvcs.GetIsClosed(this); } }
620 #region LineString, Line, LinearRing
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>
626 public int? PointCount { get { return this.spatialSvcs.GetPointCount(this); } }
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>
633 public DbGeography PointAt(int index)
635 return this.spatialSvcs.PointAt(this, index);
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.
645 public double? Area { get { return this.spatialSvcs.GetArea(this); } }
651 /// Returns a string representation of the geography value.
653 public override string ToString()
655 return string.Format(CultureInfo.InvariantCulture, "SRID={1};{0}", this.WellKnownValue.WellKnownText ?? base.ToString(), this.CoordinateSystemId);