for(Point pt: gpx.getPoints( )) Location loc = new Location( pt.getLatitude( ), pt.getLongitude( ) ) ;
private void centerMap() { int minLat = Integer.MAX_VALUE; int maxLat = Integer.MIN_VALUE; int minLon = Integer.MAX_VALUE; int maxLon = Integer.MIN_VALUE; for (Point point : twoPoints) { int lat = (int) (point.getLatitude() * 1E6); int lon = (int) (point.getLongitude() * 1E6); maxLat = Math.max(lat, maxLat); minLat = Math.min(lat, minLat); maxLon = Math.max(lon, maxLon); minLon = Math.min(lon, minLon); } mc.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); mc.animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2)); }
/** * Compute distance between two points * * @param other a {@link org.hibernate.search.spatial.impl.Point} object. * @return the distance between points * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Distance haversine formula</a> */ public double getDistanceTo(Point other) { return getDistanceTo( other.getLatitude(), other.getLongitude() ); }
/** * Compute distance between two points * * @param other a {@link org.hibernate.search.spatial.impl.Point} object. * @return the distance between points * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Distance haversine formula</a> */ public double getDistanceTo(Point other) { return getDistanceTo( other.getLatitude(), other.getLongitude() ); }
Gpx gpx = GpxFileIo.parseIn( "SomeGeoCollection.gpx" ) ; for (Point pt: gpx.getPoints( ) ) { Location loc = new Location( pt.getLatitude( ), pt.getLongitude( ) ) ; if (pt.getElevation( ) != null) loc.setElevation( pt.getElevation( ) ) ; }
pointToAdd.setX(p.getLongitude()); pointToAdd.setY(p.getLatitude());
Math.abs( minimumLatitude ), Math.abs( maximumLatitude ) ), center.getLongitude() ); maximumLongitude = referencePoint.computeDestination( radius, GeometricConstants.HEADING_EAST ) .getLongitude(); minimumLongitude = referencePoint.computeDestination( radius, GeometricConstants.HEADING_WEST ) .getLongitude();
Math.abs( minimumLatitude ), Math.abs( maximumLatitude ) ), center.getLongitude() ); maximumLongitude = referencePoint.computeDestination( radius, GeometricConstants.HEADING_EAST ) .getLongitude(); minimumLongitude = referencePoint.computeDestination( radius, GeometricConstants.HEADING_WEST ) .getLongitude();
); double[] projectedLowerRight = projectToIndexSpace( Point.fromDegrees( lowerLeft.getLatitude(), upperRight.getLongitude() ) ); int lowerRightXIndex = getCellIndex( projectedLowerRight[0], ); double[] projectedUpperLeft = projectToIndexSpace( Point.fromDegrees( upperRight.getLatitude(), lowerLeft.getLongitude() ) ); int upperLeftXIndex = getCellIndex( projectedUpperLeft[0],
); double[] projectedLowerRight = projectToIndexSpace( Point.fromDegrees( lowerLeft.getLatitude(), upperRight.getLongitude() ) ); int lowerRightXIndex = getCellIndex( projectedLowerRight[0], ); double[] projectedUpperLeft = projectToIndexSpace( Point.fromDegrees( upperRight.getLatitude(), lowerLeft.getLongitude() ) ); int upperLeftXIndex = getCellIndex( projectedUpperLeft[0],
if ( boundingBox.getLowerLeft().getLongitude() <= boundingBox.getUpperRight().getLongitude() ) { longQuery = NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), boundingBox.getUpperRight().getLongitude(), true, true ); .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), 180.0, true, true ), BooleanClause.Occur.SHOULD ) .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, -180.0, boundingBox.getUpperRight().getLongitude(), true, true ), BooleanClause.Occur.SHOULD ) .build();
if ( boundingBox.getLowerLeft().getLongitude() <= boundingBox.getUpperRight().getLongitude() ) { longQuery = NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), boundingBox.getUpperRight().getLongitude(), true, true ); .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), 180.0, true, true ), BooleanClause.Occur.SHOULD ) .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, -180.0, boundingBox.getUpperRight().getLongitude(), true, true ), BooleanClause.Occur.SHOULD ) .build();
double lowerLeftLongitude = boundingBox.getLowerLeft().getLongitude(); double upperRightLatitude = boundingBox.getUpperRight().getLatitude(); double upperRightLongitude = boundingBox.getUpperRight().getLongitude();
double lowerLeftLongitude = boundingBox.getLowerLeft().getLongitude(); double upperRightLatitude = boundingBox.getUpperRight().getLatitude(); double upperRightLongitude = boundingBox.getUpperRight().getLongitude();
@Test public void boundingBoxTest() { Point center = Point.fromDegrees( 45, 4 ); Rectangle rectangle = Rectangle.fromBoundingCircle( center, 50 ); Assert.assertEquals( 44.550339, rectangle.getLowerLeft().getLatitude(), 0.000001d ); Assert.assertEquals( 3.359047, rectangle.getLowerLeft().getLongitude(), 0.000001d ); Assert.assertEquals( 45.449660, rectangle.getUpperRight().getLatitude(), 0.000001d ); Assert.assertEquals( 4.640952, rectangle.getUpperRight().getLongitude(), 0.000001d ); } }
@Test public void normalizeTest() { Point point = Point.fromDegrees( 45, 517 ); Assert.assertEquals( 45, point.getLatitude(), 0 ); Assert.assertEquals( 157, point.getLongitude(), 0 ); Point point2 = Point.fromDegrees( 0, -185 ); Assert.assertEquals( 175, point2.getLongitude(), 0 ); Point point3 = Point.fromDegrees( 110, 0 ); Assert.assertEquals( 70, point3.getLatitude(), 0 ); Point point4 = Point.fromDegrees( -110, 0 ); Assert.assertEquals( -70, point4.getLatitude(), 0 ); Point point5 = Point.fromDegrees( 185, 0 ); Assert.assertEquals( -5, point5.getLatitude(), 0 ); Point point6 = Point.fromDegrees( 90, 180 ); Assert.assertEquals( 90, point6.getLatitude(), 0 ); Assert.assertEquals( 180, point6.getLongitude(), 0 ); Point point7 = Point.fromDegrees( -90, -180 ); Assert.assertEquals( -90, point7.getLatitude(), 0 ); Assert.assertEquals( 180, point7.getLongitude(), 0 ); }
queryBuilder.range() .onField( "longitude" ) .from( boundingBox.getLowerLeft().getLongitude() ) .to( boundingBox.getUpperRight().getLongitude() ) .createQuery() queryBuilder.range() .onField( "longitude" ) .from( boundingBox.getLowerLeft().getLongitude() ) .to( boundingBox.getUpperRight().getLongitude() ) .createQuery() Double.toString( center.getLatitude() ) + "," + Double.toString( center.getLongitude() ) + ") and radius " + Double.toString( radius )
private static JsonObject convertDistanceQuery(DistanceQuery query) { JsonObject distanceQuery = JsonBuilder.object() .add( "geo_distance", JsonBuilder.object() .addProperty( "distance", query.getRadius() + "km" ) .add( query.getCoordinatesField(), JsonBuilder.object() .addProperty( "lat", query.getCenter().getLatitude() ) .addProperty( "lon", query.getCenter().getLongitude() ) ) ).build(); distanceQuery = wrapQueryForNestedIfRequired( query.getCoordinatesField(), distanceQuery ); // we only implement the approximation optimization when we use the hash method as Elasticsearch // automatically optimize the geo_distance query with a bounding box filter so we don't need to do it // ourselves when we use the range method. Query approximationQuery = query.getApproximationQuery(); if ( approximationQuery instanceof SpatialHashQuery ) { distanceQuery = JsonBuilder.object() .add( "bool", JsonBuilder.object() .add( "must", distanceQuery ) .add( "filter", convertSpatialHashFilter( (SpatialHashQuery) approximationQuery ) ) ).build(); } return distanceQuery; }
private static JsonObject convertDistanceQuery(DistanceQuery query) { JsonObject distanceQuery = JsonBuilder.object() .add( "geo_distance", JsonBuilder.object() .addProperty( "distance", query.getRadius() + "km" ) .add( query.getCoordinatesField(), JsonBuilder.object() .addProperty( "lat", query.getCenter().getLatitude() ) .addProperty( "lon", query.getCenter().getLongitude() ) ) ).build(); distanceQuery = wrapQueryForNestedIfRequired( query.getCoordinatesField(), distanceQuery ); // we only implement the approximation optimization when we use the hash method as Elasticsearch // automatically optimize the geo_distance query with a bounding box filter so we don't need to do it // ourselves when we use the range method. Query approximationQuery = query.getApproximationQuery(); if ( approximationQuery instanceof SpatialHashQuery ) { distanceQuery = JsonBuilder.object() .add( "bool", JsonBuilder.object() .add( "must", distanceQuery ) .add( "filter", convertSpatialHashFilter( (SpatialHashQuery) approximationQuery ) ) ).build(); } return distanceQuery; }
private static JsonObject convertDistanceFilter(DistanceFilter filter) { JsonObject distanceQuery = JsonBuilder.object() .add( "geo_distance", JsonBuilder.object() .addProperty( "distance", filter.getRadius() + "km" ) .add( filter.getCoordinatesField(), JsonBuilder.object() .addProperty( "lat", filter.getCenter().getLatitude() ) .addProperty( "lon", filter.getCenter().getLongitude() ) ) ).build(); distanceQuery = wrapQueryForNestedIfRequired( filter.getCoordinatesField(), distanceQuery ); // we only implement the previous filter optimization when we use the hash method as Elasticsearch // automatically optimize the geo_distance query with a bounding box filter so we don't need to do it // ourselves when we use the range method. Filter previousFilter = filter.getPreviousFilter(); if ( previousFilter instanceof SpatialHashFilter ) { distanceQuery = JsonBuilder.object() .add( "filtered", JsonBuilder.object() .add( "query", distanceQuery ) .add( "filter", convertSpatialHashFilter( (SpatialHashFilter) previousFilter ) ) ).build(); } return distanceQuery; }