using System.Collections;
using GeoAPI.Geometries;
using GisSharpBlog.NetTopologySuite.Index;
using GisSharpBlog.NetTopologySuite.Index.Chain;
using GisSharpBlog.NetTopologySuite.Index.Strtree;
namespace GisSharpBlog.NetTopologySuite.Noding.Snapround
{
///
/// "Snaps" all s in a containing
/// s to a given .
///
public class MCIndexPointSnapper
{
///
///
///
// Public in java code... temporary modified for "safe assembly" in Sql2005
internal static readonly int numberSnaps = 0;
private IList monoChains = null;
private STRtree index = null;
///
/// Initializes a new instance of the class.
///
///
///
public MCIndexPointSnapper(IList monoChains, ISpatialIndex index)
{
this.monoChains = monoChains;
this.index = (STRtree) index;
}
///
///
///
private class QueryVisitor : IItemVisitor
{
IEnvelope env = null;
HotPixelSnapAction action = null;
///
///
///
///
///
public QueryVisitor(IEnvelope env, HotPixelSnapAction action)
{
this.env = env;
this.action = action;
}
///
///
///
public void VisitItem(object item)
{
MonotoneChain testChain = (MonotoneChain) item;
testChain.Select(env, action);
}
}
///
/// Snaps (nodes) all interacting segments to this hot pixel.
/// The hot pixel may represent a vertex of an edge,
/// in which case this routine uses the optimization
/// of not noding the vertex itself
///
/// The hot pixel to snap to.
/// The edge containing the vertex, if applicable, or null.
///
/// true if a node was added for this pixel.
public bool Snap(HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
{
IEnvelope pixelEnv = hotPixel.GetSafeEnvelope();
HotPixelSnapAction hotPixelSnapAction = new HotPixelSnapAction(hotPixel, parentEdge, vertexIndex);
index.Query(pixelEnv, new QueryVisitor(pixelEnv, hotPixelSnapAction));
return hotPixelSnapAction.IsNodeAdded;
}
///
///
///
///
///
public bool Snap(HotPixel hotPixel)
{
return Snap(hotPixel, null, -1);
}
///
///
///
public class HotPixelSnapAction : MonotoneChainSelectAction
{
private HotPixel hotPixel = null;
private SegmentString parentEdge = null;
private int vertexIndex;
private bool isNodeAdded = false;
///
/// Initializes a new instance of the class.
///
///
///
///
public HotPixelSnapAction(HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
{
this.hotPixel = hotPixel;
this.parentEdge = parentEdge;
this.vertexIndex = vertexIndex;
}
///
///
///
public bool IsNodeAdded
{
get
{
return isNodeAdded;
}
}
///
///
///
///
///
public override void Select(MonotoneChain mc, int startIndex)
{
SegmentString ss = (SegmentString) mc.Context;
// don't snap a vertex to itself
if (parentEdge != null)
if (ss == parentEdge && startIndex == vertexIndex)
return;
isNodeAdded = SimpleSnapRounder.AddSnappedNode(hotPixel, ss, startIndex);
}
}
}
}