use of org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor in project hortonmachine by TheHortonMachine.
the class OmsLineSmootherMcMaster method process.
@Execute
public void process() throws Exception {
if (!concatOr(outVector == null, doReset)) {
return;
}
if (pDensify != null) {
densify = pDensify;
}
if (pSimplify != null) {
simplify = pSimplify;
}
outVector = new DefaultFeatureCollection();
pm.message("Collecting geometries...");
linesList = FeatureUtilities.featureCollectionToList(inVector);
int size = inVector.size();
FeatureGeometrySubstitutor fGS = new FeatureGeometrySubstitutor(inVector.getSchema());
pm.beginTask("Smoothing features...", size);
for (SimpleFeature line : linesList) {
Geometry geometry = (Geometry) line.getDefaultGeometry();
List<LineString> lsList = smoothGeometries(geometry);
if (lsList.size() != 0) {
LineString[] lsArray = (LineString[]) lsList.toArray(new LineString[lsList.size()]);
MultiLineString multiLineString = gF.createMultiLineString(lsArray);
SimpleFeature newFeature = fGS.substituteGeometry(line, multiLineString);
((DefaultFeatureCollection) outVector).add(newFeature);
}
pm.worked(1);
}
pm.done();
}
use of org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor in project hortonmachine by TheHortonMachine.
the class OmsPolygonSmootherJaitools method process.
@Execute
public void process() throws Exception {
if (!concatOr(outVector == null, doReset)) {
return;
}
outVector = new DefaultFeatureCollection();
pm.message("Collecting geometries...");
List<SimpleFeature> polygonsList = FeatureUtilities.featureCollectionToList(inVector);
int size = inVector.size();
FeatureGeometrySubstitutor fGS = new FeatureGeometrySubstitutor(inVector.getSchema());
pm.beginTask("Smoothing features...", size);
PolygonSmoother smoother = new PolygonSmoother(gF);
for (SimpleFeature polygonsFeature : polygonsList) {
Geometry geometry = (Geometry) polygonsFeature.getDefaultGeometry();
int numGeometries = geometry.getNumGeometries();
List<Polygon> smoothedList = new ArrayList<Polygon>();
for (int i = 0; i < numGeometries; i++) {
Geometry geometryN = geometry.getGeometryN(i);
if (geometryN instanceof Polygon) {
Polygon polygon = (Polygon) geometryN;
Polygon smoothed = smoother.smooth(polygon, pAlpha);
smoothedList.add(smoothed);
}
}
if (smoothedList.size() != 0) {
Polygon[] lsArray = (Polygon[]) smoothedList.toArray(new Polygon[smoothedList.size()]);
MultiPolygon multiPolygonString = gF.createMultiPolygon(lsArray);
SimpleFeature newFeature = fGS.substituteGeometry(polygonsFeature, multiPolygonString);
((DefaultFeatureCollection) outVector).add(newFeature);
}
pm.worked(1);
}
pm.done();
}
use of org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor in project hortonmachine by TheHortonMachine.
the class OmsBuffer method process.
@Execute
public void process() throws Exception {
checkNull(inMap);
int joinStyle;
if (pJoinstyle.equals(JOIN_MITRE)) {
joinStyle = BufferParameters.JOIN_MITRE;
} else if (pJoinstyle.equals(JOIN_BEVEL)) {
joinStyle = BufferParameters.JOIN_BEVEL;
} else {
joinStyle = BufferParameters.JOIN_ROUND;
}
int endCapStyle;
if (pCapstyle.equals(CAP_FLAT)) {
endCapStyle = BufferParameters.CAP_FLAT;
} else if (pCapstyle.equals(CAP_SQUARE)) {
endCapStyle = BufferParameters.CAP_SQUARE;
} else {
endCapStyle = BufferParameters.CAP_ROUND;
}
FeatureGeometrySubstitutor fgs = new FeatureGeometrySubstitutor(inMap.getSchema(), MultiPolygon.class);
DefaultFeatureCollection outMaptmp = new DefaultFeatureCollection("new", fgs.getNewFeatureType());
GeometryFactory gf = GeometryUtilities.gf();
List<SimpleFeature> featuresList = FeatureUtilities.featureCollectionToList(inMap);
pm.beginTask("Buffering geometries...", featuresList.size());
for (SimpleFeature feature : featuresList) {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
double buf = pBuffer;
if (pBufferField != null) {
Object bFieldObj = feature.getAttribute(pBufferField);
if (bFieldObj instanceof Number) {
buf = ((Number) bFieldObj).doubleValue();
}
}
BufferParameters bP = new BufferParameters(quadrantSegments, endCapStyle, joinStyle, mitreLimit);
Geometry bufferedGeom = BufferOp.bufferOp(geometry, buf, bP);
List<Polygon> polygons = new ArrayList<Polygon>(bufferedGeom.getNumGeometries());
for (int i = 0; i < bufferedGeom.getNumGeometries(); i++) {
Geometry geometryN = bufferedGeom.getGeometryN(i);
if (geometryN instanceof Polygon) {
polygons.add((Polygon) geometryN);
} else {
pm.errorMessage("Ignored non polygonal geometry in: " + geometryN.toText());
}
}
MultiPolygon multiPolygon = gf.createMultiPolygon(polygons.toArray(GeometryUtilities.TYPE_POLYGON));
SimpleFeature newFeature = fgs.substituteGeometry(feature, multiPolygon);
outMaptmp.add(newFeature);
pm.worked(1);
}
pm.done();
outMap = outMaptmp;
}
use of org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor in project hortonmachine by TheHortonMachine.
the class OmsVectorIntersector method process.
// END VARS DOC
@Execute
public void process() throws Exception {
checkNull(inMap1, inMap2);
outMap = new DefaultFeatureCollection();
if (!doKeepFirstAttributes) {
SimpleFeatureCollection inMapTmp = inMap1;
inMap1 = inMap2;
inMap2 = inMapTmp;
}
List<Geometry> geometries = FeatureUtilities.featureCollectionToGeometriesList(inMap2, false, null);
GeometryCollection geometryCollection = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), gf);
Geometry intersectionGeometry = geometryCollection.buffer(0);
PreparedGeometry preparedIntersectionGeometry = PreparedGeometryFactory.prepare(intersectionGeometry);
List<SimpleFeature> mainFeatures = FeatureUtilities.featureCollectionToList(inMap1);
if (mainFeatures.size() == 0) {
throw new ModelsIllegalargumentException("No features found in the layer.", this);
}
EGeometryType geometryType = EGeometryType.forGeometry((Geometry) mainFeatures.get(0).getDefaultGeometry());
Class<?> multiClazz = geometryType.getMultiClazz();
EGeometryType newGeometryType = EGeometryType.forClass(multiClazz);
FeatureGeometrySubstitutor sub = new FeatureGeometrySubstitutor(inMap1.getSchema(), multiClazz);
pm.beginTask("Performing intersection...", mainFeatures.size());
for (SimpleFeature feature : mainFeatures) {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (preparedIntersectionGeometry.intersects(geometry)) {
Geometry intersection = geometry.intersection(intersectionGeometry);
EGeometryType intersectionGeometryType = EGeometryType.forGeometry(intersection);
if (intersectionGeometryType.isCompatibleWith(newGeometryType)) {
SimpleFeature newFeature = sub.substituteGeometry(feature, intersection);
((DefaultFeatureCollection) outMap).add(newFeature);
} else {
pm.errorMessage("Could not add intersection result geometry to layer due to incompatibility: " + intersection);
}
}
pm.worked(1);
}
pm.done();
}
use of org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor in project hortonmachine by TheHortonMachine.
the class OmsVectorSimplifier method process.
// PARAM DESC END
@Execute
public void process() throws Exception {
if (!concatOr(outVector == null, doReset)) {
return;
}
FeatureIterator<SimpleFeature> inFeatureIterator = inVector.features();
outVector = new DefaultFeatureCollection();
FeatureGeometrySubstitutor fGS = new FeatureGeometrySubstitutor(inVector.getSchema());
GeometryPrecisionReducer geometryReducer = null;
int size = inVector.size();
pm.beginTask("Simplifing features...", size);
while (inFeatureIterator.hasNext()) {
SimpleFeature feature = inFeatureIterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
List<Geometry> geomList = new ArrayList<Geometry>();
int numGeometries = geometry.getNumGeometries();
for (int i = 0; i < numGeometries; i++) {
Geometry geometryN = geometry.getGeometryN(i);
switch(pType) {
case TOPOLOGYPRESERVINGSIMPLIFIER:
TopologyPreservingSimplifier tpSimplifier = new TopologyPreservingSimplifier(geometryN);
tpSimplifier.setDistanceTolerance(pTolerance);
Geometry tpsGeometry = tpSimplifier.getResultGeometry();
geomList.add(tpsGeometry);
break;
case DOUGLAS_PEUCKER:
DouglasPeuckerSimplifier dpSimplifier = new DouglasPeuckerSimplifier(geometryN);
dpSimplifier.setDistanceTolerance(pTolerance);
Geometry dpsGeometry = dpSimplifier.getResultGeometry();
geomList.add(dpsGeometry);
break;
case PRECISION_REDUCER:
if (geometryReducer == null) {
if (pScale == null) {
throw new ModelsIllegalargumentException("To reduce the precision the scale parameter needs to be set.", this);
}
geometryReducer = new GeometryPrecisionReducer(new PrecisionModel(pScale));
}
geomList.add(geometryReducer.reduce(geometryN));
default:
}
}
Geometry newGeometry = null;
if (geomList.size() == 1) {
newGeometry = geomList.get(0);
} else {
Geometry[] geomArray = (Geometry[]) geomList.toArray(new Geometry[geomList.size()]);
newGeometry = new GeometryCollection(geomArray, gf);
}
SimpleFeature newFeature = fGS.substituteGeometry(feature, newGeometry);
((DefaultFeatureCollection) outVector).add(newFeature);
pm.worked(1);
}
pm.done();
inFeatureIterator.close();
}
Aggregations