Skip to content

Commit

Permalink
fix tests. IdentityTransformation needs to be used in cases where coo…
Browse files Browse the repository at this point in the history
…rdinate systems are not specified
  • Loading branch information
kainagel committed Feb 27, 2024
1 parent a881ad7 commit 097d1c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.matsim.api.core.v01.Identifiable;
import org.matsim.core.scenario.ProjectionUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.transformations.IdentityTransformation;
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.core.utils.io.MatsimXmlParser;
import org.matsim.utils.objectattributes.attributable.AttributesXmlReaderDelegate;
Expand Down Expand Up @@ -47,6 +48,12 @@ public CountsReaderMatsimV2( String externalInputCRS, String targetCRS, Counts<?
if (externalInputCRS != null && targetCRS != null) {
this.coordinateTransformation = TransformationFactory.getCoordinateTransformation(externalInputCRS, targetCRS);
ProjectionUtils.putCRS(this.counts, targetCRS);
} else if ( externalInputCRS==null && targetCRS==null ){
this.coordinateTransformation = new IdentityTransformation();
} else {
log.warn("finding a coordinate spec on one side but not on the other: inputCRS=" + externalInputCRS + "; targetCRS=" + targetCRS + ". We are assuming that things are consistent, and are continuing anyways." );
this.coordinateTransformation = new IdentityTransformation();
// yy this is the logic that I fould. One could alternatively fail here. kai, feb'24
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.geotools.referencing.operation.transform.IdentityTransform;
import org.matsim.api.core.v01.Identifiable;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.transformations.IdentityTransformation;
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.core.utils.io.MatsimXmlParser;
import org.xml.sax.Attributes;
Expand Down Expand Up @@ -103,7 +105,7 @@ protected void setDoctype(final String doctype) {
super.setDoctype(doctype);
// Currently the only counts-type is v1
if (COUNTS_V1.equals(doctype)) {
CoordinateTransformation coordinateTransformation = null;
CoordinateTransformation coordinateTransformation = new IdentityTransformation();
if (inputCRS != null && targetCRS != null) {
coordinateTransformation = TransformationFactory.getCoordinateTransformation(inputCRS, targetCRS );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,23 @@ void testWithControlerAndConfigParameters() {
final Counts<Link> dumpedCounts = new Counts<>();
new MatsimCountsReader( dumpedCounts ).readFile( outputDirectory+"/output_counts.xml.gz" );

for ( Id<Link> id : originalCounts.getCounts().keySet() ) {
final Coord originalCoord = originalCounts.getCount( id ).getCoord();
final Coord dumpedCoord = dumpedCounts.getCount( id ).getCoord();
// for ( Id<Link> id : originalCounts.getCounts().keySet() ) {
// final Coord originalCoord = originalCounts.getCount( id ).getCoord();
// final Coord dumpedCoord = dumpedCounts.getCount( id ).getCoord();
//
// Assertions.assertEquals(
// originalCoord.getX(),
// dumpedCoord.getX(),
// epsilon,
// "coordinates were not reprojected for dump" );
// Assertions.assertEquals(
// originalCoord.getY(),
// dumpedCoord.getY(),
// epsilon,
// "coordinates were not reprojected for dump" );
// }
// (output is now in simulation coordinate system; it is no longer re-projected. As we are also doing in other parts of matsim). kai, feb'24

Assertions.assertEquals(
originalCoord.getX(),
dumpedCoord.getX(),
epsilon,
"coordinates were not reprojected for dump" );
Assertions.assertEquals(
originalCoord.getY(),
dumpedCoord.getY(),
epsilon,
"coordinates were not reprojected for dump" );
}
}

private void assertCountsAreReprojectedCorrectly(
Expand Down

0 comments on commit 097d1c2

Please sign in to comment.