| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.geom.util; |
| 14 |
|
| 15 |
import java.util.ArrayList; |
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.locationtech.jts.geom.Coordinate; |
| 19 |
import org.locationtech.jts.geom.Geometry; |
| 20 |
import org.locationtech.jts.geom.GeometryComponentFilter; |
| 21 |
import org.locationtech.jts.geom.LineString; |
| 22 |
import org.locationtech.jts.geom.Point; |
| 23 |
|
| 24 |
/** |
| 25 |
* Extracts a representative {@link Coordinate} |
| 26 |
* from each connected component of a {@link Geometry}. |
| 27 |
* |
| 28 |
* @version 1.9 |
| 29 |
*/ |
| 30 |
public class ComponentCoordinateExtracter |
| 31 |
implements GeometryComponentFilter |
| 32 |
{ |
| 33 |
|
| 34 |
/** |
| 35 |
* Extracts a representative {@link Coordinate} |
| 36 |
* from each connected component in a geometry. |
| 37 |
* <p> |
| 38 |
* If more than one geometry is to be processed, it is more |
| 39 |
* efficient to create a single {@link ComponentCoordinateExtracter} instance |
| 40 |
* and pass it to each geometry. |
| 41 |
* |
| 42 |
* @param geom the Geometry from which to extract |
| 43 |
* @return a list of representative Coordinates |
| 44 |
*/ |
| 45 |
public static List getCoordinates(Geometry geom) |
| 46 |
{ |
| 47 |
List coords = new ArrayList(); |
| 48 |
geom.apply(new ComponentCoordinateExtracter(coords)); |
| 49 |
return coords; |
| 50 |
} |
| 51 |
|
| 52 |
private List coords; |
| 53 |
|
| 54 |
/** |
| 55 |
* Constructs a LineExtracterFilter with a list in which to store LineStrings found. |
| 56 |
*/ |
| 57 |
public ComponentCoordinateExtracter(List coords) |
| 58 |
{ |
| 59 |
this.coords = coords; |
| 60 |
} |
| 61 |
|
| 62 |
public void filter(Geometry geom) |
| 63 |
{ |
| 64 |
|
| 65 |
if (geom instanceof LineString |
| 66 |
|| geom instanceof Point) |
| 67 |
coords.add(geom.getCoordinate()); |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|