Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.netex.mapping;

import java.util.List;
import javax.annotation.Nullable;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.rutebanken.netex.model.LocationStructure;
Expand All @@ -21,10 +22,19 @@ static WgsCoordinate mapToDomain(SimplePoint_VersionStructure point) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc for the mapToDomain method is obsolete, this PR gives a good opportunity to update it.

  • You can explain here that we need to convert from the LON/LAT convention in GML to the LAT/LON convention in WGS since this is a usual source of bug/confusion.
  • You can also describe here the fallback logic you implemented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppesaraceno can you update the doc?

LocationStructure loc = point.getLocation();

// This should not happen
if (loc.getLongitude() == null || loc.getLatitude() == null) {
throw new IllegalArgumentException("Coordinate is not valid: " + loc);
if (loc.getPos() == null) {
throw new IllegalArgumentException("Coordinate is not valid: " + loc);
}

List<Double> coordinates = loc.getPos().getValue();
if (coordinates.size() != 2) {
throw new IllegalArgumentException("Coordinate is not valid: " + loc);
}

return new WgsCoordinate(coordinates.get(1), coordinates.get(0));
}

// Location is safe to process
return new WgsCoordinate(loc.getLatitude().doubleValue(), loc.getLongitude().doubleValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.math.BigDecimal;
import net.opengis.gml._3.DirectPositionType;
import org.junit.jupiter.api.Test;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.rutebanken.netex.model.LocationStructure;
Expand Down Expand Up @@ -63,4 +64,31 @@ public void handleCoordinatesWithMissingLongitude() {
.withLocation(new LocationStructure().withLatitude(LATITUDE));
assertThrows(IllegalArgumentException.class, () -> WgsCoordinateMapper.mapToDomain(p));
}

@Test
public void handleCoordinateWithGmlPosition() {
LocationStructure locationStructure = new LocationStructure()
.withPos(new DirectPositionType().withValue(LONGITUDE_VALUE, LATITUDE_VALUE));

SimplePoint_VersionStructure point = new SimplePoint_VersionStructure()
.withLocation(locationStructure);

// When map coordinates
WgsCoordinate c = WgsCoordinateMapper.mapToDomain(point);

// Then verify coordinate
assertEquals(LONGITUDE_VALUE, c.longitude(), DELTA);
assertEquals(LATITUDE_VALUE, c.latitude(), DELTA);
}

@Test
public void handleCoordinateWithIncompleteGmlPosition() {
LocationStructure locationStructure = new LocationStructure()
.withPos(new DirectPositionType().withValue(LONGITUDE_VALUE));

SimplePoint_VersionStructure point = new SimplePoint_VersionStructure()
.withLocation(locationStructure);

assertThrows(IllegalArgumentException.class, () -> WgsCoordinateMapper.mapToDomain(point));
}
}