public void GetExtentsTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); IExtents expected = _geoFactory.CreateExtents2D( 7332083.2127965018, 236823.71867240831, 7538428.618, 405610.34692560317); IExtents actual = shapeFile.GetExtents(); Assert.AreEqual(expected, actual); }
public IEnumerable <IGeometry <BufferedCoordinate> > CreateTestGeometries(int count, double minx, double miny, double maxx, double maxy) { double xrange = Math.Abs(maxx - minx); double yrange = Math.Abs(maxy - miny); for (int i = 0; i < count; i++) { double x1 = _rnd.NextDouble() * xrange + minx; double x2 = _rnd.NextDouble() * xrange + minx; double y1 = _rnd.NextDouble() * yrange + miny; double y2 = _rnd.NextDouble() * yrange + miny; yield return((IGeometry <BufferedCoordinate>)_geometryFactory.CreateExtents2D(Math.Min(x1, x2), Math.Min(y1, y2), Math.Max(x1, x2), Math.Max(y1, y2)).ToGeometry()); } }
public static IExtents2D ParseExtents(IGeometryFactory geomFactory, string extents) { string[] strVals = extents.Split(new[] {','}); if (strVals.Length != 4) return null; double minx = 0; double miny = 0; double maxx = 0; double maxy = 0; if (!double.TryParse(strVals[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out minx)) return null; if (!double.TryParse(strVals[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxx)) return null; if (maxx < minx) return null; if (!double.TryParse(strVals[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out miny)) return null; if (!double.TryParse(strVals[3], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxy)) return null; if (maxy < miny) return null; return geomFactory.CreateExtents2D(minx, miny, maxx, maxy); }
public void LayerCachingTest() { IGeometryFactory geoFactory = _factories.GeoFactory; GeometryLayer layer1 = DataSourceHelper.CreateFeatureFeatureLayer(geoFactory); GeometryLayer layer2 = DataSourceHelper.CreateFeatureFeatureLayer(geoFactory); IExtents box1 = geoFactory.CreateExtents2D(0, 0, 10, 10); IExtents box2 = geoFactory.CreateExtents2D(35, 25, 45, 35); layer1.AsyncQuery = false; // Do query layer2.AsyncQuery = false; // Do query Assert.True(layer1.Features.Extents.Contains(box2), "Test validity check"); // features intersecting box1 must have extents that contain box2 // Do query }
public void T03_SomeSelects() { PostGisProvider <Int64> prov = new PostGisProvider <Int64>( _geometryFactory, connectionString, "TestFeatureDataTable"); GeometryLayer gl = new GeometryLayer("test", prov); gl.Select(new AllAttributesExpression()); gl.Features.AcceptChanges(); Assert.AreEqual(4, gl.Features.FeatureCount); Assert.AreEqual(_geometryFactory.CreateExtents2D(0, -3, 15, 20), gl.Features.Extents); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1, -1, 1, 1)), SpatialOperation.Contains, new ThisExpression()) ); Assert.AreEqual(1, gl.Features.Rows.Count); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 -1, -1 -1))"))), SpatialOperation.Contains, new ThisExpression()) ); //SELECT testfeaturedatatable.poid,testfeaturedatatable.label,ST_AsBinary(xgeometryx)::bytea AS xgeometryx FROM public.testfeaturedatatable WHERE ( ST_Contains( ST_GeomFromWKB(:iparam0, -1), xgeometryx )) //SELECT testfeaturedatatable.poid,testfeaturedatatable.label,ST_AsBinary(xgeometryx)::bytea AS xgeometryx FROM public.testfeaturedatatable WHERE ( ST_Contains( ST_GeomFromText('POLYGON((-1 -1, 0 1, 1 -1, -1 -1))', -1), xgeometryx )) Assert.AreEqual(1, gl.Features.Rows.Count); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new GeometryExpression( prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))), SpatialOperation.Touches, new ThisExpression()) ); Assert.AreEqual(1, gl.Features.Rows.Count); //gl = new GeometryLayer(prov); //gl.Select( // new SpatialBinaryExpression( // new ThisExpression(), // SpatialOperation.Within, // new GeometryExpression(prov.GeometryFactory.WktReader.Read("POLYGON((-1 -1, 0 1, 1 -1, -1 -1))"))) // ); //Assert.AreEqual(0, gl.Features.Rows.TotalItemCount); }
public void T03_MultipleSelects() { SpatiaLite2Provider prov = new SpatiaLite2Provider( _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable"); GeometryLayer gl = new GeometryLayer("test", prov); gl.Select(new AllAttributesExpression()); gl.Features.AcceptChanges(); Assert.AreEqual(4, gl.Features.FeatureCount); Assert.AreEqual(_geometryFactory.CreateExtents2D(0, -3, 15, 20), gl.Features.Extents); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1, -1, 1, 1)), SpatialOperation.Contains, new ThisExpression()) ); Assert.AreEqual(1, gl.Features.Rows.Count); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))), SpatialOperation.Contains, new ThisExpression()) ); Assert.AreEqual(1, gl.Features.Rows.Count); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))), SpatialOperation.Touches, new ThisExpression()) ); Assert.AreEqual(1, gl.Features.Rows.Count, 1); gl = new GeometryLayer(prov); gl.Select( new SpatialBinaryExpression( new ThisExpression(), SpatialOperation.Within, new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))")))) ); Assert.AreEqual(0, gl.Features.Rows.Count); }
public static IExtents2D ParseExtents(IGeometryFactory geomFactory, string extents) { string[] strVals = extents.Split(new[] { ',' }); if (strVals.Length != 4) { return(null); } double minx = 0; double miny = 0; double maxx = 0; double maxy = 0; if (!double.TryParse(strVals[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out minx)) { return(null); } if (!double.TryParse(strVals[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxx)) { return(null); } if (maxx < minx) { return(null); } if (!double.TryParse(strVals[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out miny)) { return(null); } if (!double.TryParse(strVals[3], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxy)) { return(null); } if (maxy < miny) { return(null); } return(geomFactory.CreateExtents2D(minx, miny, maxx, maxy)); }
public void MultiLinestring() { IMultiLineString mls = _geoFactory.CreateMultiLineString(); Assert.IsTrue(mls.IsEmpty); mls.Add(_geoFactory.CreateLineString()); Assert.IsTrue(mls.IsEmpty); mls[0].Coordinates.Add(_geoFactory.CreatePoint2D(45, 68)); mls[0].Coordinates.Add(_geoFactory.CreatePoint2D(82, 44)); mls.Add(createLineString()); foreach (ILineString ls in (IEnumerable <ILineString>)mls) { Assert.IsFalse(ls.IsEmpty); } Assert.IsFalse(mls.IsEmpty); foreach (ILineString ls in (IEnumerable <ILineString>)mls) { Assert.IsFalse(ls.IsClosed); } Assert.IsFalse(mls.IsClosed); //Close linestrings foreach (ILineString ls in (IEnumerable <ILineString>)mls) { ls.Coordinates.Add((ls.StartPoint.Clone() as IPoint).Coordinate); } foreach (ILineString ls in (IEnumerable <ILineString>)mls) { Assert.IsTrue(ls.IsClosed); } Assert.IsTrue(mls.IsClosed); Assert.AreEqual(_geoFactory.CreateExtents2D(1, 2, 930, 123), mls.Extents); }