| 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.Geometry; |
| 19 |
import org.locationtech.jts.geom.GeometryCollection; |
| 20 |
import org.locationtech.jts.geom.GeometryFactory; |
| 21 |
import org.locationtech.jts.geom.util.GeometryMapper.MapOp; |
| 22 |
|
| 23 |
/** |
| 24 |
* Maps the members of a {@link GeometryCollection} |
| 25 |
* into another <tt>GeometryCollection</tt> via a defined |
| 26 |
* mapping function. |
| 27 |
* |
| 28 |
* @author Martin Davis |
| 29 |
* |
| 30 |
*/ |
| 31 |
public class GeometryCollectionMapper |
| 32 |
{ |
| 33 |
public static GeometryCollection map(GeometryCollection gc, MapOp op) |
| 34 |
{ |
| 35 |
GeometryCollectionMapper mapper = new GeometryCollectionMapper(op); |
| 36 |
return mapper.map(gc); |
| 37 |
} |
| 38 |
|
| 39 |
private MapOp mapOp = null; |
| 40 |
|
| 41 |
public GeometryCollectionMapper(MapOp mapOp) { |
| 42 |
this.mapOp = mapOp; |
| 43 |
} |
| 44 |
|
| 45 |
public GeometryCollection map(GeometryCollection gc) |
| 46 |
{ |
| 47 |
List mapped = new ArrayList(); |
| 48 |
for (int i = 0; i < gc.getNumGeometries(); i++) { |
| 49 |
Geometry g = mapOp.map(gc.getGeometryN(i)); |
| 50 |
if (!g.isEmpty()) |
| 51 |
mapped.add(g); |
| 52 |
} |
| 53 |
return gc.getFactory().createGeometryCollection( |
| 54 |
GeometryFactory.toGeometryArray(mapped)); |
| 55 |
} |
| 56 |
} |
| 57 |
|