protected override void WriteSpatialExtentsExpressionSqlInternal(StringBuilder builder, SpatialOperation spatialOperation, IExtents ext) { /// seems faster to test the actual geometry and take advantage of spatial indexing /// than to test the envelope without spatial indexing. WriteSpatialGeometryExpressionSqlInternal(builder, spatialOperation, ext.ToGeometry()); }
public override Filter MakeFilter(SpatialArgs args) { SpatialOperation op = args.Operation; if (op == SpatialOperation.IsDisjointTo) { return(new DisjointSpatialFilter(this, args, FieldName)); } Shape shape = args.Shape; int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct)); bool hasIndexedLeaves = true; if (op == SpatialOperation.Intersects) { return(new IntersectsPrefixTreeFilter(shape, FieldName, grid, detailLevel, prefixGridScanLevel , hasIndexedLeaves)); } else { if (op == SpatialOperation.IsWithin) { return(new WithinPrefixTreeFilter(shape, FieldName, grid, detailLevel, prefixGridScanLevel , -1)); } else { //-1 flag is slower but ensures correct results if (op == SpatialOperation.Contains) { return(new ContainsPrefixTreeFilter(shape, FieldName, grid, detailLevel)); } } } throw new UnsupportedSpatialOperation(op); }
protected override void WriteSpatialExtentsExpressionSqlInternal(StringBuilder builder, SpatialOperation spatialOperation, IExtents ext) { IExtents2D exts = (IExtents2D)ext; switch (spatialOperation) { case SpatialOperation.Intersects: { builder.AppendFormat( " {0}.{1}_Envelope_MinX < {2} AND {0}.{1}_Envelope_MinY < {3} AND {0}.{1}_Envelope_MaxX > {4} AND {0}.{1}_Envelope_MaxY > {5}", Provider.Table, Provider.GeometryColumn, CreateParameter(exts.XMax).ParameterName, CreateParameter(exts.YMax).ParameterName, CreateParameter(exts.XMin).ParameterName, CreateParameter(exts.YMin).ParameterName ); break; } default: throw new NotImplementedException(); } }
public SpatialArgs(SpatialOperation operation, Shape shape) { if (operation == null || shape == null) throw new ArgumentException("operation and shape are required"); this.Operation = operation; this.Shape = shape; }
public override Filter MakeFilter(SpatialArgs args) { // LUCENENET specific - added guard clause if (args is null) { throw new ArgumentNullException(nameof(args)); } SpatialOperation op = args.Operation; if (op != SpatialOperation.Intersects) { throw new UnsupportedSpatialOperationException(op); } IShape shape = args.Shape; int detailLevel = m_grid.GetLevelForDistance(args.ResolveDistErr(m_ctx, m_distErrPct)); IList <Cell> cells = m_grid.GetCells(shape, detailLevel, false /*no parents*/, true /*simplify*/); var terms = new BytesRef[cells.Count]; int i = 0; foreach (Cell cell in cells) { terms[i++] = new BytesRef(cell.TokenString);//TODO use cell.getTokenBytes() } return(new TermsFilter(FieldName, terms)); }
private readonly IShape queryShape; //the right hand side (constant) /// <summary> /// /// </summary> /// <param name="shapeValueSource"> /// Must yield <see cref="IShape"/> instances from it's ObjectVal(doc). If null /// then the result is false. This is the left-hand (indexed) side. /// </param> /// <param name="op">the predicate</param> /// <param name="queryShape">The shape on the right-hand (query) side.</param> public ShapePredicateValueSource(ValueSource shapeValueSource, SpatialOperation op, IShape queryShape) { // LUCENENET specific - added guard clauses this.shapeValueSource = shapeValueSource ?? throw new ArgumentNullException(nameof(shapeValueSource)); this.op = op ?? throw new ArgumentNullException(nameof(op)); this.queryShape = queryShape ?? throw new ArgumentNullException(nameof(queryShape)); }
public RasterQueryExpression(IGeometry geometry, SpatialOperation op) : base(new AllBandsExpression(), new SpatialBinaryExpression(new GeometryExpression(geometry), op, new ThisExpression())) { checkOp(op); }
public RasterQueryExpression(IGeometry geometry, SpatialOperation op, IRasterProvider provider) : base(new AllBandsExpression(), new SpatialBinaryExpression(new GeometryExpression(geometry), op, new ProviderExpression(provider))) { checkOp(op); }
/// <summary> /// Creates a WFS XML filter string. /// </summary> /// <param name="filter">The filter string.</param> /// <param name="geometryName">Name of the geometry object.</param> /// <param name="boundingBox">The bounding box.</param> /// <returns>A string containing WFS XML-text.</returns> private static string CreateWfsXmlFilterString(string filter, string geometryName, WfsBoundingBox boundingBox) { FormulaOperation formulaOperation; SpatialOperation bboxOperation = null; if (string.IsNullOrEmpty(geometryName)) { geometryName = "the_geom"; } if (boundingBox != null) { SpatialBoundingBox spatialBoundingBox = new SpatialBoundingBox(boundingBox.MinX, boundingBox.MinY, boundingBox.MaxX, boundingBox.MaxY, boundingBox.SrsName); bboxOperation = new SpatialOperation(new SpatialFieldValue(geometryName), spatialBoundingBox, WFSSpatialOperator.InsideBbox); } if (string.IsNullOrEmpty(filter)) { formulaOperation = bboxOperation ?? null; } else { WfsFormulaParser parser = new WfsFormulaParser(); formulaOperation = parser.Parse(filter); if (bboxOperation != null) { formulaOperation = new BinaryLogicalOperation(formulaOperation, bboxOperation, WFSBinaryLogicalOperator.And); } } WFSFilter wfsFilter = new WFSFilter { Formula = formulaOperation }; string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation(); return(strWfsXmlRepresentation); }
public RasterQueryExpression(IExtents extents, SpatialOperation op) : base(new AllBandsExpression(), new SpatialBinaryExpression(new ExtentsExpression(extents), op, new ThisExpression())) { checkOp(op); }
public override ConstantScoreQuery MakeQuery(SpatialArgs args) { if (!SpatialOperation.Is(args.Operation, SpatialOperation.Intersects, SpatialOperation.IsWithin)) { throw new UnsupportedSpatialOperation(args.Operation); } Shape shape = args.Shape; var bbox = shape as Rectangle; if (bbox != null) { return(new ConstantScoreQuery(new QueryWrapperFilter(MakeWithin(bbox)))); } var circle = shape as Circle; if (circle != null) { bbox = circle.GetBoundingBox(); var vsf = new ValueSourceFilter( new QueryWrapperFilter(MakeWithin(bbox)), MakeDistanceValueSource(circle.GetCenter()), 0, circle.GetRadius()); return(new ConstantScoreQuery(vsf)); } throw new InvalidOperationException("Only Rectangles and Circles are currently supported, " + "found [" + shape.GetType().Name + "]"); //TODO }
public override ConstantScoreQuery MakeQuery(SpatialArgs args) { if (!SpatialOperation.Is(args.Operation, SpatialOperation.Intersects, SpatialOperation.IsWithin)) { throw new UnsupportedSpatialOperation(args.Operation); } IShape shape = args.Shape; if (shape is IRectangle) { var bbox = (IRectangle)shape; return(new ConstantScoreQuery(MakeWithin(bbox))); } else if (shape is ICircle) { var circle = (ICircle)shape; var bbox = circle.BoundingBox; var vsf = new ValueSourceFilter( new QueryWrapperFilter(MakeWithin(bbox)), MakeDistanceValueSource(circle.Center), 0, circle.Radius); return(new ConstantScoreQuery(vsf)); } throw new NotSupportedException("Only IRectangles and ICircles are currently supported, " + "found [" + shape.GetType().Name + "]"); //TODO }
protected override void WriteSpatialExtentsExpressionSqlInternal(StringBuilder builder, SpatialOperation spatialOperation, IExtents ext) { //IExtents2D exts = (IExtents2D)ext; //ST_SetSRID('BOX3D(0 0,1 1)'::box3d,4326) String whereClause = ""; IExtents2D exts = (Provider.SpatialReference == null || Provider.SpatialReference.EqualParams(Provider.OriginalSpatialReference)) ? (IExtents2D)ext : (IExtents2D)Provider.CoordinateTransformation.Inverse.Transform(ext, Provider.GeometryFactory); whereClause = string.Format( " {0}.ENVELOPESINTERSECT({1}, CAST({2} AS DOUBLE), CAST({3} AS DOUBLE), CAST({4} AS DOUBLE), CAST({5} AS DOUBLE), {6}) = 1", DB2SpatialExtenderProviderStatic.DefaultSpatialSchema, Provider.QualifyColumnName(Provider.GeometryColumn), exts.XMin.ToString("g", CultureInfo.InvariantCulture), //CreateParameter(exts.XMin).ParameterName, exts.YMin.ToString("g", CultureInfo.InvariantCulture), //CreateParameter(exts.YMin).ParameterName, exts.XMax.ToString("g", CultureInfo.InvariantCulture), //CreateParameter(exts.XMax).ParameterName, exts.YMax.ToString("g", CultureInfo.InvariantCulture), //CreateParameter(exts.YMax).ParameterName, ((DB2SpatialExtenderProvider <TOid>)Provider).DB2SrsId); builder.Append(whereClause); }
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 override Filter MakeFilter(SpatialArgs args) { SpatialOperation op = args.Operation; if (op == SpatialOperation.IsDisjointTo) { return(new DisjointSpatialFilter(this, args, FieldName)); } IShape shape = args.Shape; int detailLevel = m_grid.GetLevelForDistance(args.ResolveDistErr(m_ctx, m_distErrPct)); if (m_pointsOnly || op == SpatialOperation.Intersects) { return(new IntersectsPrefixTreeFilter( shape, FieldName, m_grid, detailLevel, prefixGridScanLevel, !m_pointsOnly)); } else if (op == SpatialOperation.IsWithin) { return(new WithinPrefixTreeFilter( shape, FieldName, m_grid, detailLevel, prefixGridScanLevel, -1)); //-1 flag is slower but ensures correct results } else if (op == SpatialOperation.Contains) { return(new ContainsPrefixTreeFilter(shape, FieldName, m_grid, detailLevel, m_multiOverlappingIndexedShapes)); } throw new UnsupportedSpatialOperation(op); }
/// <summary> /// Creates a new <see cref="FeatureDataView"/> on the given /// <see cref="FeatureDataTable"/> having the specified geometry filter, /// sort order and row state filter. /// </summary> /// <param name="table">Table to create view on.</param> /// <param name="query"> /// Geometry used in building view to filter feature table rows. /// </param> /// <param name="op"> /// Type of spatial relation which <paramref name="query"/> has to features. /// </param> /// <param name="sort">Sort expression to order view by.</param> /// <param name="rowState">Filter on the state of the rows to view.</param> public FeatureDataView(FeatureDataTable table, IGeometry query, SpatialOperation op, String sort, DataViewRowState rowState) : this(table, new FeatureQueryExpression(query, op, table), sort, rowState) { }
public FeatureQueryExpression(IGeometry geometry, SpatialOperation op, IEnumerable <IFeatureDataRecord> features) : base(new AllAttributesExpression(), new SpatialBinaryExpression(new GeometryExpression(geometry), op, new FeaturesCollectionExpression(features))) { }
public FeatureQueryExpression(IExtents extents, SpatialOperation op, IEnumerable <IFeatureDataRecord> features) : base(new AllAttributesExpression(), new SpatialBinaryExpression(new ExtentsExpression(extents), op, new FeaturesCollectionExpression(features))) { }
protected override void WriteSpatialGeometryExpressionSqlInternal(StringBuilder builder, SpatialOperation op, IGeometry geom) { builder.AppendFormat(" {0}.{1}.{2}({3}) = 1 ", Provider.Table, Provider.GeometryColumn, GetSpatialMethodName(op), DeclareSqlGeometry(geom)); }
/// <param name="strategy">Needed to compute intersects</param> /// <param name="args">Used in spatial intersection</param> /// <param name="field"> /// This field is used to determine which docs have spatial data via /// <see cref="IFieldCache.GetDocsWithField(AtomicReader, string)"/>. /// Passing null will assume all docs have spatial data. /// </param> public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string field) { this.field = field; // TODO consider making SpatialArgs cloneable SpatialOperation origOp = args.Operation; //copy so we can restore args.Operation = SpatialOperation.Intersects; //temporarily set to intersects intersectsFilter = strategy.MakeFilter(args); args.Operation = origOp; }
public override void SetConfig(Config config) { m_strategy = SpatialDocMaker.GetSpatialStrategy(config.RoundNumber); m_shapeConverter = SpatialDocMaker.MakeShapeConverter(m_strategy, config, "query.spatial."); m_distErrPct = config.Get("query.spatial.distErrPct", double.NaN); m_operation = SpatialOperation.Get(config.Get("query.spatial.predicate", "Intersects")); m_score = config.Get("query.spatial.score", false); base.SetConfig(config);//call last, will call prepareQueries() }
private Query MakeSpatialQuery(SpatialArgs args) { var bbox = args.Shape as Rectangle; if (bbox == null) { throw new InvalidOperationException("Can only query by Rectangle, not " + args.Shape); } Query spatial = null; // Useful for understanding Relations: // http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm SpatialOperation op = args.Operation; if (op == SpatialOperation.BBoxIntersects) { spatial = MakeIntersects(bbox); } else if (op == SpatialOperation.BBoxWithin) { spatial = MakeWithin(bbox); } else if (op == SpatialOperation.Contains) { spatial = MakeContains(bbox); } else if (op == SpatialOperation.Intersects) { spatial = MakeIntersects(bbox); } else if (op == SpatialOperation.IsEqualTo) { spatial = MakeEquals(bbox); } else if (op == SpatialOperation.IsDisjointTo) { spatial = MakeDisjoint(bbox); } else if (op == SpatialOperation.IsWithin) { spatial = MakeWithin(bbox); } else if (op == SpatialOperation.Overlaps) { spatial = MakeIntersects(bbox); } else { throw new UnsupportedSpatialOperation(op); } return(spatial); }
protected override void WriteSpatialExtentsExpressionSqlInternal(StringBuilder builder, SpatialOperation spatialOperation, IExtents ext) { IExtents2D exts = (IExtents2D)ext; builder.Append(string.Format(" Mbr{0}( BuildMbr({1}, {2}, {3}, {4}),{5} )", spatialOperation.ToString(), CreateParameter <double>(exts.XMin).ParameterName, CreateParameter <double>(exts.YMin).ParameterName, CreateParameter <double>(exts.XMax + 1.0e-6).ParameterName, CreateParameter <double>(exts.YMax + 1.0e-6).ParameterName, Provider.GeometryColumn)); }
private void checkOp(SpatialOperation op) { switch (op) { case SpatialOperation.Contains: case SpatialOperation.Disjoint: case SpatialOperation.Intersects: return; default: throw new NotSupportedException("Operation not supported for raster query."); } }
public override Filter MakeFilter(SpatialArgs args) { var op = args.Operation; if (SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects) == false) { throw new UnsupportedSpatialOperation(op); } var shape = args.Shape; var detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct)); return(new RecursivePrefixTreeFilter(GetFieldName(), grid, shape, _prefixGridScanLevel, detailLevel)); }
protected virtual void AssertOperation(IDictionary<String, IShape> indexedDocs, SpatialOperation operation, IShape queryShape) { //Generate truth via brute force ISet<string> expectedIds = new JCG.HashSet<string>(); foreach (var stringShapeEntry in indexedDocs) { if (operation.Evaluate(stringShapeEntry.Value, queryShape)) expectedIds.add(stringShapeEntry.Key); } SpatialTestQuery testQuery = new SpatialTestQuery(); testQuery.args = new SpatialArgs(operation, queryShape); testQuery.ids = new List<string>(expectedIds); runTestQuery(SpatialMatchConcern.FILTER, testQuery); }
private QueryHelper <TModel> GeoFilter(Expression <Func <TModel, object> > exp, double longitude, double latitude, double distDEG) { string name = getName(exp.Body.ToString()); //name = name.IndexOf('.') > -1 ? name.Substring(0, name.LastIndexOf('.')) : name; SpatialOperation op = SpatialOperation.Intersects; //SpatialStrategy strat = new PointVectorStrategy(ctx, name); int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); var strat = new RecursivePrefixTreeStrategy(grid, name); var point = ctx.MakePoint(longitude, latitude); var shape = ctx.MakeCircle(point, distDEG); var args = new SpatialArgs(op, shape); filter = strat.MakeFilter(args); return(this); }
public void WfsFilterWfsXmlRepresentation_BoundingBox_CorrectXmlRepresentationIsCreated() { string strFilter = "<Filter><Or><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>5</Literal></PropertyIsEqualTo><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>6</Literal></PropertyIsEqualTo></Or></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); SpatialBoundingBox spatialBoundingBox = new SpatialBoundingBox(-180, -90, 180, 90, "EPSG:4326"); var bboxOperation = new SpatialOperation(new SpatialFieldValue("the_geom"), spatialBoundingBox, WFSSpatialOperator.InsideBbox); formulaOperation = new BinaryLogicalOperation(formulaOperation, bboxOperation, WFSBinaryLogicalOperator.And); WFSFilter wfsFilter = new WFSFilter { Formula = formulaOperation }; string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation(); string expectedXmlString = "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\"><ogc:And><ogc:Or><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>5</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>6</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or><ogc:BBOX><ogc:PropertyName>the_geom</ogc:PropertyName><gml:Envelope xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"EPSG:4326\"><gml:lowerCorner>-180 -90</gml:lowerCorner><gml:upperCorner>180 90</gml:upperCorner></gml:Envelope></ogc:BBOX></ogc:And></ogc:Filter>"; Assert.IsNotNull(formulaOperation); Assert.AreEqual(expectedXmlString, strWfsXmlRepresentation); }
public override Filter MakeFilter(SpatialArgs args) { SpatialOperation op = args.Operation; if (op != SpatialOperation.Intersects) { throw new UnsupportedSpatialOperation(op); } IShape shape = args.Shape; int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct)); IList <Cell> cells = grid.GetCells(shape, detailLevel, false /*no parents*/, true /*simplify*/); var terms = new BytesRef[cells.Count]; int i = 0; foreach (Cell cell in cells) { terms[i++] = new BytesRef(cell.TokenString);//TODO use cell.getTokenBytes() } return(new TermsFilter(FieldName, terms)); }
public override Filter MakeFilter(SpatialArgs args) { SpatialOperation op = args.Operation; if (op != SpatialOperation.Intersects) { throw new UnsupportedSpatialOperation(op); } Shape shape = args.Shape; int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct)); var cells = grid.GetNodes(shape, detailLevel, false); var filter = new TermsFilter(); foreach (Node cell in cells) { filter.AddTerm(new Term(GetFieldName(), cell.GetTokenString())); } return(filter); }
/// <param name="strategy">Needed to compute intersects</param> /// <param name="args">Used in spatial intersection</param> /// <param name="field"> /// This field is used to determine which docs have spatial data via /// <see cref="IFieldCache.GetDocsWithField(AtomicReader, string)"/>. /// Passing <c>null</c> will assume all docs have spatial data. /// </param> public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string?field) { // LUCENENET specific - added guard clauses if (strategy is null) { throw new ArgumentNullException(nameof(strategy)); } if (args is null) { throw new ArgumentNullException(nameof(args)); } this.field = field; // TODO consider making SpatialArgs cloneable SpatialOperation origOp = args.Operation; //copy so we can restore args.Operation = SpatialOperation.Intersects; //temporarily set to intersects intersectsFilter = strategy.MakeFilter(args); args.Operation = origOp; }