MarvinLitt commented on a change in pull request #3481: [CARBONDATA-3548]Geospatial Support: add hash id create,query condition analyze and generate hash id list
URL: https://github.com/apache/carbondata/pull/3481#discussion_r357042799 ########## File path: geo/src/main/java/org/apache/carbondata/geo/QuadTreeCls.java ########## @@ -0,0 +1,904 @@ +/* + * 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.carbondata.geo; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.apache.carbondata.common.logging.LogServiceFactory; + +import org.apache.log4j.Logger; + +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.Polygon; + + + +/** + * Spatial region function processing related classes + */ +class GeometryOperation { + private static final GeometryFactory geoFactory = new GeometryFactory(); + + /** + * Convert point object to polygon object in Geo + * + * @param polygon Area coordinates stored as a list + * @return JTS Polygon objects + */ + public static Polygon getPolygonByPointList(List<Point2D.Double> polygon) { + int size = polygon.size(); + if (size < 3) { + return null; + } else { + Coordinate[] rect = new Coordinate[size + 1]; + for (int i = 0; i < size; i++) { + rect[i] = new Coordinate(polygon.get(i).x, polygon.get(i).y); + } + rect[size] = new Coordinate(polygon.get(0).x, polygon.get(0).y); + return geoFactory.createPolygon(rect); + } + } + + /** + * Convert point object to polygon object in Geo + * @param polygon Area coordinates stored as a list + * @return JTS Polygon objects + */ + public static Polygon getPolygonByDoubleList(List<double[]> polygon) { + int size = polygon.size(); + if (size < 3) { + return null; + } else { + Coordinate[] rect = new Coordinate[size + 1]; + for (int i = 0; i < size; i++) { + rect[i] = new Coordinate(polygon.get(i)[0], polygon.get(i)[1]); + } + double x = polygon.get(0)[0]; + double y = polygon.get(0)[1]; + rect[size] = new Coordinate(x, y); + return geoFactory.createPolygon(rect); + } + } + + /** + * Converting point objects to point objects in Geo + * @param pointB Point2D Point object + * @return JTS Point object + */ + public static Point getPointByPoint2D(Point2D.Double pointB) { + Coordinate point = new Coordinate(pointB.x, pointB.y); + return geoFactory.createPoint(point); + } + + + /** + * Apart a and B do not intersect, a and B are polygons + * @param polygonA polygon + * @param polygonB polygon + * @return true Polygons apart,false Polygons are inseparable + */ + public static boolean disjoint(Geometry polygonA, List<Point2D.Double> polygonB) { + Polygon polyB = getPolygonByPointList(polygonB); + boolean result = polygonA.disjoint(polyB); + return result; + } + + /** + * A and B do not intersect each other, A is a polygon, B is a point + * @param polygonA polygon + * @param pointB point + * @return true Point away from polygon,false Points are inseparable from polygons + */ + public static boolean disjoint(Geometry polygonA, Point2D.Double pointB) { + Point pointGeo = getPointByPoint2D(pointB); + boolean result = polygonA.disjoint(pointGeo); + return result; + } + + /** + * contains - A contains B Compare polygon a with polygon B + * @param polygonA polygon + * @param polygonB polygon + * @return 0 Polygon a contains polygon B (a = B or a > b), + * -1 Polygon a does not contain polygon B + */ + public static boolean contains(Geometry polygonA, List<Point2D.Double> polygonB) { + Polygon polyB = getPolygonByPointList(polygonB); + return polygonA.contains(polyB); + } + + + /** + * contains - A contains B Compare whether polygon a contains B + * @param polygonA polygon + * @param pointB point + * @return true Polygon a contains point B (B in a), false Polygon a does not contain point B + */ + public static boolean contains(Geometry polygonA, Point2D.Double pointB) { + Point pointGeo = getPointByPoint2D(pointB); + boolean result = polygonA.contains(pointGeo); + return result; + } + + /** + * intersect - A intersects B Indicates that polygon a intersects polygon B + * @param polygonA polygon + * @param polygonB polygon + * @return true Polygon a intersects polygon B,false Polygon a does not intersect polygon B + */ + public static boolean intersects(Geometry polygonA, List<Point2D.Double> polygonB) { + Polygon polyB = getPolygonByPointList(polygonB); + boolean result = polygonA.intersects(polyB); + return result; + } + + /** + * intersect - A intersects B Represents the intersection of polygon A and point B + * @param polygonA polygon + * @param pointB point + * @return true Polygon a intersects point B,false Polygon a does not intersect point B + */ + public static boolean intersects(Geometry polygonA, Point2D.Double pointB) { + Point pointGeo = getPointByPoint2D(pointB); + boolean result = polygonA.intersects(pointGeo); + return result; + } +} + + +/** + * Polygon region object + */ +class QuadRect { + public Double left; + public Double top; + public Double right; + public Double bottom; + /** + * build func + * @param topleft Left upper point + * @param bottomRight Right lower point + */ + public QuadRect(Point2D.Double topleft, Point2D.Double bottomRight) { + this.left = topleft.x; + this.top = topleft.y; + this.right = bottomRight.x; + this.bottom = bottomRight.y; + } + + /** + * build func + * @param x Leftmost coordinates + * @param y Bottom coordinate + * @param x2 Rightmost coordinate + * @param y2 Top coordinate + */ + public QuadRect(double x, double y, double x2, double y2) { + this.left = x; + this.bottom = y; + this.right = x2; + this.top = y2; + } + + /** + * The given area is outside the current node area + * @param polygonRect If the circumscribed rectangle of a given region is larger than + * the coordinate with the node, it means it is outside the whole region + * @return true The given area is outside the point,false The given area is within the point area + */ + public boolean outsideBox(QuadRect polygonRect) { + return polygonRect.left < this.left || polygonRect.right > this.right || + polygonRect.top > this.top || polygonRect.bottom < this.bottom; + + } + + /** + * Get the polygon list of this area. The point is the rectangle of the inner center point of + * the grid area center point. If it is the smallest grid, it is the coordinate of the + * peripheral point + * @return 矩形区域的顶点列表 + */ + public List<Point2D.Double> getPolygonPointList() { + Point2D.Double topLeft = new Point2D.Double(this.left, this.top); Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |