GeoJsonFeature.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using MongoDB.Bson;
  16. using MongoDB.Bson.Serialization.Attributes;
  17. using MongoDB.Driver.GeoJsonObjectModel.Serializers;
  18. namespace MongoDB.Driver.GeoJsonObjectModel
  19. {
  20. /// <summary>
  21. /// Represents a GeoJson Feature object.
  22. /// </summary>
  23. /// <typeparam name="TCoordinates">The type of the coordinates.</typeparam>
  24. [BsonSerializer(typeof(GeoJsonFeatureSerializer<>))]
  25. public class GeoJsonFeature<TCoordinates> : GeoJsonObject<TCoordinates> where TCoordinates : GeoJsonCoordinates
  26. {
  27. // private fields
  28. private GeoJsonGeometry<TCoordinates> _geometry;
  29. private BsonValue _id;
  30. private BsonDocument _properties;
  31. // constructors
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="GeoJsonFeature{TCoordinates}"/> class.
  34. /// </summary>
  35. /// <param name="geometry">The geometry.</param>
  36. public GeoJsonFeature(GeoJsonGeometry<TCoordinates> geometry)
  37. : this(null, geometry)
  38. {
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="GeoJsonFeature{TCoordinates}"/> class.
  42. /// </summary>
  43. /// <param name="args">The additional args.</param>
  44. /// <param name="geometry">The geometry.</param>
  45. public GeoJsonFeature(GeoJsonFeatureArgs<TCoordinates> args, GeoJsonGeometry<TCoordinates> geometry)
  46. : base(args)
  47. {
  48. _geometry = geometry;
  49. if (args != null)
  50. {
  51. _id = args.Id;
  52. _properties = args.Properties;
  53. }
  54. }
  55. // public properties
  56. /// <summary>
  57. /// Gets the geometry.
  58. /// </summary>
  59. public GeoJsonGeometry<TCoordinates> Geometry
  60. {
  61. get { return _geometry; }
  62. }
  63. /// <summary>
  64. /// Gets the id.
  65. /// </summary>
  66. public BsonValue Id
  67. {
  68. get { return _id; }
  69. }
  70. /// <summary>
  71. /// Gets the properties.
  72. /// </summary>
  73. public BsonDocument Properties
  74. {
  75. get { return _properties; }
  76. }
  77. /// <summary>
  78. /// Gets the type of the GeoJson object.
  79. /// </summary>
  80. public override GeoJsonObjectType Type
  81. {
  82. get { return GeoJsonObjectType.Feature; }
  83. }
  84. }
  85. }