-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geo: Adds a set of no dependency geo classes for JDBC driver #36477
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
104d4e5
Add initial GeoShape hierachy
nknize 9b784e2
Geo: Clean up geo hierarchy
imotov 937e289
Address @atorok's review comments
imotov cde7964
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov 01cae20
Address @atorok's 2nd review
imotov a5acea2
Fix geo-test configuration for eclipse
imotov bb491d8
Move project name setting into settings.gradle
imotov f2f0f55
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov 7fdddb6
Add test for Geometry Visitor
imotov f31d10c
Make GeomUtils package private
imotov 168c947
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov 9408af7
Add javadoc with explanation of the Visitor Pattern
imotov a164360
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov 524c6aa
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov 4929333
Address review comments
imotov ed3a92a
Merge remote-tracking branch 'elastic/master' into issue-35767-libs-geo
imotov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.build' | ||
apply plugin: 'nebula.maven-base-publish' | ||
apply plugin: 'nebula.maven-scm' | ||
|
||
dependencies { | ||
if (isEclipse == false || project.path == ":libs:geo-tests") { | ||
testCompile("org.elasticsearch.test:framework:${version}") { | ||
exclude group: 'org.elasticsearch', module: 'elasticsearch-geo' | ||
} | ||
} | ||
} | ||
|
||
forbiddenApisMain { | ||
// geo does not depend on server | ||
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core | ||
replaceSignatureFiles 'jdk-signatures' | ||
} | ||
|
||
if (isEclipse) { | ||
// in eclipse the project is under a fake root, we need to change around the source sets | ||
sourceSets { | ||
if (project.path == ":libs:geo") { | ||
main.java.srcDirs = ['java'] | ||
main.resources.srcDirs = ['resources'] | ||
} else { | ||
test.java.srcDirs = ['java'] | ||
test.resources.srcDirs = ['resources'] | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
libs/geo/src/main/java/org/elasticsearch/geo/geometry/Circle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.geo.geometry; | ||
|
||
/** | ||
* Circle geometry (not part of WKT standard, but used in elasticsearch) | ||
*/ | ||
public class Circle implements Geometry { | ||
public static final Circle EMPTY = new Circle(); | ||
private final double lat; | ||
private final double lon; | ||
private final double radiusMeters; | ||
|
||
private Circle() { | ||
lat = 0; | ||
lon = 0; | ||
radiusMeters = -1; | ||
} | ||
|
||
public Circle(final double lat, final double lon, final double radiusMeters) { | ||
this.lat = lat; | ||
this.lon = lon; | ||
this.radiusMeters = radiusMeters; | ||
if (radiusMeters < 0 ) { | ||
throw new IllegalArgumentException("Circle radius [" + radiusMeters + "] cannot be negative"); | ||
} | ||
GeometryUtils.checkLatitude(lat); | ||
GeometryUtils.checkLongitude(lon); | ||
} | ||
|
||
@Override | ||
public ShapeType type() { | ||
return ShapeType.CIRCLE; | ||
} | ||
|
||
public double getLat() { | ||
return lat; | ||
} | ||
|
||
public double getLon() { | ||
return lon; | ||
} | ||
|
||
public double getRadiusMeters() { | ||
return radiusMeters; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Circle circle = (Circle) o; | ||
if (Double.compare(circle.lat, lat) != 0) return false; | ||
if (Double.compare(circle.lon, lon) != 0) return false; | ||
return (Double.compare(circle.radiusMeters, radiusMeters) == 0); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result; | ||
long temp; | ||
temp = Double.doubleToLongBits(lat); | ||
result = (int) (temp ^ (temp >>> 32)); | ||
temp = Double.doubleToLongBits(lon); | ||
result = 31 * result + (int) (temp ^ (temp >>> 32)); | ||
temp = Double.doubleToLongBits(radiusMeters); | ||
result = 31 * result + (int) (temp ^ (temp >>> 32)); | ||
return result; | ||
} | ||
|
||
@Override | ||
public <T> T visit(GeometryVisitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return radiusMeters < 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "lat=" + lat + ", lon=" + lon + ", radius=" + radiusMeters; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
libs/geo/src/main/java/org/elasticsearch/geo/geometry/Geometry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.geo.geometry; | ||
|
||
/** | ||
* Base class for all Geometry objects supported by elasticsearch | ||
*/ | ||
public interface Geometry { | ||
|
||
ShapeType type(); | ||
|
||
<T> T visit(GeometryVisitor<T> visitor); | ||
|
||
boolean isEmpty(); | ||
} |
85 changes: 85 additions & 0 deletions
85
libs/geo/src/main/java/org/elasticsearch/geo/geometry/GeometryCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.geo.geometry; | ||
|
||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Collection of arbitrary geometry classes | ||
*/ | ||
public class GeometryCollection<G extends Geometry> implements Geometry, Iterable<G> { | ||
public static final GeometryCollection<Geometry> EMPTY = new GeometryCollection<>(); | ||
|
||
private final List<G> shapes; | ||
|
||
public GeometryCollection() { | ||
shapes = Collections.emptyList(); | ||
} | ||
|
||
public GeometryCollection(List<G> shapes) { | ||
if (shapes == null || shapes.isEmpty()) { | ||
throw new IllegalArgumentException("the list of shapes cannot be null or empty"); | ||
} | ||
this.shapes = shapes; | ||
} | ||
|
||
@Override | ||
public ShapeType type() { | ||
return ShapeType.GEOMETRYCOLLECTION; | ||
} | ||
|
||
@Override | ||
public <T> T visit(GeometryVisitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return shapes.isEmpty(); | ||
} | ||
|
||
public int size() { | ||
return shapes.size(); | ||
} | ||
|
||
public G get(int i) { | ||
return shapes.get(i); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GeometryCollection<?> that = (GeometryCollection<?>) o; | ||
return Objects.equals(shapes, that.shapes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(shapes); | ||
} | ||
|
||
@Override | ||
public Iterator<G> iterator() { | ||
return shapes.iterator(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
libs/geo/src/main/java/org/elasticsearch/geo/geometry/GeometryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.geo.geometry; | ||
|
||
/** | ||
* Geometry-related utility methods | ||
*/ | ||
final class GeometryUtils { | ||
/** | ||
* Minimum longitude value. | ||
*/ | ||
static final double MIN_LON_INCL = -180.0D; | ||
|
||
/** | ||
* Maximum longitude value. | ||
*/ | ||
static final double MAX_LON_INCL = 180.0D; | ||
|
||
/** | ||
* Minimum latitude value. | ||
*/ | ||
static final double MIN_LAT_INCL = -90.0D; | ||
|
||
/** | ||
* Maximum latitude value. | ||
*/ | ||
static final double MAX_LAT_INCL = 90.0D; | ||
|
||
// No instance: | ||
private GeometryUtils() { | ||
} | ||
|
||
/** | ||
* validates latitude value is within standard +/-90 coordinate bounds | ||
*/ | ||
static void checkLatitude(double latitude) { | ||
if (Double.isNaN(latitude) || latitude < MIN_LAT_INCL || latitude > MAX_LAT_INCL) { | ||
throw new IllegalArgumentException( | ||
"invalid latitude " + latitude + "; must be between " + MIN_LAT_INCL + " and " + MAX_LAT_INCL); | ||
} | ||
} | ||
|
||
/** | ||
* validates longitude value is within standard +/-180 coordinate bounds | ||
*/ | ||
static void checkLongitude(double longitude) { | ||
if (Double.isNaN(longitude) || longitude < MIN_LON_INCL || longitude > MAX_LON_INCL) { | ||
throw new IllegalArgumentException( | ||
"invalid longitude " + longitude + "; must be between " + MIN_LON_INCL + " and " + MAX_LON_INCL); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we planning to publish this jar e.x to maven central ?
Note that we'll have to update the release manager in that case.
We should only configure publishing if we do plan to publish it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. Its content will be shipped as a part of fat jdbc jar for SQL, but it will also used inside elasticsearch itself for geo operations. So that probably means that it needs to be published, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, don't forget to add it to release manager.