use of com.revolsys.geometry.model.impl.GeometryCollectionImpl in project com.revolsys.open by revolsys.
the class GeometryFactory method geometryCollection.
/**
* Does not flattern nested geometry collections.
*
* @param geometries
* @return
*/
@SuppressWarnings("unchecked")
public <G extends Geometry> G geometryCollection(final Iterable<? extends Geometry> geometries) {
if (geometries == null) {
return (G) geometryCollection();
} else {
DataType dataType = null;
boolean heterogeneous = false;
final List<Geometry> geometryList = new ArrayList<>();
if (geometries != null) {
for (final Geometry geometry : geometries) {
if (geometry != null) {
if (heterogeneous) {
} else {
final DataType geometryDataType = geometry.getDataType();
if (dataType == null) {
dataType = geometryDataType;
} else if (dataType != geometryDataType) {
heterogeneous = true;
dataType = null;
}
}
final Geometry copy = geometry.newGeometry(this);
geometryList.add(copy);
}
}
}
if (geometryList.size() == 0) {
return (G) geometryCollection();
} else if (geometryList.size() == 1) {
return (G) geometryList.get(0);
} else if (dataType == DataTypes.POINT) {
return (G) punctual(geometryList);
} else if (dataType == DataTypes.LINE_STRING) {
return (G) lineal(geometryList);
} else if (dataType == DataTypes.POLYGON) {
return (G) polygonal(geometryList);
} else {
final Geometry[] geometryArray = new Geometry[geometryList.size()];
geometryList.toArray(geometryArray);
return (G) new GeometryCollectionImpl(this, geometryArray);
}
}
}
Aggregations