XLatLonShapeLineQuery(String field, QueryRelation queryRelation, Line... lines) { super(field, queryRelation); /** line queries do not support within relations, only intersects and disjoint */ if (queryRelation == QueryRelation.WITHIN) { throw new IllegalArgumentException("LatLonShapeLineQuery does not support " + QueryRelation.WITHIN + " queries"); } if (lines == null) { throw new IllegalArgumentException("lines must not be null"); } if (lines.length == 0) { throw new IllegalArgumentException("lines must not be empty"); } for (int i = 0; i < lines.length; ++i) { if (lines[i] == null) { throw new IllegalArgumentException("line[" + i + "] must not be null"); } else if (lines[i].minLon > lines[i].maxLon) { throw new IllegalArgumentException("LatLonShapeLineQuery does not currently support querying across dateline."); } } this.lines = lines.clone(); this.line2D = Line2D.create(lines); }
@Override protected boolean queryMatches(byte[] t, int[] scratchTriangle) { XLatLonShape.decodeTriangle(t, scratchTriangle); double alat = GeoEncodingUtils.decodeLatitude(scratchTriangle[0]); double alon = GeoEncodingUtils.decodeLongitude(scratchTriangle[1]); double blat = GeoEncodingUtils.decodeLatitude(scratchTriangle[2]); double blon = GeoEncodingUtils.decodeLongitude(scratchTriangle[3]); double clat = GeoEncodingUtils.decodeLatitude(scratchTriangle[4]); double clon = GeoEncodingUtils.decodeLongitude(scratchTriangle[5]); if (queryRelation == XLatLonShape.QueryRelation.WITHIN) { return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) == Relation.CELL_INSIDE_QUERY; } // INTERSECTS return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) != Relation.CELL_OUTSIDE_QUERY; }
@Override protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle) { double minLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(minTriangle, minYOffset)); double minLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(minTriangle, minXOffset)); double maxLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(maxTriangle, maxYOffset)); double maxLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(maxTriangle, maxXOffset)); // check internal node against query return line2D.relate(minLat, maxLat, minLon, maxLon); }
/** create a Line2D edge tree from provided array of Linestrings */ public static Line2D create(Line... lines) { Line2D components[] = new Line2D[lines.length]; for (int i = 0; i < components.length; ++i) { components[i] = new Line2D(lines[i]); } return (Line2D)createTree(components, 0, components.length - 1, false); } }
@Override protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle) { double minLat = GeoEncodingUtils.decodeLatitude(LatLonShape.decodeTriangleBoxVal(minTriangle, minYOffset)); double minLon = GeoEncodingUtils.decodeLongitude(LatLonShape.decodeTriangleBoxVal(minTriangle, minXOffset)); double maxLat = GeoEncodingUtils.decodeLatitude(LatLonShape.decodeTriangleBoxVal(maxTriangle, maxYOffset)); double maxLon = GeoEncodingUtils.decodeLongitude(LatLonShape.decodeTriangleBoxVal(maxTriangle, maxXOffset)); // check internal node against query return line2D.relate(minLat, maxLat, minLon, maxLon); }
@Override protected boolean queryMatches(byte[] t) { long a = NumericUtils.sortableBytesToLong(t, 4 * LatLonShape.BYTES); long b = NumericUtils.sortableBytesToLong(t, 5 * LatLonShape.BYTES); long c = NumericUtils.sortableBytesToLong(t, 6 * LatLonShape.BYTES); int aX = (int)((a >>> 32) & 0x00000000FFFFFFFFL); int bX = (int)((b >>> 32) & 0x00000000FFFFFFFFL); int cX = (int)((c >>> 32) & 0x00000000FFFFFFFFL); int aY = (int)(a & 0x00000000FFFFFFFFL); int bY = (int)(b & 0x00000000FFFFFFFFL); int cY = (int)(c & 0x00000000FFFFFFFFL); double alat = GeoEncodingUtils.decodeLatitude(aY); double alon = GeoEncodingUtils.decodeLongitude(aX); double blat = GeoEncodingUtils.decodeLatitude(bY); double blon = GeoEncodingUtils.decodeLongitude(bX); double clat = GeoEncodingUtils.decodeLatitude(cY); double clon = GeoEncodingUtils.decodeLongitude(cX); if (queryRelation == LatLonShape.QueryRelation.WITHIN) { return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) == Relation.CELL_INSIDE_QUERY; } // INTERSECTS return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) != Relation.CELL_OUTSIDE_QUERY; }
public LatLonShapeLineQuery(String field, QueryRelation queryRelation, Line... lines) { super(field, queryRelation); /** line queries do not support within relations, only intersects and disjoint */ if (queryRelation == QueryRelation.WITHIN) { throw new IllegalArgumentException("LatLonShapeLineQuery does not support " + QueryRelation.WITHIN + " queries"); } if (lines == null) { throw new IllegalArgumentException("lines must not be null"); } if (lines.length == 0) { throw new IllegalArgumentException("lines must not be empty"); } for (int i = 0; i < lines.length; ++i) { if (lines[i] == null) { throw new IllegalArgumentException("line[" + i + "] must not be null"); } else if (lines[i].minLon > lines[i].maxLon) { throw new IllegalArgumentException("LatLonShapeLineQuery does not currently support querying across dateline."); } } this.lines = lines.clone(); this.line2D = Line2D.create(lines); }