-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SEDONA-265] Migrate all ST functions to Sedona Inferred Expressions (#…
…820)
- Loading branch information
1 parent
1b73ccf
commit 7044c0c
Showing
12 changed files
with
390 additions
and
397 deletions.
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
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
52 changes: 52 additions & 0 deletions
52
common/src/main/java/org/apache/sedona/common/Predicates.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,52 @@ | ||
/** | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.apache.sedona.common; | ||
|
||
import org.locationtech.jts.geom.Geometry; | ||
|
||
public class Predicates { | ||
public static boolean contains(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.contains(rightGeometry); | ||
} | ||
public static boolean intersects(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.intersects(rightGeometry); | ||
} | ||
public static boolean within(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.within(rightGeometry); | ||
} | ||
public static boolean covers(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.covers(rightGeometry); | ||
} | ||
public static boolean coveredBy(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.coveredBy(rightGeometry); | ||
} | ||
public static boolean crosses(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.crosses(rightGeometry); | ||
} | ||
public static boolean overlaps(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.overlaps(rightGeometry); | ||
} | ||
public static boolean touches(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.touches(rightGeometry); | ||
} | ||
public static boolean equals(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.symDifference(rightGeometry).isEmpty(); | ||
} | ||
public static boolean disjoint(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.disjoint(rightGeometry); | ||
} | ||
public static boolean orderingEquals(Geometry leftGeometry, Geometry rightGeometry) { | ||
return leftGeometry.equalsExact(rightGeometry); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
common/src/main/java/org/apache/sedona/common/utils/GeoHashDecoder.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,84 @@ | ||
/** | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.apache.sedona.common.utils; | ||
|
||
import org.locationtech.jts.geom.Geometry; | ||
|
||
public class GeoHashDecoder { | ||
private static final int[] bits = new int[] {16, 8, 4, 2, 1}; | ||
private static final String base32 = "0123456789bcdefghjkmnpqrstuvwxyz"; | ||
|
||
public static class InvalidGeoHashException extends Exception { | ||
public InvalidGeoHashException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
public static Geometry decode(String geohash, Integer precision) throws InvalidGeoHashException { | ||
return decodeGeoHashBBox(geohash, precision).getBbox().toPolygon(); | ||
} | ||
|
||
private static class LatLon { | ||
public Double[] lons; | ||
|
||
public Double[] lats; | ||
|
||
public LatLon(Double[] lons, Double[] lats) { | ||
this.lons = lons; | ||
this.lats = lats; | ||
} | ||
|
||
BBox getBbox() { | ||
return new BBox( | ||
lons[0], | ||
lons[1], | ||
lats[0], | ||
lats[1] | ||
); | ||
} | ||
} | ||
|
||
private static LatLon decodeGeoHashBBox(String geohash, Integer precision) throws InvalidGeoHashException { | ||
LatLon latLon = new LatLon(new Double[] {-180.0, 180.0}, new Double[] {-90.0, 90.0}); | ||
String geoHashLowered = geohash.toLowerCase(); | ||
int geoHashLength = geohash.length(); | ||
int targetPrecision = geoHashLength; | ||
if (precision != null) { | ||
if (precision < 0) throw new InvalidGeoHashException("Precision can not be negative"); | ||
else targetPrecision = Math.min(geoHashLength, precision); | ||
} | ||
boolean isEven = true; | ||
|
||
for (int i = 0; i < targetPrecision ; i++){ | ||
char c = geoHashLowered.charAt(i); | ||
byte cd = (byte) base32.indexOf(c); | ||
if (cd == -1){ | ||
throw new InvalidGeoHashException(String.format("Invalid character '%s' found at index %d", c, i)); | ||
} | ||
for (int j = 0;j < 5; j++){ | ||
byte mask = (byte) bits[j]; | ||
int index = (mask & cd) == 0 ? 1 : 0; | ||
if (isEven){ | ||
latLon.lons[index] = (latLon.lons[0] + latLon.lons[1]) / 2; | ||
} | ||
else { | ||
latLon.lats[index] = (latLon.lats[0] + latLon.lats[1]) / 2; | ||
} | ||
isEven = !isEven; | ||
} | ||
} | ||
return latLon; | ||
} | ||
|
||
} |
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
Oops, something went wrong.