private IEnumerable <IFeature> EnumerateFeatures(IPreparedGeometry preparedGeometry) { lock (_featuresLock) { uint id = 0; if (FilterDelegate == null) { foreach (var feature in _features) { var geom = feature.Geometry; if (preparedGeometry.Intersects(feature.Geometry)) { yield return(feature); } id++; } } else { foreach (var feature in _features) { if (FilterDelegate(feature) && preparedGeometry.Intersects(feature.Geometry)) { yield return(feature); } id++; } } } }
public override void Setup() { var sinePoly = CreateSineStar(new Coordinate(0, 0), 100000.0, nPts); _preparedGeometry = PreparedGeometryFactory.Prepare(sinePoly); WaitHandles = new WaitHandle[ThreadTestRunner.DefaultThreadCount]; }
/// <summary> /// Adds an index to this class internally to compute spatial relations faster. In NTS this /// is called a <see cref="IPreparedGeometry"/>. This /// isn't done by default because it takes some time to do the optimization, and it uses more /// memory. Calling this method isn't thread-safe so be careful when this is done. If it was /// already indexed then nothing happens. /// </summary> public virtual void Index() { if (preparedGeometry == null) { preparedGeometry = PreparedGeometryFactory.Prepare(geom); } }
private IPolygon GetResult() { IGeometryFactory gf = _poly.Factory; ILinearRing shell = (ILinearRing)_poly.ExteriorRing; IPreparedGeometry shellPrep = PreparedGeometryFactory.Prepare(gf.CreatePolygon(shell)); IList <IGeometry> holes = new List <IGeometry>(); for (int i = 0; i < _poly.NumInteriorRings; i++) { IGeometry hole = _poly.GetInteriorRingN(i); if (shellPrep.Covers(hole)) { holes.Add(hole); } } // all holes valid, so return original if (holes.Count == _poly.NumInteriorRings) { return(_poly); } // return new polygon with covered holes only ILinearRing[] arr = GeometryFactory.ToLinearRingArray(holes); IPolygon result = gf.CreatePolygon(shell, arr); return(result); }
public override void Setup() { var sinePoly = CreateSineStar(new Coordinate(0, 0), 100000.0, nPts); _preparedGeometry = PreparedGeometryFactory.Prepare(sinePoly); WaitHandles = new WaitHandle[ThreadTestRunner.DefaultThreadCount]; }
private static IPreparedGeometry CacheFetch(Geometry g) { if (g != _cacheKey) { _cacheKey = g; _cache = new PreparedGeometryFactory().Create(g); } return(_cache); }
/// <summary> /// Determine if a Polygon (presumably from a map element) intersects with the data contained in the server. /// </summary> /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param> /// <param name="place">Polygon to check against the server's bounds</param> /// <returns>true if the 2 parameters intersect, or false if they do not.</returns> public static bool IsInBounds(IPreparedGeometry bounds, Polygon place) { if (DisableBoundsCheck || bounds.Intersects(place)) { return(true); } return(false); }
/// <summary> /// Determine if a GeoArea (presumably from a PlusCode) intersects with the data contained in the server. /// </summary> /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param> /// <param name="place">GeoArea to check against the server's bounds</param> /// <returns>true if the 2 parameters intersect, or false if they do not.</returns> public static bool IsInBounds(IPreparedGeometry bounds, GeoArea place) { if (DisableBoundsCheck || bounds.Intersects(Converters.GeoAreaToPolygon(place))) { return(true); } return(false); }
private static void CheckContainsProperly(IPreparedGeometry pg, IGeometry g2) { var pgResult = pg.ContainsProperly(g2); var expected = ContainsProperly(pg.Geometry, g2); if (pgResult != expected) throw new InvalidOperationException("PreparedGeometry.containsProperly result does not match expected"); // System.out.println("Results match!"); }
private static IPreparedGeometry cacheFetch(Geometry g) { if (g != cacheKey) { cacheKey = g; cache = (new PreparedGeometryFactory()).Create(g); } return(cache); }
/// <summary> /// Determine if a Lat/Lon coordinate pair intersects with the data contained in the server. /// </summary> /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param> /// <param name="lat">latitude in degrees</param> /// <param name="lon">longitude in degrees</param> /// <returns>true if the 2 parameters intersect, or false if they do not.</returns> public static bool IsInBounds(IPreparedGeometry bounds, double lat, double lon) { Point p = new Point(lon, lat); if (DisableBoundsCheck || bounds.Intersects(p)) { return(true); } return(false); }
private static void CheckContainsProperly(IPreparedGeometry pg, IGeometry g2) { bool pgResult = pg.ContainsProperly(g2); bool expected = ContainsProperly(pg.Geometry, g2); if (pgResult != expected) { throw new InvalidOperationException("PreparedGeometry.containsProperly result does not match expected"); } // System.out.println("Results match!"); }
private static void CheckCovers(IPreparedGeometry pg, IGeometry g2) { var pgResult = pg.Covers(g2); var expected = pg.Geometry.Covers(g2); if (pgResult != expected) { throw new InvalidOperationException("PreparedGeometry.covers result does not match expected"); } // System.out.println("Results match!"); }
public void RunPreparedPolygon() { for (int i = 0; i < NUM_ITER; i++) { prepGeom = (new PreparedGeometryFactory()).Create(sinePoly); foreach (var pt in testPoints) { prepGeom.Covers(pt); //prepGeom.contains(pt); } } }
public override void StartRun(int nPts) { TestContext.WriteLine("Running with size " + nPts); TestContext.WriteLine("Iterations per run = " + NUM_ITER); // Geometry poly = createCircle(new Coordinate(0, 0), 100, nPts); sinePoly = createSineStar(new Coordinate(0, 0), 100, nPts); // System.out.println(poly); // Geometry target = sinePoly.getBoundary(); prepGeom = (new PreparedGeometryFactory()).Create(sinePoly); testPoints = CreatePoints(sinePoly.EnvelopeInternal, NUM_PTS); }
private static void CheckIntersects(IPreparedGeometry pg, IGeometry g2) { bool pgResult = pg.Intersects(g2); bool expected = pg.Geometry.Intersects(g2); if (pgResult != expected) { // pg.intersects(g2); throw new InvalidOperationException("PreparedGeometry.intersects result does not match expected"); } // System.out.println("Results match!"); }
private static void CheckIntersects(IPreparedGeometry pg, IGeometry g2) { bool pgResult = pg.Intersects(g2); bool expected = pg.Geometry.Intersects(g2); if (pgResult != expected) { // pg.intersects(g2); throw new InvalidOperationException("PreparedGeometry.intersects result does not match expected"); } // System.out.println("Results match!"); }
private bool CheckIfMatch(IPreparedGeometry polygon, Geometry current_polygon, Mode mode) { if (mode == Mode.Intersect) { return(polygon.Intersects(current_polygon)); } if (mode == Mode.Contains) { return(polygon.Contains(current_polygon)); } throw new InvalidEnumArgumentException("unkown mode"); }
internal static IGeometry PolygonizeForClip(IGeometry geometry, IPreparedGeometry clip) { var lines = LineStringExtracter.GetLines(geometry); var clippedLines = new List<IGeometry>(); foreach (ILineString line in lines) { if (clip.Contains(line)) clippedLines.Add(line); } var polygonizer = new Polygonizer(); polygonizer.Add(clippedLines); var polys = polygonizer.GetPolygons(); var polyArray = GeometryFactory.ToGeometryArray(polys); return geometry.Factory.CreateGeometryCollection(polyArray); }
private static Boolean CheckIntersects(IGeometry target, IGeometry test) { bool expectedResult = target.Intersects(test); PreparedGeometryFactory pgFact = new PreparedGeometryFactory(); IPreparedGeometry prepGeom = pgFact.Create(target); bool prepResult = prepGeom.Intersects(test); if (prepResult != expectedResult) { return(false); } return(true); }
public void TestResultsEqual(IGeometry g, ILineString line) { bool slowIntersects = g.Intersects(line); PreparedGeometryFactory pgFact = new PreparedGeometryFactory(); IPreparedGeometry prepGeom = pgFact.Create(g); bool fastIntersects = prepGeom.Intersects(line); if (slowIntersects != fastIntersects) { Console.WriteLine(line); Console.WriteLine("Slow = " + slowIntersects + ", Fast = " + fastIntersects); throw new Exception("Different results found for intersects() !"); } }
public List <string> GetHashes(string startingHash, IPreparedGeometry polygon, int precision, Mode mode, IProgress <HashingProgress> progress = null) { var startTime = Stopwatch.StartNew(); var queuedHashes = new Queue <string>(); var processedHashes = new Dictionary <string, bool>(); //starting hash queuedHashes.Enqueue(startingHash); while (queuedHashes.Count > 0) { var current_geohash = queuedHashes.Dequeue(); progress?.Report(new HashingProgress() { QueueSize = queuedHashes.Count, HashesProcessed = processedHashes.Count, RunningSince = startTime.Elapsed }); if (!processedHashes.ContainsKey(current_geohash)) { var current_polygon = GeohashToPolygon(current_geohash); if (CheckIfMatch(polygon, current_polygon, mode)) { processedHashes.Add(current_geohash, true); foreach (var neighborHash in geohasher.GetNeighbors(current_geohash).Values) { if (!processedHashes.ContainsKey(neighborHash)) { queuedHashes.Enqueue(neighborHash); } } } else { processedHashes.Add(current_geohash, false); } } } return(processedHashes.Where(x => x.Value == true).Select(x => x.Key).ToList()); }
private void AddParishNames(List <Feature> features, string fieldname) { int featureNum = 0; int originalToSearch = 0; int lastSaved = int.MaxValue; int featuresCount = features.Count(); foreach (Feature f in features) { featureNum++; if (f.Attributes[fieldname] == null || f.Attributes[fieldname].ToString().Length == 0) { Console.WriteLine("Parish is null?? type_code:" + f.Attributes["TYPE_CODE"]); // f.Attributes["TYPE_CODE"] = "FA" } IPreparedGeometry geom = PreparedGeometryFactory.Prepare(f.Geometry); int count = 0; IEnumerable <OS50kGazetteer> toSearch = OS50k.Where(x => x.ParishName == null || x.ParishName.Length == 0); if (originalToSearch == 0) { originalToSearch = toSearch.Count(); } foreach (OS50kGazetteer os50k in toSearch) { if (geom.Intersects(os50k.BufferedPoint)) { os50k.ParishName = (string)f.Attributes[fieldname]; if (os50k.ParishName.EndsWith(" CP")) { os50k.ParishName = os50k.ParishName.Substring(0, os50k.ParishName.Length - 3); } count++; } } int left = toSearch.Count() - count; textBox1.AppendText("Set " + count + " entries for parish: " + f.Attributes[fieldname] + " number " + featureNum + " / " + featuresCount + " leaving " + left + " of " + originalToSearch + " to search\n"); if (lastSaved - 2000 > left) { lastSaved = left; SaveOS50kGazetteer(); } Application.DoEvents(); } }
internal static IGeometry PolygonizeForClip(IGeometry geometry, IPreparedGeometry clip) { var lines = LineStringExtracter.GetLines(geometry); var clippedLines = new List <IGeometry>(); foreach (ILineString line in lines) { if (clip.Contains(line)) { clippedLines.Add(line); } } var polygonizer = new Polygonizer(); polygonizer.Add(clippedLines); var polys = polygonizer.GetPolygons(); var polyArray = GeometryFactory.ToGeometryArray(polys); return(geometry.Factory.CreateGeometryCollection(polyArray)); }
/// <summary> /// Method to perform preparatory things for executing an intersection query against the data source /// </summary> /// <param name="geom">The geometry to use as filter.</param> protected override void OnBeginExecuteIntersectionQuery(IGeometry geom, CancellationToken?cancellationToken = null) { PreparedGeometry = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom); base.OnBeginExecuteIntersectionQuery(geom); }
/// <summary> /// Releases all managed resources /// </summary> protected override void ReleaseManagedResources() { PreparedGeometry = null; base.ReleaseManagedResources(); }
/// <summary> /// Determine if a Polygon (presumably from a map element) intersects with the data contained in the server. /// </summary> /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param> /// <param name="plusCode">PlusCode string to check against the server bounds.</param> /// <returns>true if the 2 parameters intersect, or false if they do not.</returns> public static bool IsInBounds(IPreparedGeometry bounds, string plusCode) { return(IsInBounds(bounds, OpenLocationCode.DecodeValid(plusCode))); }
/// <summary> /// Return Hashes for a given polygon /// </summary> /// <param name="startingHash">Starting Position, e.g use centroid.x and centroid.y</param> /// <param name="polygon">Polygon for which to create hashes</param> /// <param name="precision">Precision of the hashes, defaults to 6</param> /// <param name="mode">Fill Mode for the hashes</param> /// <param name="progress">Allows reporting progress</param> /// <returns></returns> public List <string> GetHashes(string startingHash, IPreparedGeometry polygon, int precision = 6, Mode mode = Mode.Contains, IProgress <HashingProgress> progress = null) { return(new PolygonHasher().GetHashes(startingHash, polygon, precision, mode, progress)); }
/// <summary> /// Method to do cleanup work after having performed the intersection query against the data source /// </summary> protected override void OnEndExecuteIntersectionQuery() { PreparedGeometry = null; base.OnEndExecuteIntersectionQuery(); }
/// <summary> /// Method to perform preparatory things for executing an intersection query against the data source /// </summary> /// <param name="geom">The geometry to use as filter.</param> protected override void OnBeginExecuteIntersectionQuery(IGeometry geom, CancellationToken? cancellationToken = null) { PreparedGeometry = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom); base.OnBeginExecuteIntersectionQuery(geom); }
/// <summary> /// Releases all managed resources /// </summary> protected override void ReleaseManagedResources() { PreparedGeometry = null; base.ReleaseManagedResources(); }
/// <summary> /// Method to perform preparatory things for executing an intersection query against the data source /// </summary> /// <param name="geom">The geometry to use as filter.</param> protected override void OnBeginExecuteIntersectionQuery(Geometry geom) { PreparedGeometry = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom); base.OnBeginExecuteIntersectionQuery(geom); }
/// <summary> /// Method to do cleanup work after having performed the intersection query against the data source /// </summary> protected override void OnEndExecuteIntersectionQuery() { PreparedGeometry = null; base.OnEndExecuteIntersectionQuery(); }
public static List <IFeature> GetFeatureCollectionFromGeoJsonByteArray(byte[] fileContentsByteArray, int coordinatePrecision, IPreparedGeometry boundingBox) { var featureCollection = GetFeatureCollectionFromGeoJsonByteArray(fileContentsByteArray, coordinatePrecision); return(featureCollection.Where(x => boundingBox.Intersects(x.Geometry)).ToList()); }