-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Part 1] Add geo support #5654
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
[Part 1] Add geo support #5654
Changes from all commits
5329f2f
e778f61
b4cf2ad
2ac9fe3
d548d24
0ebb9c5
b14d7c5
bb51f43
b3bfad3
0d6285f
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 |
|---|---|---|
|
|
@@ -163,7 +163,10 @@ | |
| <groupId>com.jayway.jsonpath</groupId> | ||
| <artifactId>json-path</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.locationtech.jts</groupId> | ||
|
||
| <artifactId>jts-core</artifactId> | ||
| </dependency> | ||
| <!-- test --> | ||
| <dependency> | ||
| <groupId>org.apache.pinot</groupId> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF 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.apache.pinot.core.geospatial; | ||
|
|
||
| /** | ||
| * The geometry type. | ||
| */ | ||
| public enum GeometryType { | ||
| POINT(false, 0, "ST_Point"), | ||
| MULTI_POINT(true, 1, "ST_MultiPoint"), | ||
| LINE_STRING(false, 2, "ST_LineString"), | ||
| MULTI_LINE_STRING(true, 3, "ST_MultiLineString"), | ||
| POLYGON(false, 4, "ST_Polygon"), | ||
| MULTI_POLYGON(true, 5, "ST_MultiPolygon"), | ||
| GEOMETRY_COLLECTION(true, 6, "ST_GeomCollection"); | ||
|
|
||
| private static final GeometryType[] ID_TO_TYPE_MAP = | ||
| new GeometryType[]{POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON, GEOMETRY_COLLECTION}; | ||
| private final boolean _multiType; | ||
| private final int _id; | ||
| private final String _name; | ||
|
|
||
| GeometryType(boolean multiType, int id, String name) { | ||
| _multiType = multiType; | ||
| _id = id; | ||
| _name = name; | ||
| } | ||
|
|
||
| public boolean isMultiType() { | ||
| return _multiType; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return _name; | ||
| } | ||
|
|
||
| /** | ||
| * @return the id of the serialization type | ||
| */ | ||
| public int id() { | ||
| return _id; | ||
| } | ||
|
|
||
| /** | ||
| * Constructs the serialization type from the id | ||
| * @param id id of the serialization type | ||
| * @return the serialization type | ||
| */ | ||
| public static GeometryType fromID(int id) { | ||
| if (id > ID_TO_TYPE_MAP.length) { | ||
| throw new IllegalArgumentException("Invalid type id: " + id); | ||
| } | ||
| return ID_TO_TYPE_MAP[id]; | ||
| }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF 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.apache.pinot.core.geospatial; | ||
|
|
||
| import com.google.common.base.Joiner; | ||
| import org.locationtech.jts.geom.Geometry; | ||
| import org.locationtech.jts.geom.GeometryFactory; | ||
| import org.locationtech.jts.geom.PrecisionModel; | ||
|
|
||
|
|
||
| /** | ||
| * Utility methods for the geometry. | ||
| */ | ||
| public class GeometryUtils { | ||
| /** | ||
| * Coordinate system of lat/lng per https://epsg.io/4326 | ||
| */ | ||
| public static int GEOGRAPHY_SRID = 4326; | ||
| public static byte GEOGRAPHY_SET_MASK = (byte) 0x80; | ||
| public static byte GEOGRAPHY_GET_MASK = (byte) 0x7f; | ||
| public static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); | ||
| public static final GeometryFactory GEOGRAPHY_FACTORY = new GeometryFactory(new PrecisionModel(), GEOGRAPHY_SRID); | ||
| public static final double EARTH_RADIUS_KM = 6371.01; | ||
| public static final double EARTH_RADIUS_M = EARTH_RADIUS_KM * 1000.0; | ||
| public static final Joiner OR_JOINER = Joiner.on(" or "); | ||
|
|
||
| private GeometryUtils() { | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the given geo-spatial object is a geography object. | ||
| * @param geometry the given object to check | ||
| * @return <code>true</code> if the given geo-spatial object is a geography object, <code>false</code> otherwise | ||
| */ | ||
| public static boolean isGeography(Geometry geometry) { | ||
| return geometry.getSRID() == GEOGRAPHY_SRID; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.