Commit 8e385d6f authored by Katharina Przybill's avatar Katharina Przybill
Browse files

Update EquidistanceDevelopment.java, calculate with unclipped Geometry

parent d7c7e4e9
......@@ -4,7 +4,13 @@ import static java.lang.Math.max;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygonal;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
......@@ -66,13 +72,11 @@ public class EquidistanceDevelopment{
/*.areaOfInterest(new OSHDBBoundingBox(8.631992340087889,
49.38226103399081, 8.732757568359375,
49.44212421583237)) // hd barron*/
.timestamps("2007-01-01", "2017-01-01")
.timestamps("2008-01-01", "2017-01-01")
.osmType(OSMType.WAY, OSMType.RELATION)
.osmEntityFilter(osmEntity -> {
// get relation only if it is a multipolygon
if (osmEntity.getType() == OSMType.RELATION) {
if (!osmEntity.hasTagValue(typeMultipolyTag.getKey(), typeMultipolyTag.getValue())) {
return false;
}
......@@ -84,18 +88,22 @@ public class EquidistanceDevelopment{
.groupByEntity()
.filter(osmContributions -> {
// exclude objects where area change is "large"
// exclude objects where area change is "large" or which are not polygons
//deletion (getGeometryBefore) or not deletion (getGeometryAfter)
double area_first = osmContributions.get(0).getGeometryAfter().getArea();
OSMContribution lastContribution = osmContributions.get(osmContributions.size() - 1);
double area_last;
Geometry geom_first = osmContributions.get(0).getGeometryUnclippedAfter();
Geometry geom_last;
if (lastContribution.is(ContributionType.DELETION)) {
area_last = lastContribution.getGeometryBefore().getArea();
geom_last = lastContribution.getGeometryUnclippedBefore();
} else {
area_last = lastContribution.getGeometryAfter().getArea();
geom_last = lastContribution.getGeometryUnclippedAfter();
}
if (!(geom_first instanceof Polygonal && geom_last instanceof Polygonal))
return false; // is not a polygon
double area_first = geom_first.getArea();
double area_last = geom_last.getArea();
if (Math.min(area_first, area_last) / Math.max(area_first, area_last) < 0.5)
return false; // area change is to large
......@@ -103,7 +111,7 @@ public class EquidistanceDevelopment{
})
.map(osmContributions -> {
//creation -> use getGeometryAfter
Geometry geometry_first = osmContributions.get(0).getGeometryAfter();
Geometry geometry_first = osmContributions.get(0).getGeometryUnclippedAfter();
double equidistance_first =
Geo.lengthOf(geometry_first.getBoundary()) / geometry_first.getCoordinates().length;
......@@ -111,24 +119,50 @@ public class EquidistanceDevelopment{
OSMContribution lastContribution = osmContributions.get(osmContributions.size() - 1);
Geometry geometry_last;
if (lastContribution.is(ContributionType.DELETION)){
geometry_last = lastContribution.getGeometryBefore();
geometry_last = lastContribution.getGeometryUnclippedBefore();
}else {
geometry_last = lastContribution.getGeometryAfter();
geometry_last = lastContribution.getGeometryUnclippedAfter();
}
double equidistance_last =
Geo.lengthOf(geometry_last.getBoundary()) / geometry_last.getCoordinates().length;
// right: Development of the equidistance. Subtract equidistance from the initially created
// polygon from its corresponding one which is recently valid
// right: Development of the equidistance. Substract equidistance from polygon
// which is recently valid from the initially created corresponding one
return new ImmutablePair<>(equidistance_first, equidistance_first - equidistance_last);
//return new ImmutablePair<>(equidistance_first, equidistance_last);
})
.collect();
// sort by equidistance_first
devel_equ.sort(Comparator.comparingDouble(Pair::getRight));
devel_equ.sort(Comparator.comparingDouble(Pair::getLeft));
// output
for (ImmutablePair<Double, Double> result : devel_equ)
System.out.format("%.2f\t;%.2f\n", result.getLeft(), result.getRight());
// write result to txt file
BufferedWriter writer = null;
try {
//create a temporary file
String fileName = "equ_stg.txt";
File logFile = new File(fileName);
writer = new BufferedWriter(new FileWriter(logFile));
for (ImmutablePair<Double, Double> result : devel_equ) {
String line = result.getLeft().toString() + " ; " + result.getRight().toString();
writer.write(line);
writer.newLine();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
// Close the writer regardless of what happens...
writer.close();
} catch (Exception e) {
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment