Skip to content

Commit

Permalink
Fix Conflation with relations. Standard distance
Browse files Browse the repository at this point in the history
Rewrote ConflationMatchCommand to avoid problems when conflated
primitives are members of relations.
(delete class ReplaceGeometryOnlyCommand which was a bad idea afterall)

Add "Standard Distance" matcher, which makes more sense than "Centroid"
when matching nodes to ways.

Simplify build.xml
Cleanup some compilation warnings.
  • Loading branch information
tyndare committed Mar 18, 2017
1 parent 13ff87d commit d8c13fa
Show file tree
Hide file tree
Showing 31 changed files with 430 additions and 392 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-utilsplugin2"/>
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/build.properties
/build
/dist
/test/build
/test/report
/dist
File renamed without changes.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# the current plugin version. Increment if you create a new build to be rolled out
# via the OSM subversion repository
#
plugin.version=0.5.0
plugin.version=0.5.1

# the lowest JOSM version the curent plugin version is compatible with
#
Expand Down
112 changes: 20 additions & 92 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,100 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="josm-conflation-plugin" default="dist" basedir=".">
<project name="conflation" default="dist" basedir=".">

<property name="ant.build.javac.target" value="1.8"/>
<property name="ant.build.javac.source" value="1.8"/>
<property file="build.properties" />

<property name="plugin.build.dir" value="build" />
<property name="plugin.src.dir" value="src" />
<property name="plugin.dist.dir" value="../../dist" />
<property name="plugin.jar" value="${plugin.dist.dir}/conflation.jar" />
<property name="josm" location="../../core/dist/josm-custom.jar"/>
<property name="jts.plugin.jar" location="${plugin.dist.dir}/jts.jar"/>
<property name="utilsplugin2.plugin.jar" location="${plugin.dist.dir}/utilsplugin2.jar"/>
<!-- enter the SVN commit message -->
<property name="commit.message" value="Conflation"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="${josm.required.version}"/>

<target name="init">
<available file="build.properties" property="build.properties.present" />
<fail unless="build.properties.present">**
** Property file 'build.properties' doesn't exist.
** Create a copy from 'build.properties.template' and update the properties
** according to your local environment.
</fail>
<property file="build.properties" />
<property name="plugin.author" value="Josh Doe"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.conflation.ConflationPlugin"/>
<property name="plugin.description" value="Tool for conflating data (matching and merging)."/>
<property name="plugin.icon" value="images/dialogs/conflation.png"/>
<property name="plugin.link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Conflation"/>
<property name="plugin.requires" value="jts;utilsplugin2"/>
<property name="plugin.canloadatruntime" value="true"/>
<property name="version.entry.commit.revision" value="${plugin.version}"/>

<path id="compile.path">
<pathelement location="${josm}" />
<pathelement location="${jts.plugin.jar}"/>
<pathelement location="${utilsplugin2.plugin.jar}"/>
</path>
<!-- ** include targets that all plugins have in common ** -->
<import file="../build-common.xml"/>

<mkdir dir="${plugin.build.dir}" />
</target>
<fileset id="plugin.requires.jars" dir="${plugin.dist.dir}">
<include name="jts.jar"/>
<include name="utilsplugin2.jar"/>
</fileset>

<target name="compile" depends="init">
<echo message="compiling sources for ${plugin.jar} ... " />
<echo>Classpath includes ${josm}</echo>
<echo>Classpath includes ${jts.plugin.jar}</echo>
<echo>Classpath includes ${utilsplugin2.plugin.jar}</echo>
<javac srcdir="src" classpathref="compile.path" debug="true" destdir="${plugin.build.dir}" includeantruntime="false" encoding="UTF-8">
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>

<target name="dist" depends="clean,init,compile" description="Create the plugin jar">
<tstamp>
<format property="plugin.build.date" pattern="yyyy-MM-dd hh:mm aa" />
</tstamp>

<copy todir="${plugin.build.dir}/images">
<fileset dir="images">
<include name="**/*.png" />
</fileset>
</copy>

<copy todir="${plugin.build.dir}">
<fileset dir=".">
<include name="README" />
<include name="LICENSE" />
<include name="README.*" />
<include name="LICENSE.*" />
</fileset>
</copy>

<jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifestencoding="UTF-8">
<manifest>
<attribute name="Author" value="Josh Doe" />
<attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.conflation.ConflationPlugin" />
<attribute name="Plugin-Date" value="${plugin.build.date}" />
<attribute name="Plugin-Description" value="(Warning: Experimental!) Tool for conflating (merging) data." />
<attribute name="Plugin-Icon" value="images/dialogs/conflation.png"/>
<attribute name="Plugin-Link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Conflation" />
<attribute name="Plugin-Mainversion" value="${josm.required.version}" />
<attribute name="Plugin-Requires" value="jts;utilsplugin2"/>
<attribute name="Plugin-Version" value="${plugin.version}" />
</manifest>
</jar>
</target>

<target name="clean" description="Clean the build environment">
<delete dir="${plugin.build.dir}" />
</target>

<target name="osm-svn-install" depends="dist">
<echo>Installing the plugin in ${local.osm.svn.path}</echo>
<copy file="${plugin.jar}" todir="${local.osm.svn.path}" />
</target>

<!-- ************************************************************************************ -->
<!-- * Targets for compiling and running tests -->
<!-- ************************************************************************************ -->

<target name="dev-install" depends="dist">
<echo>Installing the plugin in ${local.install.path}</echo>
<copy file="${plugin.jar}" todir="${local.install.path}" />
</target>

<target name="test"/>
<target name="checkstyle"/>
<target name="findbugs"/>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import com.vividsolutions.jts.geom.Geometry;

public class CentroidAligner extends IndependentCandidateMatcher {

private IndependentCandidateMatcher matcher;

public CentroidAligner(IndependentCandidateMatcher matcher) {
this.matcher = matcher;
}

@Override
public double match(Geometry target, Geometry candidate) {
return matcher.match(align(target), align(candidate));
}

private Geometry align(Geometry original) {
Geometry aligned = (Geometry) original.clone();
MatcherUtil.align(aligned, aligned.getCentroid().getCoordinate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public CentroidDistanceMatcher(double maxDistance) {
setMaxDistance(maxDistance);
}

@Override
protected double distance(Geometry target, Geometry candidate) {
return target.getCentroid().distance(
candidate.getCentroid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public CompactnessMatcher() {
* @return 1 - the difference between the values of the shape
* characteristic, defined above.
*/
@Override
public double match(Geometry target, Geometry candidate) {
double score = 1 - Math.abs(characteristic(target)
- characteristic(candidate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Map<Feature, Matches> match(
}
targets.add(match.getTarget());
candidates.add(match.getCandidate());
scores.add(new Double(match.getScore()));
scores.add(Double.valueOf(match.getScore()));
}
//Re-add filtered-out targets, but with zero-score matches [Jon Aquino]
Map<Feature, Matches> targetToMatchesMap =
Expand All @@ -51,4 +51,4 @@ public Map<Feature, Matches> match(
}
return targetToMatchesMap;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public HausdorffDistanceMatcher(double maxDistance) {
setMaxDistance(maxDistance);
}

@Override
protected double distance(Geometry target, Geometry candidate) {
return new VertexHausdorffDistance(target, candidate).distance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void add(Feature feature, double score) {
if (score == 0) {
return;
}
scores.add(new Double(score));
scores.add(Double.valueOf(score));
dataset.add(feature);
if (score > topScore) {
topScore = score;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class OverlapMatcher extends IndependentCandidateMatcher {

@Override
public double match(Geometry target, Geometry candidate) {
//Impose the min to curb roundoff error in exact matches (a situation which
//arose during testing (identical datasets)) [Jon Aquino]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public SymDiffMatcher() {
* @param candidate the feature to compare with the target
* @return candidates with a score greater than 0 (typically all the candidates).
*/
@Override
public double match(Geometry target, Geometry candidate) {
Geometry targetGeom = (Geometry) target.clone();
Geometry candidateGeom = (Geometry) candidate.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public int compare(Feature o1, Feature o2) {
unionID++;
for (Feature targetConstituent : compositeTarget.getFeatures()) {
lastTargetConstituents.add(targetConstituent);
lastUnionIDs.add(new Integer(unionID));
lastUnionIDs.add(Integer.valueOf(unionID));
}
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ protected Map<Feature, Matches> disambiguateCompositeTargetConstituents(
}
compositeTargets.add(match.getTarget());
candidates.add(match.getCandidate());
scores.add(new Double(match.getScore()));
scores.add(Double.valueOf(match.getScore()));
targetConstituentsEncountered.addAll(((CompositeFeature) match.getTarget()).getFeatures());
}
Map<Feature, Matches> newMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void add(FeatureMatcher matcher, double weight) {
if (weight == 0) {
return;
}
matcherToWeightMap.put(matcher, new Double(weight));
matcherToWeightMap.put(matcher, Double.valueOf(weight));
}

private Map<FeatureMatcher, Double> matcherToWeightMap = new HashMap<>();
Expand Down Expand Up @@ -128,8 +128,8 @@ private void addToFeatureToScoreMap(Matches matches, FeatureMatcher matcher,

private void addToFeatureToScoreMap(Feature feature, double score, Map<Feature, Double> featureToScoreMap) {
Double oldScore = featureToScoreMap.get(feature);
if (oldScore == null) { oldScore = new Double(0); }
featureToScoreMap.put(feature, new Double(oldScore.doubleValue() + score));
if (oldScore == null) { oldScore = Double.valueOf(0); }
featureToScoreMap.put(feature, Double.valueOf(oldScore.doubleValue() + score));
}

private double normalizedWeight(FeatureMatcher matcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public MyValidatingTextField(
super(text, columns, validator);
setHorizontalAlignment(alignment);
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (getText().trim().length() == 0) {
setText(emptyStringReplacement);
Expand All @@ -42,6 +43,7 @@ public void focusLost(FocusEvent e) {

public static final Validator NON_NEGATIVE_DOUBLE_VALIDATOR =
new ValidatingTextField.Validator() {
@Override
public boolean isValid(String text) {
if (text.length() == 0) {
return true;
Expand All @@ -56,6 +58,7 @@ public boolean isValid(String text) {
}
};

@Override
public double getDouble() {
try {
return Double.parseDouble(getText().trim());
Expand All @@ -77,6 +80,7 @@ public double getDouble() {

public static final Validator NON_NEGATIVE_INTEGER_VALIDATOR =
new ValidatingTextField.Validator() {
@Override
public boolean isValid(String text) {
if (text.length() == 0) {
return true;
Expand All @@ -94,6 +98,7 @@ public static class CompositeValidator implements Validator {
public CompositeValidator(Validator[] validators) {
this.validators = validators;
}
@Override
public boolean isValid(String text) {
for (int i = 0; i < validators.length; i++) {
if (!validators[i].isValid(text)) {
Expand All @@ -109,6 +114,7 @@ public static class GreaterThanValidator implements Validator {
public GreaterThanValidator(double threshold) {
this.threshold = threshold;
}
@Override
public boolean isValid(String text) {
return text.trim().length() == 0
|| Double.parseDouble(text.trim()) > threshold;
Expand Down
4 changes: 4 additions & 0 deletions src/com/vividsolutions/jump/feature/BasicFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public BasicFeature(FeatureSchema featureSchema) {
/**
* A low-level accessor that is not normally used. It is called by ViewSchemaPlugIn.
*/
@Override
public void setAttributes(Object[] attributes) {
this.attributes = attributes;
}
Expand All @@ -69,6 +70,7 @@ public void setAttributes(Object[] attributes) {
*@param attributeIndex the array index at which to put the new attribute
*@param newAttribute the new attribute
*/
@Override
public void setAttribute(int attributeIndex, Object newAttribute) {
attributes[attributeIndex] = newAttribute;
}
Expand All @@ -79,6 +81,7 @@ public void setAttribute(int attributeIndex, Object newAttribute) {
*@param i the index of the attribute to get
*@return the attribute
*/
@Override
public Object getAttribute(int i) {
return attributes[i];
//We used to eat ArrayOutOfBoundsExceptions here. I've removed this behaviour
Expand All @@ -88,6 +91,7 @@ public Object getAttribute(int i) {
/**
* A low-level accessor that is not normally used. It is called by ViewSchemaPlugIn.
*/
@Override
public Object[] getAttributes() {
return attributes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/vividsolutions/jump/feature/FeatureSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void addAttribute(String attributeName, AttributeType attributeType) {
}

attributeNames.add(attributeName);
attributeNameToIndexMap.put(attributeName, new Integer(attributeCount));
attributeNameToIndexMap.put(attributeName, Integer.valueOf(attributeCount));
attributeTypes.add(attributeType);
attributeCount++;
}
Expand Down
Loading

0 comments on commit d8c13fa

Please sign in to comment.