private static void filterSelected(ILayer layer, IMapView2D view, IExtents worldBounds) { if (layer == null) { return; } FeatureLayer filterLayer = layer as FeatureLayer; if (filterLayer != null) { if (layer.Enabled && filterLayer.AreFeaturesSelectable && layer.IsVisibleWhen(isInView(view.WorldWidth))) { SpatialBinaryExpression spatialExpression = SpatialBinaryExpression.Intersects(new FeaturesCollectionExpression(filterLayer.Features), new ExtentsExpression(worldBounds)); filterLayer.SelectedFilter = filterLayer.SelectedFilter == null ? new FeatureQueryExpression(new AllAttributesExpression(), spatialExpression, null) : new FeatureQueryExpression(filterLayer.SelectedFilter, spatialExpression); } } IEnumerable <ILayer> layers = layer as IEnumerable <ILayer>; if (layers != null) { foreach (ILayer child in layers) { filterSelected(child, view, worldBounds); } } }
public void ChangeViewSpatialFilterTriggersNotification() { FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory); FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(data.GetExtents()); IFeatureDataReader reader = data.ExecuteFeatureQuery(query); table.Load(reader, LoadOption.OverwriteChanges, null); FeatureDataView view = new FeatureDataView(table); Boolean resetNotificationOccured = false; view.ListChanged += delegate(Object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.Reset) { resetNotificationOccured = true; } }; Assert.False(resetNotificationOccured); IExtents queryExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10); SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(queryExtents); view.SpatialFilter = expression; Assert.True(resetNotificationOccured); }
private Boolean inGeometryFilter(FeatureDataRow feature) { if (_viewDefinition == null || _viewDefinition.SpatialPredicate == null) { return(true); } SpatialBinaryExpression spatialQueryExpression = _viewDefinition.SpatialPredicate; SpatialOperation op = spatialQueryExpression.Op; GeometryExpression geometryExpression = spatialQueryExpression.SpatialExpression as GeometryExpression; ExtentsExpression extentsExpression = spatialQueryExpression.SpatialExpression as ExtentsExpression; if (!SpatialExpression.IsNullOrEmpty(geometryExpression)) { return(SpatialBinaryExpression.IsMatch(op, spatialQueryExpression.IsSpatialExpressionLeft, geometryExpression.Geometry, feature.Geometry)); } if (!SpatialExpression.IsNullOrEmpty(extentsExpression)) { return(SpatialBinaryExpression.IsMatch(op, spatialQueryExpression.IsSpatialExpressionLeft, extentsExpression.Extents, feature.Extents)); } return(true); }
public void ChangeViewSpatialFilterReturnsOnlyFilteredRows() { FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory); FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(data.GetExtents()); IFeatureDataReader reader = data.ExecuteFeatureQuery(query); table.Load(reader); IGeometry queryExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10).ToGeometry(); List <FeatureDataRow> expectedRows = new List <FeatureDataRow>(); foreach (FeatureDataRow row in table) { IGeometry g = row.Geometry; if (queryExtents.Intersects(g)) { expectedRows.Add(row); } } FeatureDataView view = new FeatureDataView(table); SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(queryExtents); view.SpatialFilter = expression; Assert.Equal(expectedRows.Count, view.Count); }
private void queueableBeginQuery(Object asyncResult) { AsyncResult <IFeatureDataReader> typedAsyncResult = asyncResult as AsyncResult <IFeatureDataReader>; Assert.IsNotNull(typedAsyncResult); FeatureQueryExpression query = typedAsyncResult.AsyncState as FeatureQueryExpression; if (query == null) { SpatialBinaryExpression spatialBinaryExpression = typedAsyncResult.AsyncState as SpatialBinaryExpression; if (spatialBinaryExpression != null) { query = new FeatureQueryExpression(new AllAttributesExpression(), spatialBinaryExpression, query.Sort); } } try { typedAsyncResult.SetComplete(InnerFeatureProvider.ExecuteFeatureQuery(query), false); } catch (Exception terminatingException) { typedAsyncResult.SetComplete(false, terminatingException); } }
public IEnumerable <TOid> ExecuteOidQuery(SpatialBinaryExpression query) { foreach (IFeatureDataRecord fdr in ExecuteFeatureDataReader( PrepareSelectCommand( new FeatureQueryExpression(new AttributesProjectionExpression(new[] { OidColumn }), (AttributeBinaryExpression)null, query)))) { yield return((TOid)fdr.GetOid()); } }
public void LoadIntersectingLayerData(IGeometry region) { if (region == null) { throw new ArgumentNullException("region"); } SpatialBinaryExpression exp = new SpatialBinaryExpression(new GeometryExpression(region), SpatialOperation.Intersects, new LayerExpression(this)); QueryExpression query = GetQueryFromSpatialBinaryExpression(exp); LoadLayerData(query); }
public void SettingGeometryFilterToIdenticalGeometryDoesntChangeFilterObject() { FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory); FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(data.GetExtents()); IFeatureDataReader reader = data.ExecuteFeatureQuery(query); table.Load(reader, LoadOption.OverwriteChanges, null); IGeometry filter = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10).ToGeometry(); FeatureDataView view = new FeatureDataView(table, filter, "", DataViewRowState.CurrentRows); IGeometry filterCopy = filter.Clone(); Assert.NotSame(filter, filterCopy); Assert.Equal(filter, filterCopy); SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(filterCopy); view.SpatialFilter = expression; Assert.NotSame(expression, view.SpatialFilter); }
protected virtual void VisitSpatialBinaryExpression(StringBuilder builder, SpatialBinaryExpression exp) { if (exp == null) { return; } if (exp.SpatialExpression is ExtentsExpression) { WriteSpatialExtentsExpressionSql(builder, exp.Op, (exp.SpatialExpression).Extents); } else if (exp.SpatialExpression is GeometryExpression) { WriteSpatialGeometryExpressionSql(builder, exp.Op, ((GeometryExpression)exp.SpatialExpression).Geometry); } else { throw new NotImplementedException(string.Format("{0} is not implemented", exp.GetType())); } }
private FeatureQueryExpression transformQuery(FeatureQueryExpression query) { SpatialBinaryExpression spatial = query.SpatialPredicate; ICoordinateSystem querySpatialReference = spatial.SpatialExpression.SpatialReference; if (querySpatialReference.EqualParams(OriginalSpatialReference)) { return(query); } //if (querySpatialReference != OriginalSpatialReference) //{ // throw new InvalidOperationException("The query's spatial reference doesn't match the provider's."); //} GeometryExpression geoExpression = spatial.SpatialExpression as GeometryExpression; if (geoExpression != null) { IGeometry transformed = CoordinateTransformation.InverseTransform(geoExpression.Geometry, GeometryFactory); geoExpression = new GeometryExpression(transformed); spatial = spatial.IsSpatialExpressionLeft ? new SpatialBinaryExpression(geoExpression, spatial.Op, spatial.Expression) : new SpatialBinaryExpression(spatial.Expression, spatial.Op, geoExpression); } else { IExtents transformed = CoordinateTransformation.InverseTransform(spatial.SpatialExpression.Extents, GeometryFactory); ExtentsExpression extentsExpression = new ExtentsExpression(transformed); spatial = spatial.IsSpatialExpressionLeft ? new SpatialBinaryExpression(extentsExpression, spatial.Op, spatial.Expression) : new SpatialBinaryExpression(spatial.Expression, spatial.Op, extentsExpression); } query = new FeatureQueryExpression(query, spatial); return(query); }
public void SettingViewFilterToIncludeRowsNotPresentInTableCausesFeaturesRequestNotification() { FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory); FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory); Boolean featuresRequested = false; //table.FeaturesNotFound += delegate { featuresRequested = true; }; FeatureDataView view = new FeatureDataView(table); IExtents otherHalfBounds = data.GetExtents(); otherHalfBounds.TranslateRelativeToWidth(0.5, 0.5); otherHalfBounds.Scale(0.5); Assert.False(featuresRequested); SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(otherHalfBounds); view.SpatialFilter = expression; Assert.True(featuresRequested); }
public void SettingSpatialPredicateOfFilterChangesViewToMatchFilter() { FeatureDataTable <Guid> table; FeatureDataView view; createDataViewOnNewTable(out view, out table, false); Assert.Equal(table.Rows.Count, view.Count); view.SpatialFilter = SpatialBinaryExpression.Intersects(table.Extents); Assert.Equal(table.Rows.Count, view.Count); view.SpatialFilter = new SpatialBinaryExpression(new ThisExpression(), SpatialOperation.Disjoint, new ExtentsExpression(table.Extents)); Assert.Equal(0, view.Count); view.SpatialFilter = SpatialBinaryExpression.Intersects(_factories.GeoFactory.CreatePoint2D(0, 0)); Assert.Equal(1, view.Count); }
public IEnumerable <UInt32> ExecuteOidQuery(SpatialBinaryExpression query) { if (query == null) { throw new ArgumentNullException("query"); } SpatialExpression spatialExpression = query.SpatialExpression; if (SpatialExpression.IsNullOrEmpty(spatialExpression)) { yield break; } if (query.Expression == null) { throw new ArgumentException("The SpatialQueryExpression must have " + "a non-null Expression."); } ExtentsExpression extentsExpression = spatialExpression as ExtentsExpression; GeometryExpression geometryExpression = spatialExpression as GeometryExpression; IExtents filterExtents = extentsExpression != null ? extentsExpression.Extents : null; IGeometry filterGeometry = geometryExpression != null ? geometryExpression.Geometry : null; Assert.IsTrue(filterExtents != null || filterGeometry != null); Boolean isLeft = query.IsSpatialExpressionLeft; SpatialOperation op = query.Op; LayerExpression layerExpression = query.Expression as LayerExpression; if (layerExpression != null) { for (UInt32 i = 0; i < _geometries.Count; i++) { if (isGeometryAtIndexAMatch((Int32)i, op, isLeft, filterGeometry)) { yield return(i); } } yield break; } OidCollectionExpression oidsCollection = query.Expression as OidCollectionExpression; if (oidsCollection != null) { if (oidsCollection.Right == null) { throw new ArgumentException("The OidCollectionExpression in the query " + "has a null collection"); } IEnumerable oids = oidsCollection.Right.Collection; if (oids == null) { yield break; } foreach (Object oid in oids) { if (isGeometryAtIndexAMatch((Int32)oid, op, isLeft, filterGeometry)) { yield return((UInt32)oid); } } yield break; } }
protected override QueryExpression GetQueryFromSpatialBinaryExpression(SpatialBinaryExpression exp) { return new RasterQueryExpression(exp); }
protected override QueryExpression GetQueryFromSpatialBinaryExpression(SpatialBinaryExpression exp) { return(new RasterQueryExpression(exp)); }
protected abstract QueryExpression GetQueryFromSpatialBinaryExpression(SpatialBinaryExpression exp);
public IEnumerable <Guid> ExecuteOidQuery(SpatialBinaryExpression query) { throw new NotImplementedException(); }
public void VariousFilteringCombinationTestSequence() { // this horrendous sequence is what I had time alloted for // takes some better setup to factor into tests that test 1 thing FeatureDataTable <Guid> table; FeatureDataView view; createDataViewOnNewTable(out view, out table, false); Assert.Equal(table.Rows.Count, view.Count); SpatialBinaryExpression spatialFilter = SpatialBinaryExpression.Intersects(_factories.GeoFactory.WktReader.Read("POLYGON ((19 19, 21 19, 20 21, 19 19))")); // test basic spatial filter view.SpatialFilter = spatialFilter; Assert.Equal(3, view.Count); // setup for combination tests List <Guid> oidsInSpatialFilter = new List <Guid>(3); foreach (FeatureDataRow row in (IEnumerable <FeatureDataRow>)view) { oidsInSpatialFilter.Add((Guid)row.GetOid()); } List <Guid> oidsNotInSpatialFilter = new List <Guid>(table.Rows.Count - 3); foreach (FeatureDataRow <Guid> row in table) { if (!oidsNotInSpatialFilter.Contains(row.Id)) { oidsNotInSpatialFilter.Add(row.Id); } } List <Guid> twoOidsFromEachList = new List <Guid>(4); twoOidsFromEachList.AddRange(oidFilterSource(oidsInSpatialFilter, 2)); twoOidsFromEachList.AddRange(oidFilterSource(oidsNotInSpatialFilter, 2)); // test spatial filter and oid filter OidCollectionExpression spanningOids = new OidCollectionExpression(twoOidsFromEachList); view.OidFilter = spanningOids; Assert.Equal(2, view.Count); // test clearing spatial component view.SpatialFilter = null; Assert.Equal(4, view.Count); // test inverting oid filter view.IsViewDefinitionExclusive = true; Assert.Equal(table.Rows.Count - 4, view.Count); // test both components with inversion view.SpatialFilter = spatialFilter; Assert.Equal(table.Rows.Count - 2, view.Count); // test clearing OidFilter view.OidFilter = null; Assert.Equal(table.Rows.Count - 3, view.Count); // test clearing inversion view.IsViewDefinitionExclusive = false; Assert.Equal(3, view.Count); // test clearing everything view.SpatialFilter = null; Assert.Equal(table.Rows.Count, view.Count); }
private Boolean isGeometryAtIndexAMatch(Int32 index, SpatialOperation op, Boolean isLeft, IGeometry filterGeometry) { IGeometry current = _geometries[index]; return(SpatialBinaryExpression.IsMatch(op, isLeft, filterGeometry, current)); }
protected override QueryExpression GetQueryFromSpatialBinaryExpression(SpatialBinaryExpression exp) { throw new NotSupportedException("Query type should determined by individual layers in group."); }