use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.
the class ShapefileInstanceWriter method traverseInstanceForGeometries.
/**
* Method to traverse instance to find geometries.
*
* @param instance instance.
* @return list of geometries.
*/
private List<GeometryProperty<?>> traverseInstanceForGeometries(Instance instance) {
// find geometries in the schema.
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(null);
traverser.traverse(instance, geoFind);
List<GeometryProperty<?>> geoms = geoFind.getGeometries();
return geoms;
}
use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.
the class GenericGeometryHandler method createGeometry.
/**
* @see GeometryHandler#createGeometry(Instance, int, IOProvider)
*/
@Override
public Collection<GeometryProperty<?>> createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
CRSDefinition defaultCrsDef = GMLGeometryUtil.findCRS(instance);
// depth first traverser that on cancel continues traversal but w/o the
// children of the current object
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(defaultCrsDef);
traverser.traverse(instance, geoFind);
return createGeometry(instance, geoFind.getGeometries(), defaultCrsDef, reader);
}
use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.
the class CalculateArea method evaluate.
/**
* @see eu.esdihumboldt.hale.common.align.transformation.function.impl.AbstractSingleTargetPropertyTransformation#evaluate(java.lang.String,
* eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
* com.google.common.collect.ListMultimap, java.lang.String,
* eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition,
* java.util.Map,
* eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
*/
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
// get input geometry
PropertyValue input = variables.get(null).get(0);
Object inputValue = input.getValue();
// depth first traverser that on cancel continues traversal but w/o the
// children of the current object
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(null);
traverser.traverse(inputValue, geoFind);
List<GeometryProperty<?>> geoms = geoFind.getGeometries();
Geometry geom = null;
if (geoms.size() > 1) {
int area = 0;
for (GeometryProperty<?> geoProp : geoms) {
area += geoProp.getGeometry().getArea();
}
return area;
} else {
geom = geoms.get(0).getGeometry();
}
if (geom != null) {
return geom.getArea();
} else {
throw new TransformationException("Geometry for calculate area could not be retrieved.");
}
}
use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.
the class NetworkExpansion method calculateBuffer.
/**
* Calculate a buffer geometry.
*
* @param geometryHolder the geometry or object holding a geometry
* @param bufferWidth the buffer width
* @param log the transformation log, may be <code>null</code>
* @return the buffer geometry or <code>null</code>
*/
@Nullable
public static GeometryProperty<Geometry> calculateBuffer(Object geometryHolder, double bufferWidth, @Nullable TransformationLog log) {
// find contained geometries
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(null);
traverser.traverse(geometryHolder, geoFind);
List<GeometryProperty<?>> geometries = geoFind.getGeometries();
GeometryProperty<?> old_geometry = null;
if (!geometries.isEmpty()) {
old_geometry = geometries.get(0);
if (geometries.size() > 1) {
if (log != null) {
log.warn(log.createMessage("Multiple geometries found, but network expansion is only done on the first.", null));
}
}
}
GeometryProperty<Geometry> result = null;
if (old_geometry != null) {
Geometry new_geometry = null;
BufferParameters bufferParameters = new BufferParameters();
bufferParameters.setEndCapStyle(CAP_STYLE);
new_geometry = BufferOp.bufferOp(old_geometry.getGeometry(), bufferWidth, bufferParameters);
result = new DefaultGeometryProperty<Geometry>(old_geometry.getCRSDefinition(), new_geometry);
}
return result;
}
use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.
the class Centroid method calculateCentroid.
/**
* Calculate the centroid for a given geometry or object holding a geometry.
*
* @param geometryHolder {@link Geometry}, {@link GeometryProperty} or
* {@link Instance} holding a geometry
* @return the centroid of the geometry
* @throws TransformationException if the no geometry could be extracted
* from the input
*/
public static GeometryProperty<?> calculateCentroid(Object geometryHolder) throws TransformationException {
// depth first traverser that on cancel continues traversal but w/o the
// children of the current object
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(null);
traverser.traverse(geometryHolder, geoFind);
List<GeometryProperty<?>> geoms = geoFind.getGeometries();
Geometry result;
CRSDefinition oldCRS = null;
if (geoms.size() > 1) {
// multiple geometries -> create a multi point
// XXX is this the desired behavior?
Point[] centroids = new Point[geoms.size()];
GeometryFactory geomFactory = new GeometryFactory();
for (int i = 0; i < geoms.size(); i++) {
GeometryProperty<?> prop = geoms.get(i);
centroids[i] = prop.getGeometry().getCentroid();
if (oldCRS == null) {
// assume the same CRS for all points
oldCRS = prop.getCRSDefinition();
}
}
result = geomFactory.createMultiPoint(centroids);
} else {
Geometry geom = geoms.get(0).getGeometry();
oldCRS = geoms.get(0).getCRSDefinition();
if (geom != null) {
result = geom.getCentroid();
} else {
throw new TransformationException("Geometry for centroid could not be retrieved.");
}
}
return new DefaultGeometryProperty<Geometry>(oldCRS, result);
}
Aggregations