Commit a25ee392 authored by Katharina Przybill's avatar Katharina Przybill
Browse files

Upload New File

parent d927320c
package similarProjectsComparison.oshdb.landuseGeometry;
import static java.lang.Math.max;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.heigit.bigspatialdata.oshdb.api.db.OSHDBH2;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.OSMContributionView;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.OSMEntitySnapshotView;
import org.heigit.bigspatialdata.oshdb.api.object.OSMContribution;
import org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.bigspatialdata.oshdb.osm.OSMRelation;
import org.heigit.bigspatialdata.oshdb.osm.OSMType;
import org.heigit.bigspatialdata.oshdb.osm.OSMWay;
import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTag;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTagKey;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp;
import org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType;
import org.heigit.bigspatialdata.oshdb.util.geometry.Geo;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.TagTranslator;
import org.heigit.bigspatialdata.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter;
import similarProjectsComparison.oshdb.geomdistance.Junctions.WayNode;
public class EquidistanceDevelopment{
public static void main(String[] args) throws Exception {
// database
OSHDBH2 oshdb = (new OSHDBH2(
"C:\\Users\\ob437\\eclipse-workspace\\oshdb-examples\\oshdb-examples\\workshops\\src\\main\\resources\\bw_z15_keytables.compressed.oshdb.mv.db"))
.multithreading(!true);
// OSHDBH2 oshdbKeytables = new OSHDBH2("C:\\Users\\ob437\\eclipse-workspace\\oshdb-examples\\oshdb-examples\\workshops\\src\\main\\resources\\bw_z15_keytables.compressed.oshdb.mv.db");
OSHDBH2 oshdbKeytables = oshdb;
TagTranslator tt = new TagTranslator(oshdbKeytables.getConnection());
OSHDBTag typeMultipolyTag = tt.getOSHDBTagOf("type", "multipolygon");
OSHDBTagKey naturalKey = tt.getOSHDBTagKeyOf("natural");
OSHDBTagKey landuseKey = tt.getOSHDBTagKeyOf("landuse");
// query
List<ImmutablePair<Double, Double>> devel_equ = OSMContributionView.on(oshdb)
.keytables(oshdbKeytables)
//.areaOfInterest(new OSHDBBoundingBox(8.6598,49.3966,8.726,49.4249)) // HD
.areaOfInterest(new OSHDBBoundingBox(8.9079,48.6626,9.4469,48.8959)) // Stuttgart
/*.areaOfInterest(new OSHDBBoundingBox(80.83053588867188,
26.722307016045065, 81.1065673828125,
26.96124577052697)) // lucknow indien*/
/*.areaOfInterest(new OSHDBBoundingBox(72.762451171875,
18.884198609350264, 72.99728393554688,
19.32539900916396)) // mumbai indien*/
/*.areaOfInterest(new OSHDBBoundingBox(8.631992340087889,
49.38226103399081, 8.732757568359375,
49.44212421583237)) // hd barron*/
.timestamps("2007-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;
}
}
// get only ways and relations with natural or landuse tag
return osmEntity.hasTagKey(naturalKey) || osmEntity.hasTagKey(landuseKey);
})
.groupByEntity()
.filter(osmContributions -> {
// exclude objects where area change is "large"
//deletion (getGeometryBefore) or not deletion (getGeometryAfter)
double area_first = osmContributions.get(0).getGeometryAfter().getArea();
OSMContribution lastContribution = osmContributions.get(osmContributions.size() - 1);
double area_last;
if (lastContribution.is(ContributionType.DELETION)) {
area_last = lastContribution.getGeometryBefore().getArea();
} else {
area_last = lastContribution.getGeometryAfter().getArea();
}
if (Math.min(area_first, area_last) / Math.max(area_first, area_last) < 0.5)
return false; // area change is to large
return true;
})
.map(osmContributions -> {
//creation -> use getGeometryAfter
Geometry geometry_first = osmContributions.get(0).getGeometryAfter();
double equidistance_first =
Geo.lengthOf(geometry_first.getBoundary()) / geometry_first.getCoordinates().length;
//deletion (getGeometryBefore) or nicht deletion (getGeometryAfter)
OSMContribution lastContribution = osmContributions.get(osmContributions.size() - 1);
Geometry geometry_last;
if (lastContribution.is(ContributionType.DELETION)){
geometry_last = lastContribution.getGeometryBefore();
}else {
geometry_last = lastContribution.getGeometryAfter();
}
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
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));
// output
for (ImmutablePair<Double, Double> result : devel_equ)
System.out.format("%.2f\t;%.2f\n", result.getLeft(), result.getRight());
}
}
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