Class InteriorPoint

 1 /*
 2  * Copyright (c) 2016 Martin Davis.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12 package org.locationtech.jts.algorithm;
13  
14 import org.locationtech.jts.geom.Coordinate;
15 import org.locationtech.jts.geom.Geometry;
16 import org.locationtech.jts.geom.GeometryFactory;
17 import org.locationtech.jts.geom.Point;
18  
19 /**
20  * Computes an interior point of a <code>{@link Geometry}</code>.
21  * An interior point is guaranteed to lie in the interior of the Geometry,
22  * if it possible to calculate such a point exactly. 
23  * Otherwise, the point may lie on the boundary of the geometry.
24  * <p>
25  * The interior point of an empty geometry is <code>null</code>.
26  */
27 public class InteriorPoint {
28   
29   /**
30    * Compute a location of an interior point in a {@link Geometry}.
31    * Handles all geometry types.
32    * 
33    * @param geom a geometry in which to find an interior point
34    * @return the location of an interior point, 
35    *  or <code>null</code> if the input is empty
36    */
37   public static Coordinate getInteriorPoint(Geometry geom) {
38     if (geom.isEmpty()) 
39       return null;
40     
41     Coordinate interiorPt = null;
42     int dim = geom.getDimension();
43     if (dim == 0) {
44       interiorPt = InteriorPointPoint.getInteriorPoint(geom);
45     }
46     else if (dim == 1) {
47       interiorPt = InteriorPointLine.getInteriorPoint(geom);
48     }
49     else {
50       interiorPt = InteriorPointArea.getInteriorPoint(geom);
51     }
52     return interiorPt;
53   }
54  
55 }
56