List of usage examples for org.apache.lucene.spatial.query SpatialArgs setDistErr
public void setDistErr(Double distErr)
From source file:com.boundlessgeo.elasticsearch.geoheatmap.GeoHeatmapAggregatorFactory.java
License:Apache License
private Integer resolveGridLevel(Optional<Double> distErrOp, Optional<Double> distErrPctOp) { SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, this.inputShape); if (distErrOp.isPresent()) { spatialArgs.setDistErr(distErrOp.get() * DistanceUnit.DEFAULT.getDistancePerDegree()); }/* w ww. jav a 2 s. co m*/ spatialArgs.setDistErrPct(distErrPctOp.orElse(DEFAULT_DIST_ERR_PCT)); double distErr = spatialArgs.resolveDistErr(strategy.getSpatialContext(), DEFAULT_DIST_ERR_PCT); if (distErr <= 0) { throw new AggregationInitializationException(String.format(Locale.ROOT, "%s or %s should be > 0 or instead provide %s=%s for absolute maximum detail", GeoHeatmapAggregationBuilder.DIST_ERR_PCT_FIELD, GeoHeatmapAggregationBuilder.DIST_ERR_FIELD, GeoHeatmapAggregationBuilder.GRID_LEVEL_FIELD, strategy.getGrid().getMaxLevels())); } return strategy.getGrid().getLevelForDistance(distErr); }
From source file:com.stratio.cassandra.lucene.search.condition.GeoShapeCondition.java
License:Apache License
/** {@inheritDoc} */ @Override//from www.j ava 2s .c o m public Query query(Schema schema) { // Get the spatial strategy from the mapper SpatialStrategy strategy; Mapper mapper = schema.getMapper(field); if (mapper == null) { throw new IndexException("No mapper found for field '%s'", field); } else if (mapper instanceof GeoShapeMapper) { strategy = ((GeoShapeMapper) mapper).strategy; } else if (mapper instanceof GeoPointMapper) { strategy = ((GeoPointMapper) mapper).distanceStrategy; } else { throw new IndexException( "'geo_shape' search requires a mapper of type 'geo_point' or 'geo_shape' " + "but found %s:%s", field, mapper); } // Apply transformations JtsGeometry transformedGeometry = geometry; if (transformations != null) { for (GeoTransformation transformation : transformations) { transformedGeometry = transformation.apply(transformedGeometry, CONTEXT); } } // Build query SpatialArgs args = new SpatialArgs(operation.getSpatialOperation(), transformedGeometry); args.setDistErr(0.0); Query query = strategy.makeQuery(args); query.setBoost(boost); return query; }
From source file:org.apache.blur.analysis.type.spatial.SpatialArgsParser.java
License:Apache License
/** * Parses a string such as "Intersects(-10,20,-8,22) distErrPct=0.025". * //www . j ava 2 s .c o m * @param v * The string to parse. Mandatory. * @param shapeReadWriter * The spatial shapeReadWriter. Mandatory. * @return Not null. * @throws IllegalArgumentException * If there is a problem parsing the string. * @throws InvalidShapeException * Thrown from {@link ShapeReadWriter#readShape(String)} */ public static SpatialArgs parse(String v, ShapeReadWriter<SpatialContext> shapeReadWriter) throws IllegalArgumentException, InvalidShapeException { int idx = v.indexOf('('); int edx = v.lastIndexOf(')'); if (idx < 0 || idx > edx) { throw new IllegalArgumentException("missing parens: " + v, null); } SpatialOperation op = SpatialOperation.get(v.substring(0, idx).trim()); String body = v.substring(idx + 1, edx).trim(); if (body.length() < 1) { throw new IllegalArgumentException("missing body : " + v, null); } Shape shape = shapeReadWriter.readShape(body); SpatialArgs args = new SpatialArgs(op, shape); if (v.length() > (edx + 1)) { body = v.substring(edx + 1).trim(); if (body.length() > 0) { Map<String, String> aa = parseMap(body); args.setDistErrPct(readDouble(aa.remove(DIST_ERR_PCT))); args.setDistErr(readDouble(aa.remove(DIST_ERR))); if (!aa.isEmpty()) { throw new IllegalArgumentException("unused parameters: " + aa, null); } } } args.validate(); return args; }
From source file:org.apache.jena.query.spatial.SpatialIndexLucene.java
License:Apache License
private List<Node> query$(IndexReader indexReader, Shape shape, int limit, SpatialOperation operation) throws IOException { if (limit <= 0) limit = MAX_N;//w ww . j a va 2 s . c om IndexSearcher indexSearcher = new IndexSearcher(indexReader); SpatialArgs args = new SpatialArgs(operation, shape); args.setDistErr(0.0); Query query = strategy.makeQuery(args); TopDocs docs = indexSearcher.search(query, limit); List<Node> results = new ArrayList<>(); for (ScoreDoc sd : docs.scoreDocs) { Document doc = indexSearcher.doc(sd.doc); String[] values = doc.getValues(docDef.getEntityField()); for (String v : values) { Node n = SpatialQueryFuncs.stringToNode(v); results.add(n); } } return results; }
From source file:org.apache.solr.handler.component.SpatialHeatmapFacets.java
License:Apache License
/** Called by {@link org.apache.solr.request.SimpleFacets} to compute heatmap facets. */ public static NamedList<Object> getHeatmapForField(String fieldKey, String fieldName, ResponseBuilder rb, SolrParams params, DocSet docSet) throws IOException { //get the strategy from the field type final SchemaField schemaField = rb.req.getSchema().getField(fieldName); final FieldType type = schemaField.getType(); if (!(type instanceof AbstractSpatialPrefixTreeFieldType)) { //FYI we support the term query one too but few people use that one throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "heatmap field needs to be of type " + SpatialRecursivePrefixTreeFieldType.class); }// ww w .ja v a 2s .c om AbstractSpatialPrefixTreeFieldType rptType = (AbstractSpatialPrefixTreeFieldType) type; final PrefixTreeStrategy strategy = (PrefixTreeStrategy) rptType.getStrategy(fieldName); final SpatialContext ctx = strategy.getSpatialContext(); //get the bbox (query Rectangle) String geomStr = params.getFieldParam(fieldKey, FacetParams.FACET_HEATMAP_GEOM); final Shape boundsShape = geomStr == null ? ctx.getWorldBounds() : SpatialUtils.parseGeomSolrException(geomStr, ctx); //get the grid level (possibly indirectly via distErr or distErrPct) final int gridLevel; Integer gridLevelObj = params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_LEVEL); final int maxGridLevel = strategy.getGrid().getMaxLevels(); if (gridLevelObj != null) { gridLevel = gridLevelObj; if (gridLevel <= 0 || gridLevel > maxGridLevel) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, FacetParams.FACET_HEATMAP_LEVEL + " should be > 0 and <= " + maxGridLevel); } } else { //SpatialArgs has utility methods to resolve a 'distErr' from optionally set distErr & distErrPct. Arguably that // should be refactored to feel less weird than using it like this. SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects/*ignored*/, boundsShape == null ? ctx.getWorldBounds() : boundsShape); final Double distErrObj = params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR); if (distErrObj != null) { // convert distErr units based on configured units spatialArgs.setDistErr(distErrObj * rptType.getDistanceUnits().multiplierFromThisUnitToDegrees()); } spatialArgs.setDistErrPct(params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR_PCT)); double distErr = spatialArgs.resolveDistErr(ctx, DEFAULT_DIST_ERR_PCT); if (distErr <= 0) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, FacetParams.FACET_HEATMAP_DIST_ERR_PCT + " or " + FacetParams.FACET_HEATMAP_DIST_ERR + " should be > 0 or instead provide " + FacetParams.FACET_HEATMAP_LEVEL + "=" + maxGridLevel + " if you insist on maximum detail"); } //The SPT (grid) can lookup a grid level satisfying an error distance constraint gridLevel = strategy.getGrid().getLevelForDistance(distErr); } //Compute! final HeatmapFacetCounter.Heatmap heatmap; try { heatmap = HeatmapFacetCounter.calcFacets(strategy, rb.req.getSearcher().getTopReaderContext(), docSet.getTopFilter(), boundsShape, gridLevel, params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_MAX_CELLS, 100_000) // will throw if exceeded ); } catch (IllegalArgumentException e) {//e.g. too many cells throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.toString(), e); } //Populate response NamedList<Object> result = new NamedList<>(); result.add("gridLevel", gridLevel); result.add("columns", heatmap.columns); result.add("rows", heatmap.rows); result.add("minX", heatmap.region.getMinX()); result.add("maxX", heatmap.region.getMaxX()); result.add("minY", heatmap.region.getMinY()); result.add("maxY", heatmap.region.getMaxY()); boolean hasNonZero = false; for (int count : heatmap.counts) { if (count > 0) { hasNonZero = true; break; } } formatCountsAndAddToNL(fieldKey, rb, params, heatmap.columns, heatmap.rows, hasNonZero ? heatmap.counts : null, result); return result; }