-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Changes from 6 commits
104d4e5
9b784e2
937e289
cde7964
01cae20
a5acea2
bb491d8
f2f0f55
7fdddb6
f31d10c
168c947
9408af7
a164360
524c6aa
4929333
ed3a92a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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' | ||
|
||
archivesBaseName = 'elasticsearch-geo' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: you could have |
||
|
||
publishing { | ||
publications { | ||
nebula { | ||
artifactId = archivesBaseName | ||
} | ||
} | ||
} | ||
|
||
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'] | ||
} | ||
} | ||
} |
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; | ||
|
||
/** | ||
* Basic reusable geo-spatial utility methods | ||
*/ | ||
public final class GeoUtils { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. I renamed it to GeometryUtils when I made changed its visibility. |
||
/** | ||
* Minimum longitude value. | ||
*/ | ||
public static final double MIN_LON_INCL = -180.0D; | ||
|
||
/** | ||
* Maximum longitude value. | ||
*/ | ||
public static final double MAX_LON_INCL = 180.0D; | ||
|
||
/** | ||
* Minimum latitude value. | ||
*/ | ||
public static final double MIN_LAT_INCL = -90.0D; | ||
|
||
/** | ||
* Maximum latitude value. | ||
*/ | ||
public static final double MAX_LAT_INCL = 90.0D; | ||
|
||
// No instance: | ||
private GeoUtils() { | ||
} | ||
|
||
/** | ||
* validates latitude value is within standard +/-90 coordinate bounds | ||
*/ | ||
public 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 | ||
*/ | ||
public 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); | ||
} | ||
} | ||
|
||
} | ||
iverase marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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 org.elasticsearch.geo.GeoUtils; | ||
|
||
/** | ||
* 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"); | ||
} | ||
GeoUtils.checkLatitude(lat); | ||
GeoUtils.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; | ||
} | ||
|
||
} |
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(); | ||
} |
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(); | ||
} | ||
} |
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.