本文整理汇总了C#中IEnvelope.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# IEnvelope.Contains方法的具体用法?C# IEnvelope.Contains怎么用?C# IEnvelope.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnvelope
的用法示例。
在下文中一共展示了IEnvelope.Contains方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvertSelection
/// <summary>
/// Inverts the selection based on the current SelectionMode
/// </summary>
/// <param name="region">The geographic region to reverse the selected state</param>
/// <param name="affectedArea">The affected area to invert</param>
public bool InvertSelection(IEnvelope region, out IEnvelope affectedArea)
{
SuspendChanges();
bool flipped = false;
affectedArea = new Envelope();
IDictionary<IFeature, IDrawnState> states = Filter.DrawnStates;
foreach (KeyValuePair<IFeature, IDrawnState> kvp in states)
{
bool doFlip = false;
IFeature f = kvp.Key;
if (SelectionMode == SelectionMode.IntersectsExtent)
{
if (region.Intersects(f.Envelope))
{
kvp.Value.IsSelected = !kvp.Value.IsSelected;
affectedArea.ExpandToInclude(f.Envelope);
}
}
else if (SelectionMode == SelectionMode.ContainsExtent)
{
if (region.Contains(f.Envelope))
{
kvp.Value.IsSelected = !kvp.Value.IsSelected;
affectedArea.ExpandToInclude(f.Envelope);
}
}
IPolygon reg = region.ToPolygon();
IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry);
switch (SelectionMode)
{
case SelectionMode.Contains:
if (region.Intersects(f.Envelope))
{
if (reg.Contains(geom)) doFlip = true;
}
break;
case SelectionMode.CoveredBy:
if (reg.CoveredBy(geom)) doFlip = true;
break;
case SelectionMode.Covers:
if (reg.Covers(geom)) doFlip = true;
break;
case SelectionMode.Disjoint:
if (reg.Disjoint(geom)) doFlip = true;
break;
case SelectionMode.Intersects:
if (region.Intersects(f.Envelope))
{
if (reg.Intersects(geom)) doFlip = true;
}
break;
case SelectionMode.Overlaps:
if (reg.Overlaps(geom)) doFlip = true;
break;
case SelectionMode.Touches:
if (reg.Touches(geom)) doFlip = true;
break;
case SelectionMode.Within:
if (reg.Within(geom)) doFlip = true;
break;
}
if (doFlip)
{
flipped = true;
kvp.Value.IsSelected = !kvp.Value.IsSelected;
affectedArea.ExpandToInclude(f.Envelope);
}
}
ResumeChanges();
return flipped;
}
示例2: RemoveRegion
/// <summary>
/// Tests each member currently in the selected features based on
/// the SelectionMode. If it passes, it will remove the feature from
/// the selection.
/// </summary>
/// <param name="region">The geographic region to remove</param>
/// <param name="affectedArea">A geographic area that was affected by this change.</param>
/// <returns>Boolean, true if the collection was changed</returns>
public bool RemoveRegion(IEnvelope region, out IEnvelope affectedArea)
{
SuspendChanges();
bool removed = false;
affectedArea = new Envelope();
var query = from pair in _filter.DrawnStates
where pair.Value.IsSelected
select pair.Key;
List<IFeature> selectedFeatures = query.ToList();
foreach (IFeature f in selectedFeatures)
{
bool doRemove = false;
if (_selectionMode == SelectionMode.IntersectsExtent)
{
if (region.Intersects(f.Envelope))
{
if (Remove(f))
{
removed = true;
affectedArea.ExpandToInclude(f.Envelope);
}
}
}
else if (_selectionMode == SelectionMode.ContainsExtent)
{
if (region.Contains(f.Envelope))
{
if (Remove(f))
{
removed = true;
affectedArea.ExpandToInclude(f.Envelope);
}
}
}
IPolygon reg = region.ToPolygon();
IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry);
switch (_selectionMode)
{
case SelectionMode.Contains:
if (region.Intersects(f.Envelope))
{
if (reg.Contains(geom)) doRemove = true;
}
break;
case SelectionMode.CoveredBy:
if (reg.CoveredBy(geom)) doRemove = true;
break;
case SelectionMode.Covers:
if (reg.Covers(geom)) doRemove = true;
break;
case SelectionMode.Disjoint:
if (reg.Disjoint(geom)) doRemove = true;
break;
case SelectionMode.Intersects:
if (region.Intersects(f.Envelope))
{
if (reg.Intersects(geom)) doRemove = true;
}
break;
case SelectionMode.Overlaps:
if (reg.Overlaps(geom)) doRemove = true;
break;
case SelectionMode.Touches:
if (reg.Touches(geom)) doRemove = true;
break;
case SelectionMode.Within:
if (reg.Within(geom)) doRemove = true;
break;
}
if (doRemove)
{
if (Remove(f))
{
affectedArea.ExpandToInclude(f.Envelope);
removed = true;
}
}
}
ResumeChanges();
return removed;
}
示例3: AddRegion
/// <summary>
/// This uses extent checking (rather than full polygon intersection checking). It will add
/// any members that are either contained by or intersect with the specified region
/// depending on the SelectionMode property. The order of operation is the region
/// acting on the feature, so Contains, for instance, would work with points.
/// </summary>
/// <param name="region"></param>
/// <param name="affectedArea">The affected area of this addition</param>
/// <returns>True if any item was actually added to the collection</returns>
public bool AddRegion(IEnvelope region, out IEnvelope affectedArea)
{
bool added = false;
SuspendChanges();
affectedArea = new Envelope();
Stopwatch sw = new Stopwatch();
Stopwatch total = new Stopwatch();
total.Start();
foreach (IFeature f in FeatureList)
{
bool doAdd = false;
if (_selectionMode == SelectionMode.IntersectsExtent)
{
if (region.Intersects(f.Envelope))
{
Add(f);
affectedArea.ExpandToInclude(f.Envelope);
added = true;
}
}
else if (_selectionMode == SelectionMode.ContainsExtent)
{
if (region.Contains(f.Envelope))
{
Add(f);
affectedArea.ExpandToInclude(f.Envelope);
added = true;
}
}
IGeometry reg;
if (region.Width == 0 && region.Height == 0)
{
reg = new Point(region.X, region.Y);
}
else if (region.Height == 0 || region.Width == 0)
{
Coordinate[] coords = new Coordinate[2];
coords[0] = new Coordinate(region.X, region.Y);
coords[1] = new Coordinate(region.Bottom(), region.Right());
reg = new LineString(coords);
}
else
{
reg = region.ToPolygon();
}
IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry);
switch (_selectionMode)
{
case SelectionMode.Contains:
if (region.Contains(f.Envelope))
{
doAdd = true;
}
else if (region.Intersects(f.Envelope))
{
if (reg.Contains(geom)) doAdd = true;
}
break;
case SelectionMode.CoveredBy:
if (reg.CoveredBy(geom)) doAdd = true;
break;
case SelectionMode.Covers:
if (reg.Covers(geom)) doAdd = true;
break;
case SelectionMode.Disjoint:
if (reg.Disjoint(geom)) doAdd = true;
break;
case SelectionMode.Intersects:
if (region.Contains(f.Envelope))
{
doAdd = true;
}
else if (region.Intersects(f.Envelope))
{
if (reg.Intersects(geom)) doAdd = true;
}
break;
case SelectionMode.Overlaps:
if (reg.Overlaps(geom)) doAdd = true;
break;
case SelectionMode.Touches:
if (reg.Touches(geom)) doAdd = true;
break;
case SelectionMode.Within:
if (reg.Within(geom)) doAdd = true;
break;
}
//.........这里部分代码省略.........
示例4: ComputeKey
/// <summary>
/// Return a square envelope containing the argument envelope,
/// whose extent is a power of two and which is based at a power of 2.
/// </summary>
/// <param name="itemEnv"></param>
public void ComputeKey(IEnvelope itemEnv)
{
level = ComputeQuadLevel(itemEnv);
env = new Envelope();
ComputeKey(level, itemEnv);
// MD - would be nice to have a non-iterative form of this algorithm
while (!env.Contains(itemEnv))
{
level += 1;
ComputeKey(level, itemEnv);
}
}
示例5: HandleBoundaries
/// <summary>
/// The original algorithm simply allows edges that have one defined point and
/// another "NAN" point. Simply excluding the not a number coordinates fails
/// to preserve the known direction of the ray. We only need to extend this
/// long enough to encounter the bounding box, not infinity.
/// </summary>
/// <param name="graph">The VoronoiGraph with the edge list</param>
/// <param name="bounds">The polygon bounding the datapoints</param>
private static void HandleBoundaries(VoronoiGraph graph, IEnvelope bounds)
{
List<ILineString> boundSegments = new List<ILineString>();
List<VoronoiEdge> unboundEdges = new List<VoronoiEdge>();
// Identify bound edges for intersection testing
foreach (VoronoiEdge edge in graph.Edges)
{
if(edge.VVertexA.ContainsNan() || edge.VVertexB.ContainsNan())
{
unboundEdges.Add(edge);
continue;
}
boundSegments.Add(new LineString(new List<Coordinate>{edge.VVertexA.ToCoordinate(), edge.VVertexB.ToCoordinate()}));
}
// calculate a length to extend a ray to look for intersections
IEnvelope env = bounds;
double h = env.Height;
double w = env.Width;
double len = Math.Sqrt(w * w + h * h); // len is now long enough to pass entirely through the dataset no matter where it starts
foreach (VoronoiEdge edge in unboundEdges)
{
// the unbound line passes thorugh start
Coordinate start = (edge.VVertexB.ContainsNan())
? edge.VVertexA.ToCoordinate()
: edge.VVertexB.ToCoordinate();
// the unbound line should have a direction normal to the line joining the left and right source points
double dx = edge.LeftData.X - edge.RightData.X;
double dy = edge.LeftData.Y - edge.RightData.Y;
double l = Math.Sqrt(dx*dx + dy*dy);
// the slope of the bisector between left and right
double sx = -dy/l;
double sy = dx/l;
Coordinate center = bounds.Center();
if((start.X > center.X && start.Y > center.Y) || (start.X < center.X && start.Y < center.Y))
{
sx = dy/l;
sy = -dx/l;
}
Coordinate end1 = new Coordinate(start.X + len*sx, start.Y + len * sy);
Coordinate end2 = new Coordinate(start.X - sx * len, start.Y - sy * len);
Coordinate end = (end1.Distance(center) < end2.Distance(center)) ? end2 : end1;
if(bounds.Contains(end))
{
end = new Coordinate(start.X - sx * len, start.Y - sy * len);
}
if (edge.VVertexA.ContainsNan())
{
edge.VVertexA = new Vector2(end.ToArray());
}
else
{
edge.VVertexB = new Vector2(end.ToArray());
}
}
}
示例6: Overlaps
/// <summary>
/// Overlaps is defined as intersecting, but having some part of each envelope that is also outside
/// of the other envelope. Therefore it would amount to saying "Intersects And Not Contains And Not Within"
/// </summary>
/// <param name="self">The IEnvelope to use with this method</param>
/// <param name="other"></param>
/// <returns></returns>
public static bool Overlaps(this IEnvelope self, IEnvelope other)
{
if (self.Intersects(other) == false) return false;
if (self.Contains(other)) return false;
if (other.Contains(self)) return false;
return true;
}
示例7: GetShapeAtIndex
/// <inheritdocs/>
protected override Shape GetShapeAtIndex(FileStream fs, ShapefileIndexFile shx, ShapefileHeader header, int shp, IEnvelope envelope)
{
// Read from the index file because some deleted records
// might still exist in the .shp file.
long offset = (shx.Shapes[shp].ByteOffset);
fs.Seek(offset, SeekOrigin.Begin);
Shape myShape = new Shape();
// Position Value Type Number Byte Order
ShapeRange shape = new ShapeRange(FeatureType.Point); //--------------------------------------------------------------------
shape.RecordNumber = fs.ReadInt32(Endian.BigEndian); // Byte 0 Record Number Integer 1 Big
shape.ContentLength = fs.ReadInt32(Endian.BigEndian); // Byte 4 Content Length Integer 1 Big
ShapeType shapeType = (ShapeType)fs.ReadInt32(); // Byte 8 Shape Type Integer 1 Little
if (shapeType == ShapeType.NullShape)
{
return null;
}
double[] vertices = fs.ReadDouble(2);
double x = vertices[0], y = vertices[1];
// Don't add this shape to the result
if (envelope != null)
{
if (!envelope.Contains(new Coordinate(x, y)))
{
return null;
}
}
shape.StartIndex = 0;
shape.NumParts = 1;
shape.NumPoints = 1;
shape.ShapeType = shapeType;
shape.Extent = new Extent(x, y, x, y);
myShape.Range = shape;
myShape.Vertices = vertices;
if (header.ShapeType == ShapeType.PointM)
{
myShape.M = fs.ReadDouble(1);
myShape.MinM = myShape.MaxM = myShape.M[0];
shape.Extent = new ExtentM(shape.Extent, myShape.MinM, myShape.MaxM);
}
else if (header.ShapeType == ShapeType.PointZ)
{
// For Z shapefiles, the Z part is not optional.
myShape.Z = fs.ReadDouble(1);
myShape.MinZ = myShape.MaxZ = myShape.Z[0];
myShape.M = fs.ReadDouble(1);
myShape.MinM = myShape.MaxM = myShape.M[0];
shape.Extent = new ExtentMZ(shape.Extent.MinX, shape.Extent.MinY, myShape.MinM, myShape.MinZ, shape.Extent.MaxX, shape.Extent.MaxY, myShape.MaxM, myShape.MaxZ);
}
PartRange partR = new PartRange(myShape.Vertices, 0, 0, FeatureType.Point) { NumVertices = 1 };
shape.Parts.Add(partR);
myShape.Range = shape;
return myShape;
}