| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 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 |
|