Returns a new geometry based on an existing one, with a specific point as
a new vertex. A default distance 10E-6 is used to snap the input point.

@param geometry
@param point
@return
@throws SQLException
345717
public static Geometry addPoint(Geometry geometry, Point point) throws SQLException {
        return addPoint(geometry, point, PRECISION);
    }
1365925
public void geometryUpdate(Geometry oldGeometry, Geometry newGeometry) {
		if (oldGeometry != null) {
			geometries.remove(oldGeometry);
		}
		if (newGeometry != null) {
			geometries.add(newGeometry);
		}

		if (geometries.size() == 0) {
			searchGeometry = null;
			updateGeometryOnMap();

		} else if (geometries.size() == 1) {
			searchGeometry = geometries.get(0);
			updateGeometryOnMap();

		} else {
			 SearchCommService.mergeGeometries(geometries, new DataCallback<Geometry>() {
				public void execute(Geometry result) {
					searchGeometry = result;
					updateGeometryOnMap();
				}
			});
		}
	}
1075831
public static Point projectPoint(Geometry point, Geometry geometry) {
        if (point == null || geometry==null) {
            return null;
        }
        if (point.getDimension()==0 && geometry.getDimension() == 1) {
            LengthIndexedLine ll = new LengthIndexedLine(geometry);
            double index = ll.project(point.getCoordinate());
            return geometry.getFactory().createPoint(ll.extractPoint(index));
        } else {
            return null;
        }
    }
1201294
private static Geometry insertVertexInMultipoint(Geometry g, Point vertexPoint) {
        ArrayList<Point> geoms = new ArrayList<Point>();
        for (int i = 0; i < g.getNumGeometries(); i++) {
            Point geom = (Point) g.getGeometryN(i);
            geoms.add(geom);
        }
        geoms.add(FACTORY.createPoint(new Coordinate(vertexPoint.getX(), vertexPoint.getY())));
        return FACTORY.createMultiPoint(GeometryFactory.toPointArray(geoms));
    }
735917
private Point translate(Point point) {
		Coordinate c = point.getCoordinate();
		return point.getGeometryFactory().createPoint(new Coordinate(c.getX() + translateX, c.getY() + translateY));
	}
785202
function(geometry) {
            var gml = this.createElementNS(this.gmlns, "gml:MultiPoint");
            var points = geometry.components;
            var pointMember, pointGeom;
            for(var i=0; i<points.length; i++) { 
                pointMember = this.createElementNS(this.gmlns,
                                                   "gml:pointMember");
                pointGeom = this.buildGeometry.point.apply(this,
                                                               [points[i]]);
                pointMember.appendChild(pointGeom);
                gml.appendChild(pointMember);
            }
            return gml;            
        }
1099109
public static LineString createLine(Geometry pointA, Geometry... optionalPoints) throws SQLException {
        if( pointA == null || optionalPoints.length > 0 && optionalPoints[0] == null) {
            return null;
        }
        if (pointA.getNumGeometries() == 1 && !atLeastTwoPoints(optionalPoints, countPoints(pointA))) {
            throw new SQLException("At least two points are required to make a line.");
        }
        List<Coordinate> coordinateList = new LinkedList<Coordinate>();
        addCoordinatesToList(pointA, coordinateList);
        for (Geometry optionalPoint : optionalPoints) {
            addCoordinatesToList(optionalPoint, coordinateList);
        }
        return ((Geometry) pointA).getFactory().createLineString(
                coordinateList.toArray(new Coordinate[optionalPoints.length]));
    }
800400
public static void toKMLGeometry(Geometry geometry, ExtrudeMode extrude, int altitudeModeEnum, StringBuilder sb) throws SQLException {
        if (geometry instanceof Point) {
            toKMLPoint((Point) geometry, extrude, altitudeModeEnum, sb);
        } else if (geometry instanceof LineString) {
            toKMLLineString((LineString) geometry, extrude, altitudeModeEnum, sb);
        } else if (geometry instanceof Polygon) {
            toKMLPolygon((Polygon) geometry, extrude, altitudeModeEnum, sb);
        } else if (geometry instanceof GeometryCollection) {
            toKMLMultiGeometry((GeometryCollection) geometry, extrude, altitudeModeEnum, sb);
        } else {
            throw new SQLException("This geometry type is not supported : " + geometry.toString());
        }
    }
922074
private static String getFirstGeometryField(String tableName, Connection connection) throws SQLException {
        // Find first geometry column
        List<String> geomFields = SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())));
        if (!geomFields.isEmpty()) {
            return geomFields.get(0);
        } else {
            throw new SQLException("The table " + tableName + " does not contain a geometry field");
        }
    }
313652
@SuppressWarnings("unchecked")
    public GoogleMapShape toShape(Geometry geometry) {

        GoogleMapShape shape = null;

        GeometryType geometryType = geometry.getGeometryType();
        switch (geometryType) {
            case POINT:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.LAT_LNG, toLatLng((Point) geometry));
                break;
            case LINESTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYLINE_OPTIONS,
                        toPolyline((LineString) geometry));
                break;
            case POLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toPolygon((Polygon) geometry));
                break;
            case MULTIPOINT:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_LAT_LNG,
                        toLatLngs((MultiPoint) geometry));
                break;
            case MULTILINESTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYLINE_OPTIONS,
                        toPolylines((MultiLineString) geometry));
                break;
            case MULTIPOLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((MultiPolygon) geometry));
                break;
            case CIRCULARSTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYLINE_OPTIONS,
                        toPolyline((CircularString) geometry));
                break;
            case COMPOUNDCURVE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYLINE_OPTIONS,
                        toPolylines((CompoundCurve) geometry));
                break;
            case CURVEPOLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toCurvePolygon((CurvePolygon) geometry));
                break;
            case POLYHEDRALSURFACE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((PolyhedralSurface) geometry));
                break;
            case TIN:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((TIN) geometry));
                break;
            case TRIANGLE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toPolygon((Triangle) geometry));
                break;
            case GEOMETRYCOLLECTION:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.COLLECTION,
                        toShapes((GeometryCollection<Geometry>) geometry));
                break;
            default:
                throw new GeoPackageException("Unsupported Geometry Type: "
                        + geometryType.getName());
        }

        return shape;
    }
1199647
public void insertGeometry( String tableName, Geometry geometry, String epsg ) throws Exception {
        String epsgStr = "4326";
        if (epsg == null) {
            epsgStr = epsg;
        }

        GeometryColumn gc = getGeometryColumnsForTable(tableName);
        String sql = "INSERT INTO " + tableName + " (" + gc.geometryColumnName + ") VALUES (ST_GeomFromText(?, " + epsgStr + "))";

        execOnConnection(connection -> {
            try (IHMPreparedStatement pStmt = connection.prepareStatement(sql)) {
                pStmt.setString(1, geometry.toText());
                pStmt.executeUpdate();
            }
            return null;
        });

    }
1335040
private static boolean intersectsPoint(Geometry point, Geometry geometry) {
		if (geometry.getGeometries() != null) {
			for (Geometry child : geometry.getGeometries()) {
				if (intersectsPoint(point, child)) {
					return true;
				}
			}
		}
		if (geometry.getCoordinates() != null) {
			Coordinate coordinate = point.getCoordinates()[0];
			if (geometry.getCoordinates().length == 1) {
				return coordinate.equals(geometry.getCoordinates()[0]);
			} else {
				for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
					double distance = MathService.distance(geometry.getCoordinates()[i],
							geometry.getCoordinates()[i + 1], coordinate);
					if (distance < DEFAULT_DOUBLE_DELTA) {
						return true;
					}
				}
			}
		}
		return false;
	}
719900
public static Geometry rotate(Geometry geom, double theta, Point point) {
        return rotate(geom, theta, point.getX(), point.getY());
    }
43158
private void addGeometry(Geometry geom) throws IllegalArgumentException {
        if(!geom.isValid()) {
            throw new IllegalArgumentException("Provided geometry is not valid !");
        }
        if(geom instanceof GeometryCollection) {
            Map<TriangulationPoint, Integer> pts = new HashMap<TriangulationPoint, Integer>(geom.getNumPoints());
            List<Integer> segments = new ArrayList<Integer>(pts.size());
            AtomicInteger pointsCount = new AtomicInteger(0);
            PointHandler pointHandler = new PointHandler(this, pts, pointsCount);
            LineStringHandler lineStringHandler = new LineStringHandler(this, pts, pointsCount, segments);
            for(int geomId = 0; geomId < geom.getNumGeometries(); geomId++) {
                addSimpleGeometry(geom.getGeometryN(geomId), pointHandler, lineStringHandler);
            }
            int[] index = new int[segments.size()];
            for(int i = 0; i < index.length; i++) {
                index[i] = segments.get(i);
            }
            // Construct final points array by reversing key,value of hash map
            TriangulationPoint[] ptsArray = new TriangulationPoint[pointsCount.get()];
            for(Map.Entry<TriangulationPoint, Integer> entry : pts.entrySet()) {
                ptsArray[entry.getValue()] = entry.getKey();
            }
            pts.clear();
            convertedInput = new ConstrainedPointSet(Arrays.asList(ptsArray), index);
        } else {
            addGeometry(geom.getFactory().createGeometryCollection(new Geometry[]{geom}));
        }
    }
441017
public static Geometry updateZ(Geometry geometry, double z, int updateCondition) throws SQLException {
        if(geometry == null){
            return null;
        }
        if (updateCondition == 1 || updateCondition == 2 || updateCondition == 3) {
            Geometry outPut = geometry.copy();
            outPut.apply(new UpdateZCoordinateSequenceFilter(z, updateCondition));
            return outPut;
        } else {
            throw new SQLException("Available values are 1, 2 or 3.\n"
                    + "Please read the description of the function to use it.");
        }
    }
529657
int addGeometry(Geometry geometry) {
		Geometry.Type gt = geometry.getType();
		if (Geometry.isMultiPath(gt.value()))
			return addMultiPath_((MultiPath) geometry);
		if (gt == Geometry.Type.MultiPoint)
			return addMultiPoint_((MultiPoint) geometry);

		throw GeometryException.GeometryInternalError();
	}
140104
private static void getPunctualGeometry(ArrayList<Point> points, Geometry geometry) {
         for (int i = 0; i < geometry.getNumGeometries(); i++) {
            Geometry subGeom = geometry.getGeometryN(i);
            if(subGeom instanceof Point){
                points.add((Point) subGeom);
            }
            else if (subGeom instanceof GeometryCollection){
                getPunctualGeometry(points, subGeom);
            }
        }
    }