public void TestA() { Coordinate p1 = new Coordinate(-123456789, -40); Coordinate p2 = new Coordinate(381039468754763d, 123456789); Coordinate q = new Coordinate(0, 0); ILineString l = new GeometryFactory().CreateLineString(new Coordinate[] {p1, p2}); IPoint p = new GeometryFactory().CreatePoint(q); Assert.AreEqual(false, l.Intersects(p)); Assert.AreEqual(false, CGAlgorithms.IsOnLine(q, new Coordinate[] { p1, p2 })); Assert.AreEqual(-1, CGAlgorithms.ComputeOrientation(p1, p2, q)); }
/// <summary> /// Query shapefile by MBR. /// MBR coordinates MUST be in the Shapefile's coordinate system. /// /// NOTE: If you are using the default ISpatialIndex (which is an instance of the STRtree NTS class), it has some limitations. /// Since it works with MBRs rather than the shapes themselves, you can get some shapes that are not actually in the MBR /// you provided just because their MBRs are bounded by the given envelope. /// If you wish to avoid this behaviour, send true in the second paramter, but be weary of the consequences listed below. /// </summary> /// <param name="envelope"> The envlope to query. </param> /// <param name="testGeometriesActuallyInMBR"> /// False by default, true to double-check the returned geometries against given Envelope, to avoid index error margin. /// /// It is advisable that you implement your own ISpatialIndex with your required precision rather than set this to True. /// /// ********** /// CAUTION: If you choose to set this parameter as True, it will greatly affect performance as it /// will cancel any lazy mechanism implemented with reading the geometries from the file. /// Do not set this to True unless you either: /// A. Do not have any performance restrictions. /// Or: /// B. Absolutely need that precision in the geographic query. /// ********** /// </param> /// <returns></returns> public IEnumerable<IShapefileFeature> ReadByMBRFilter(Envelope envelope, bool testGeometriesActuallyInMBR = false) { if (envelope == null) { throw new ArgumentNullException("envelope"); } // If index creation task wasnt completed, wait for it to complete. if (!m_IsIndexingComplete) { m_IndexCreationTask.Wait(); } IList<ShapeLocationInFileInfo> shapesInRegion = m_SpatialIndex.Query(envelope); if (shapesInRegion.Count == 0) { return Enumerable.Empty<IShapefileFeature>(); } IEnumerable<IShapefileFeature> results = shapesInRegion.Select(ReadFeature); if (!testGeometriesActuallyInMBR) { return results; } else { IGeometry envelopeGeo = new GeometryFactory().ToGeometry(envelope); return results.Where(feature => { return envelopeGeo.Intersects(feature.Geometry); }); } }
public void testPredicatesReturnFalseForEmptyGeometries() { var p1 = new GeometryFactory().CreatePoint((Coordinate) null); var p2 = new GeometryFactory().CreatePoint(new Coordinate(5, 5)); Assert.AreEqual(false, p1.Equals(p2)); Assert.AreEqual(true, p1.Disjoint(p2)); Assert.AreEqual(false, p1.Intersects(p2)); Assert.AreEqual(false, p1.Touches(p2)); Assert.AreEqual(false, p1.Crosses(p2)); Assert.AreEqual(false, p1.Within(p2)); Assert.AreEqual(false, p1.Contains(p2)); Assert.AreEqual(false, p1.Overlaps(p2)); Assert.AreEqual(false, p2.Equals(p1)); Assert.AreEqual(true, p2.Disjoint(p1)); Assert.AreEqual(false, p2.Intersects(p1)); Assert.AreEqual(false, p2.Touches(p1)); Assert.AreEqual(false, p2.Crosses(p1)); Assert.AreEqual(false, p2.Within(p1)); Assert.AreEqual(false, p2.Contains(p1)); Assert.AreEqual(false, p2.Overlaps(p1)); }