-
Notifications
You must be signed in to change notification settings - Fork 310
/
ComponentGeometryExtractor.cs
47 lines (43 loc) · 1.63 KB
/
ComponentGeometryExtractor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections.Generic;
namespace NetTopologySuite.Geometries.Utilities
{
/// <summary>
/// Extracts a representative <see cref="Coordinate"/>
/// from each connected component of a <see cref="Geometry"/>.
/// </summary>
/// <version>1.9</version>
public class ComponentCoordinateExtracter : IGeometryComponentFilter
{
/// <summary>
/// Extracts a representative <see cref="Coordinate"/>
/// from each connected component in a geometry.
/// <para/>
/// If more than one geometry is to be processed, it is more
/// efficient to create a single <see cref="ComponentCoordinateExtracter"/>
/// instance and pass it to each geometry.
/// </summary>
/// <param name="geom">The Geometry from which to extract</param>
/// <returns>A list of representative Coordinates</returns>
public static List<Coordinate> GetCoordinates(Geometry geom)
{
var coords = new List<Coordinate>();
geom.Apply(new ComponentCoordinateExtracter(coords));
return coords;
}
private readonly List<Coordinate> _coords;
/// <summary>
/// Constructs a LineExtracterFilter with a list in which to store LineStrings found.
/// </summary>
public ComponentCoordinateExtracter(List<Coordinate> coords)
{
_coords = coords;
}
public void Filter(Geometry geom)
{
// add coordinates from connected components
if (geom is LineString
|| geom is Point)
_coords.Add(geom.Coordinate);
}
}
}