-
Notifications
You must be signed in to change notification settings - Fork 310
/
GeometryCollectionMapper.cs
55 lines (51 loc) · 1.61 KB
/
GeometryCollectionMapper.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
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
namespace NetTopologySuite.Geometries.Utilities
{
/// <summary>
/// Maps the members of a <see cref="GeometryCollection"/>
/// into another <tt>GeometryCollection</tt> via a defined
/// mapping function.
/// </summary>
/// <author>Martin Davis</author>
public class GeometryCollectionMapper
{
/// <summary>
///
/// </summary>
/// <param name="gc"></param>
/// <param name="op"></param>
/// <returns></returns>
public static GeometryCollection Map(GeometryCollection gc, Func<Geometry, Geometry> op)
{
var mapper = new GeometryCollectionMapper(op);
return mapper.Map(gc);
}
private readonly Func<Geometry, Geometry> _mapOp;
/// <summary>
/// Creates an instance of this class
/// </summary>
/// <param name="mapOp"></param>
public GeometryCollectionMapper(Func<Geometry, Geometry> mapOp)
{
_mapOp = mapOp;
}
/// <summary>
///
/// </summary>
/// <param name="gc"></param>
/// <returns></returns>
public GeometryCollection Map(GeometryCollection gc)
{
var mapped = new List<Geometry>();
for (int i = 0; i < gc.NumGeometries; i++)
{
var g = _mapOp(gc.GetGeometryN(i));
if (!g.IsEmpty)
mapped.Add(g);
}
return gc.Factory.CreateGeometryCollection(
GeometryFactory.ToGeometryArray(mapped));
}
}
}