本文整理汇总了C#中Envelope.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# Envelope.Intersects方法的具体用法?C# Envelope.Intersects怎么用?C# Envelope.Intersects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Envelope
的用法示例。
在下文中一共展示了Envelope.Intersects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClipGeometryCollection
private static IGeometryCollection ClipGeometryCollection(IGeometryCollection geom, Envelope clipEnv)
{
var clipPoly = geom.Factory.ToGeometry(clipEnv);
var clipped = new List<IGeometry>();
for (var i = 0; i < geom.NumGeometries; i++)
{
var g = geom.GetGeometryN(i);
IGeometry result = null;
// don't clip unless necessary
if (clipEnv.Contains(g.EnvelopeInternal))
result = g;
else if (clipEnv.Intersects(g.EnvelopeInternal))
{
result = clipPoly.Intersection(g);
// keep vertex key info
result.UserData = g.UserData;
}
if (result != null && !result.IsEmpty)
{
clipped.Add(result);
}
}
return geom.Factory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(clipped));
}
示例2: TestQuadTree
public void TestQuadTree()
{
var qtree = new Index.Quadtree.Quadtree<IPoint>();
var ptBuilder = new Shape.Random.RandomPointsInGridBuilder { Extent = new Envelope(-500, 500, -500, 500), NumPoints = 600000, GutterFraction = 0.1d };
var mp = (IMultiPoint)ptBuilder.GetGeometry();
foreach (var coord in mp.Coordinates)
{
var point = GeometryFactory.Default.CreatePoint(coord);
qtree.Insert(point.EnvelopeInternal, point);
}
var search = new Envelope(4, 6, 4, 6);
var res = qtree.Query(search);
Assert.IsTrue(search.MinX == search.MinY && search.MinX == 4d);
Assert.IsTrue(search.MaxX == search.MaxY && search.MaxX == 6d);
Console.WriteLine(string.Format("Query returned: {0}", res.Count));
var reallyIntersecting = 0;
foreach (var point in res)
{
if (search.Intersects(point.EnvelopeInternal))
reallyIntersecting++;
//Assert.IsTrue(search.Intersects(point.EnvelopeInternal));
}
Console.WriteLine(string.Format("Really intersecting: {0}", reallyIntersecting));
Console.WriteLine(string.Format("Ratio: {0}", (double)reallyIntersecting / res.Count));
}
示例3: TestEverything
public void TestEverything()
{
Envelope e1 = new Envelope();
Assert.IsTrue(e1.IsNull);
Assert.AreEqual(0, e1.Width, 1E-3);
Assert.AreEqual(0, e1.Height, 1E-3);
e1.ExpandToInclude(100, 101);
e1.ExpandToInclude(200, 202);
e1.ExpandToInclude(150, 151);
Assert.AreEqual(200, e1.MaxX, 1E-3);
Assert.AreEqual(202, e1.MaxY, 1E-3);
Assert.AreEqual(100, e1.MinX, 1E-3);
Assert.AreEqual(101, e1.MinY, 1E-3);
Assert.IsTrue(e1.Contains(120, 120));
Assert.IsTrue(e1.Contains(120, 101));
Assert.IsTrue(!e1.Contains(120, 100));
Assert.AreEqual(101, e1.Height, 1E-3);
Assert.AreEqual(100, e1.Width, 1E-3);
Assert.IsTrue(!e1.IsNull);
Envelope e2 = new Envelope(499, 500, 500, 501);
Assert.IsTrue(!e1.Contains(e2));
Assert.IsTrue(!e1.Intersects(e2));
e1.ExpandToInclude(e2);
Assert.IsTrue(e1.Contains(e2));
Assert.IsTrue(e1.Intersects(e2));
Assert.AreEqual(500, e1.MaxX, 1E-3);
Assert.AreEqual(501, e1.MaxY, 1E-3);
Assert.AreEqual(100, e1.MinX, 1E-3);
Assert.AreEqual(101, e1.MinY, 1E-3);
Envelope e3 = new Envelope(300, 700, 300, 700);
Assert.IsTrue(!e1.Contains(e3));
Assert.IsTrue(e1.Intersects(e3));
Envelope e4 = new Envelope(300, 301, 300, 301);
Assert.IsTrue(e1.Contains(e4));
Assert.IsTrue(e1.Intersects(e4));
}
示例4: ExecuteIntersectionQuery
public override void ExecuteIntersectionQuery(Envelope bbox, FeatureDataSet ds)
{
var fdt = CreateTable();
fdt.BeginLoadData();
foreach (var relation in Matrix.Relations(RestrictId))
{
var origin = relation.Key;
var destin = relation.Value;
var box = origin.Value.EnvelopeInternal;
box.ExpandToInclude(destin.Value.EnvelopeInternal);
if (!bbox.Intersects(box))
continue;
var val = Matrix[origin.Key, destin.Key];
if (!Valid(val)) continue;
var fdr = (FeatureDataRow)fdt.LoadDataRow(new object[] { CreateOid(origin.Key, destin.Key), val }, true);
var sval = Scale(val);
if (origin.Key == destin.Key)
{
fdr.Geometry = CreateCircle(origin.Value, sval);
}
else
{
fdr.Geometry = CreateLoad(origin.Value, destin.Value, sval);
val = Matrix[destin.Key, origin.Key];
if (Valid(val))
{
sval = Scale(val);
fdr = (FeatureDataRow)fdt.LoadDataRow(new object[] { CreateOid(destin.Key, origin.Key), val }, true);
fdr.Geometry = CreateLoad(destin.Value, origin.Value, sval);
}
}
}
fdt.EndLoadData();
ds.Tables.Add(fdt);
}
示例5: GetGeometriesInView
public override Collection<IGeometry> GetGeometriesInView(Envelope bbox)
{
var res = new Collection<IGeometry>();
foreach (var relation in Matrix.Relations(RestrictId))
{
var origin = relation.Key;
var destin = relation.Value;
var box = origin.Value.EnvelopeInternal;
box.ExpandToInclude(destin.Value.EnvelopeInternal);
if (!bbox.Intersects(box))
continue;
var val = Matrix[origin.Key, destin.Key];
if (!Valid(val)) continue;
val = Scale(val);
if (origin.Key == destin.Key)
{
res.Add(CreateCircle(origin.Value, val));
}
else
{
res.Add(CreateLoad(origin.Value, destin.Value, val));
val = Matrix[destin.Key, origin.Key];
if (Valid(val))
{
val = Scale(val);
res.Add(CreateLoad(destin.Value, origin.Value, val));
}
}
}
return res;
}
示例6: IsInRegion
private bool IsInRegion(Map map, Envelope region)
{
if (region == null)
return true; // region not defined --> we can load the layer without waiting for map extent
if (map == null)
return false;
Envelope extent = map.Extent;
if (extent == null || extent.SpatialReference == null)
return false;
// KML LODS are based on the diagonal size
double regionSize = Math.Sqrt(region.Width * region.Width + region.Height * region.Height);
// Test that current map extent intersects the KML region
if (!region.Intersects(extent))
return false;
// Test the LOD level
double lod = regionSize / map.Resolution;
return !(lod < RegionInfo.MinLodPixels || (lod > RegionInfo.MaxLodPixels && RegionInfo.MaxLodPixels != -1)); // Keep ! to take care of NaN
}
示例7: GetObjectIDsInView
public override Collection<uint> GetObjectIDsInView(Envelope bbox)
{
var res = new Collection<uint>();
foreach (var relation in Matrix.Relations(RestrictId))
{
var origin = relation.Key;
var destin = relation.Value;
var box = origin.Value.EnvelopeInternal;
box.ExpandToInclude(destin.Value.EnvelopeInternal);
if (!bbox.Intersects(box))
continue;
var val = Matrix[origin.Key, destin.Key];
if (!Valid(val)) continue;
if (origin.Key == destin.Key)
res.Add(CreateOid(origin.Key, origin.Key));
else
{
res.Add(CreateOid(origin.Key, destin.Key));
val = Matrix[destin.Key, origin.Key];
if (Valid(val))
res.Add(CreateOid(destin.Key, origin.Key));
}
}
return res;
}
示例8: IntersectTreeRecursive
/// <summary>
/// Recursive function that traverses the tree and looks for intersections with a boundingbox
/// </summary>
/// <param name="box">Boundingbox to intersect with</param>
/// <param name="node">Node to search from</param>
/// <param name="list">List of found intersections</param>
private static void IntersectTreeRecursive(Envelope box, QuadTree node, /*ref*/ ICollection<uint> list)
{
if (node.IsLeaf) //Leaf has been reached
{
foreach (var boxObject in node._objList)
{
if(box.Intersects(boxObject.Box))
list.Add(boxObject.ID);
}
/*
for (int i = 0; i < node._objList.Count; i++)
{
list.Add(node._objList[i].ID);
}
*/
}
else
{
if (node.Box.Intersects(box))
{
if (node.Child0 != null)
IntersectTreeRecursive(box, node.Child0, /*ref*/ list);
if (node.Child1 != null)
IntersectTreeRecursive(box, node.Child1, /*ref*/ list);
}
}
}
示例9: ExecuteIntersectionQuery
public override void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds)
{
GetNonSpatialColumns();
using (var conn = GetConnection(ConnectionString))
{
var strSql = "SELECT " + _columns + ", \"" + GeometryColumn + "\" AS \"_smtmp_\" ";
strSql += "FROM " + Table + " WHERE ";
// Attribute constraint
if (!String.IsNullOrEmpty(_definitionQuery))
strSql += DefinitionQuery + " AND ";
// Spatial constraint
strSql += GetBoxClause(box);
using (var cmd = new SQLiteCommand(strSql, conn))
{
using (var reader = cmd.ExecuteReader())
{
var geomIndex = reader.FieldCount - 1;
var fdt = CreateTableFromReader(reader, geomIndex);
var dataTransfer = new object[geomIndex];
var geoReader = new GaiaGeoReader(Factory.CoordinateSequenceFactory, Factory.PrecisionModel,
_ordinates);
fdt.BeginLoadData();
while (reader.Read())
{
IGeometry g = null;
if (!reader.IsDBNull(geomIndex))
g = geoReader.Read((byte[])reader.GetValue(geomIndex));
//No geometry, no feature!
if (g == null)
continue;
//If not using RTree index we need to filter in code
if (_spatiaLiteIndex != SpatiaLiteIndex.RTree && !box.Intersects(g.EnvelopeInternal))
continue;
//Get all the attribute data
var count = reader.GetValues(dataTransfer);
System.Diagnostics.Debug.Assert(count == dataTransfer.Length);
var fdr = (FeatureDataRow)fdt.LoadDataRow(dataTransfer, true);
fdr.Geometry = g;
}
reader.Close();
fdt.EndLoadData();
ds.Tables.Add(fdt);
}
}
}
}
示例10: GetGeometriesInView
/// <summary>
/// Returns features within the specified bounding box
/// </summary>
/// <param name="bbox"></param>
/// <returns></returns>
public Collection<IGeometry> GetGeometriesInView(Envelope bbox)
{
var list = new Collection<IGeometry>();
lock (_features)
{
foreach (FeatureDataRow fdr in _features.Rows)
if (!fdr.Geometry.IsEmpty)
if (FilterDelegate == null || FilterDelegate(fdr))
{
if (bbox.Intersects(fdr.Geometry.EnvelopeInternal))
list.Add(fdr.Geometry);
}
}
return list;
}
示例11: DownloadDisclaimer
private void DownloadDisclaimer(double[] ul, double[] lr, string level)
{
try
{
//level = m_TileSource.Schema.Resolutions.Count - level;
string mapType = "";
if (_mapType == MapType.Images)
mapType = "k";
else if (_mapType == MapType.Hybrid)
{
mapType = "h";
}
//string url = string.Format(CultureInfo.InvariantCulture, "http://maps.googleapis.com/maps/api/js/ViewportInfoService.GetViewportInfo?1m6&1m2&1d{0}&2d{1}&2m2&1d{2}&2d{3}&2u{7}&4s{4}&5e{6}&callback=resp&token={5}", lr[1], ul[0], ul[1], lr[0], m_Language, 12345, (int)m_MapType, level);
var url = string.Format(CultureInfo.InvariantCulture, "http://maps.google.com/maps/vp?spn={0},{1}&t={5}&z={2}&key=&mapclient=jsapi&vp={3},{4}&ev=mk",
ul[1] - lr[1], lr[0] - ul[0], level, (lr[1] + ul[1]) / 2.0, (ul[0] + lr[0]) / 2.0, mapType);
var rq = (HttpWebRequest)WebRequest.Create(url);
rq.Referer = "http://localhost";
rq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1";
string json;
using (var s = rq.GetResponse().GetResponseStream())
{
if (s == null)
throw new WebException("Failed to get web response stream");
json = new StreamReader(s).ReadToEnd();
}
var mstrs = new List<string>();
var kstrs = new List<string>();
var bbox = new Envelope(new Coordinate(ul[0],lr[1]),new Coordinate(lr[0],ul[1]));
var levelId = int.Parse(level, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
foreach (Match m in _rex.Matches(json))
{
if (m.Groups["txt"].Success && !string.IsNullOrEmpty(m.Groups["txt"].Value))
{
int minLevel = int.Parse(m.Groups["minlevel"].Value);
int maxLevel = int.Parse(m.Groups["maxlevel"].Value);
if (levelId < minLevel || levelId > maxLevel)
continue;
double minx = double.Parse(m.Groups["minx"].Value, CultureInfo.InvariantCulture);
double miny = double.Parse(m.Groups["miny"].Value, CultureInfo.InvariantCulture);
double maxx = double.Parse(m.Groups["maxx"].Value, CultureInfo.InvariantCulture);
double maxy = double.Parse(m.Groups["maxy"].Value, CultureInfo.InvariantCulture);
if (bbox.Intersects(new Envelope(minx, maxx, miny, maxy)))
{
if (m.Groups["type"].Value == "m")
{
if (!mstrs.Contains(m.Groups["txt"].Value))
mstrs.Add(m.Groups["txt"].Value);
}
else
{
if (!kstrs.Contains(m.Groups["txt"].Value))
{
kstrs.Add(m.Groups["txt"].Value);
}
}
}
}
}
string txt = "";
if (_mapType == MapType.Map || _mapType == MapType.Hybrid)
{
txt = MapPrefix + " " + string.Join(",", mstrs.ToArray());
}
else if ( _mapType == MapType.Images)
{
txt = SatellitePrefix + " " + string.Join(",",kstrs.ToArray());
}
if (_mapType == MapType.Hybrid)
{
txt += ", " + SatellitePrefix + " " + string.Join(",", kstrs.ToArray());
}
_disclaimerText = txt;
/*if (rex.IsMatch(jSon))
{
Match m = rex.Match(jSon);
if (m.Groups["text"].Success)
{
m_DisclaymerText = m.Groups["text"].Value;
}
}*/
}
catch (Exception ex)
{
if (Log.IsDebugEnabled)
Log.Debug(ex);
}
}
示例12: GetObjectIDsInView
/// <summary>
/// Returns all objects whose boundingbox intersects 'bbox'.
/// </summary>
/// <param name="bbox"></param>
/// <returns></returns>
public override Collection<uint> GetObjectIDsInView(Envelope bbox)
{
var list = new Collection<uint>();
for (int i = 0; i < _geometries.Count; i++)
if (bbox.Intersects(_geometries[i].EnvelopeInternal))
list.Add((uint) i);
return list;
}
示例13: GetGeometriesInView
/// <summary>
/// Returns features within the specified bounding box
/// </summary>
/// <param name="bbox"></param>
/// <returns></returns>
public override Collection<IGeometry> GetGeometriesInView(Envelope bbox)
{
var list = new Collection<IGeometry>();
for (var i = 0; i < _geometries.Count; i++)
if (!_geometries[i].IsEmpty)
if (bbox.Intersects(_geometries[i].EnvelopeInternal))
list.Add(_geometries[i]);
return list;
}
示例14: ExecuteIntersectionQuery
/// <summary>
/// Returns the data associated with all the geometries that are intersected by 'geom'
/// </summary>
/// <param name="box">Geometry to intersect with</param>
/// <param name="ds">FeatureDataSet to fill data into</param>
public override void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds)
{
var table = (FeatureDataTable)_baseTable.Copy();
table.TableName = _content.TableName;
table.BeginLoadData();
using (var rdr = CreateReader(7, box))
{
if (rdr.HasRows)
{
var geometryIndex = rdr.FieldCount - 1;
while (rdr.Read())
{
var geom = _reader.Read((byte[])rdr.GetValue(geometryIndex));
if (geom.Header.IsEmpty) continue;
if (!box.Intersects(geom.Header.Extent)) continue;
var data = new object[geometryIndex];
rdr.GetValues(data);
var fdr = (FeatureDataRow) table.LoadDataRow(data, true);
fdr.Geometry = geom.GetGeometry();
}
}
}
table.EndLoadData();
if (table.Rows.Count > 0)
ds.Tables.Add(table);
}
示例15: GetGeometriesInView
/// <summary>
/// Gets the features within the specified <see cref="GeoAPI.Geometries.Envelope"/>
/// </summary>
/// <param name="bbox"></param>
/// <returns>Features within the specified <see cref="GeoAPI.Geometries.Envelope"/></returns>
public override Collection<IGeometry> GetGeometriesInView(Envelope bbox)
{
var res = new Collection<IGeometry>();
using (var reader = CreateReader(2, bbox))
{
while (reader.Read())
{
var gpkg = _reader.Read((byte[]) reader.GetValue(0));
if (gpkg.Header.IsEmpty) continue;
if (bbox.Intersects(gpkg.Header.Extent))
res.Add(gpkg.GetGeometry());
//else
//{
// System.Threading.Thread.Sleep(1);
//}
}
}
return res;
}