/Branches/0.9-GeoJSON/SharpMap/Geometries/MultiLineString.cs

# · C# · 262 lines · 125 code · 27 blank · 110 comment · 15 complexity · d8eeb8eafdcd7baf8ef20568c041225a MD5 · raw file

  1. // Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
  2. //
  3. // This file is part of SharpMap.
  4. // SharpMap is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // SharpMap is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. // You should have received a copy of the GNU Lesser General Public License
  14. // along with SharpMap; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Collections.ObjectModel;
  19. namespace SharpMap.Geometries
  20. {
  21. /// <summary>
  22. /// A MultiLineString is a MultiCurve whose elements are LineStrings.
  23. /// </summary>
  24. [Serializable]
  25. public class MultiLineString : MultiCurve
  26. {
  27. private IList<LineString> _LineStrings;
  28. /// <summary>
  29. /// Initializes an instance of a MultiLineString
  30. /// </summary>
  31. public MultiLineString()
  32. {
  33. _LineStrings = new Collection<LineString>();
  34. }
  35. /// <summary>
  36. /// Collection of <see cref="LineString">LineStrings</see> in the <see cref="MultiLineString"/>
  37. /// </summary>
  38. public IList<LineString> LineStrings
  39. {
  40. get { return _LineStrings; }
  41. set { _LineStrings = value; }
  42. }
  43. /// <summary>
  44. /// Returns an indexed geometry in the collection
  45. /// </summary>
  46. /// <param name="index">Geometry index</param>
  47. /// <returns>Geometry at index</returns>
  48. public new LineString this[int index]
  49. {
  50. get { return _LineStrings[index]; }
  51. }
  52. /// <summary>
  53. /// Returns true if all LineStrings in this MultiLineString is closed (StartPoint=EndPoint for each LineString in this MultiLineString)
  54. /// </summary>
  55. public override bool IsClosed
  56. {
  57. get
  58. {
  59. for (int i = 0; i < _LineStrings.Count; i++)
  60. if (!_LineStrings[i].IsClosed)
  61. return false;
  62. return true;
  63. }
  64. }
  65. /// <summary>
  66. /// The length of this MultiLineString which is equal to the sum of the lengths of the element LineStrings.
  67. /// </summary>
  68. public override double Length
  69. {
  70. get
  71. {
  72. double l = 0;
  73. for (int i = 0; i < _LineStrings.Count; i++)
  74. l += _LineStrings[i].Length;
  75. return l;
  76. }
  77. }
  78. /// <summary>
  79. /// Returns the number of geometries in the collection.
  80. /// </summary>
  81. public override int NumGeometries
  82. {
  83. get { return _LineStrings.Count; }
  84. }
  85. /// <summary>
  86. /// If true, then this Geometry represents the empty point set, ?, for the coordinate space.
  87. /// </summary>
  88. /// <returns>Returns 'true' if this Geometry is the empty geometry</returns>
  89. public override bool IsEmpty()
  90. {
  91. if (_LineStrings == null || _LineStrings.Count == 0)
  92. return true;
  93. for (int i = 0; i < _LineStrings.Count; i++)
  94. if (!_LineStrings[i].IsEmpty())
  95. return false;
  96. return true;
  97. }
  98. /// <summary>
  99. /// Returns 'true' if this Geometry has no anomalous geometric points, such as self
  100. /// intersection or self tangency. The description of each instantiable geometric class will include the specific
  101. /// conditions that cause an instance of that class to be classified as not simple.
  102. /// </summary>
  103. /// <returns>true if the geometry is simple</returns>
  104. public override bool IsSimple()
  105. {
  106. throw new NotImplementedException();
  107. }
  108. /// <summary>
  109. /// Returns the closure of the combinatorial boundary of this Geometry. The
  110. /// combinatorial boundary is defined as described in section 3.12.3.2 of [1]. Because the result of this function
  111. /// is a closure, and hence topologically closed, the resulting boundary can be represented using
  112. /// representational geometry primitives
  113. /// </summary>
  114. /// <returns>Closure of the combinatorial boundary of this Geometry</returns>
  115. public override Geometry Boundary()
  116. {
  117. throw new NotImplementedException();
  118. }
  119. /// <summary>
  120. /// Returns the shortest distance between any two points in the two geometries
  121. /// as calculated in the spatial reference system of this Geometry.
  122. /// </summary>
  123. /// <param name="geom">Geometry to calculate distance to</param>
  124. /// <returns>Shortest distance between any two points in the two geometries</returns>
  125. public override double Distance(Geometry geom)
  126. {
  127. throw new NotImplementedException();
  128. }
  129. /// <summary>
  130. /// Returns a geometry that represents all points whose distance from this Geometry
  131. /// is less than or equal to distance. Calculations are in the Spatial Reference
  132. /// System of this Geometry.
  133. /// </summary>
  134. /// <param name="d">Buffer distance</param>
  135. /// <returns>Buffer around geometry</returns>
  136. public override Geometry Buffer(double d)
  137. {
  138. throw new NotImplementedException();
  139. }
  140. /// <summary>
  141. /// Geometry?eturns a geometry that represents the convex hull of this Geometry.
  142. /// </summary>
  143. /// <returns>The convex hull</returns>
  144. public override Geometry ConvexHull()
  145. {
  146. throw new NotImplementedException();
  147. }
  148. /// <summary>
  149. /// Returns a geometry that represents the point set intersection of this Geometry
  150. /// with anotherGeometry.
  151. /// </summary>
  152. /// <param name="geom">Geometry to intersect with</param>
  153. /// <returns>Returns a geometry that represents the point set intersection of this Geometry with anotherGeometry.</returns>
  154. public override Geometry Intersection(Geometry geom)
  155. {
  156. throw new NotImplementedException();
  157. }
  158. /// <summary>
  159. /// Returns a geometry that represents the point set union of this Geometry with anotherGeometry.
  160. /// </summary>
  161. /// <param name="geom">Geometry to union with</param>
  162. /// <returns>Unioned geometry</returns>
  163. public override Geometry Union(Geometry geom)
  164. {
  165. throw new NotImplementedException();
  166. }
  167. /// <summary>
  168. /// Returns a geometry that represents the point set difference of this Geometry with anotherGeometry.
  169. /// </summary>
  170. /// <param name="geom">Geometry to compare to</param>
  171. /// <returns>Geometry</returns>
  172. public override Geometry Difference(Geometry geom)
  173. {
  174. throw new NotImplementedException();
  175. }
  176. /// <summary>
  177. /// Returns a geometry that represents the point set symmetric difference of this Geometry with anotherGeometry.
  178. /// </summary>
  179. /// <param name="geom">Geometry to compare to</param>
  180. /// <returns>Geometry</returns>
  181. public override Geometry SymDifference(Geometry geom)
  182. {
  183. throw new NotImplementedException();
  184. }
  185. /// <summary>
  186. /// Returns an indexed geometry in the collection
  187. /// </summary>
  188. /// <param name="N">Geometry index</param>
  189. /// <returns>Geometry at index N</returns>
  190. public override Geometry Geometry(int N)
  191. {
  192. return _LineStrings[N];
  193. }
  194. /// <summary>
  195. /// The minimum bounding box for this Geometry.
  196. /// </summary>
  197. /// <returns></returns>
  198. public override BoundingBox GetBoundingBox()
  199. {
  200. if (_LineStrings == null || _LineStrings.Count == 0)
  201. return null;
  202. BoundingBox bbox = _LineStrings[0].GetBoundingBox();
  203. for (int i = 1; i < _LineStrings.Count; i++)
  204. bbox = bbox.Join(_LineStrings[i].GetBoundingBox());
  205. return bbox;
  206. }
  207. /// <summary>
  208. /// Return a copy of this geometry
  209. /// </summary>
  210. /// <returns>Copy of Geometry</returns>
  211. public new MultiLineString Clone()
  212. {
  213. MultiLineString geoms = new MultiLineString();
  214. for (int i = 0; i < _LineStrings.Count; i++)
  215. geoms.LineStrings.Add(_LineStrings[i].Clone());
  216. return geoms;
  217. }
  218. /// <summary>
  219. /// Gets an enumerator for enumerating the geometries in the GeometryCollection
  220. /// </summary>
  221. /// <returns></returns>
  222. public override IEnumerator<Geometry> GetEnumerator()
  223. {
  224. foreach (LineString l in _LineStrings)
  225. yield return l;
  226. }
  227. public override GeometryType2 GeometryType
  228. {
  229. get
  230. {
  231. return GeometryType2.MultiLineString;
  232. }
  233. }
  234. }
  235. }