use of mil.nga.sf.geojson.Position in project joa by sebastianfrey.
the class GeoPackageQuery method toPolygon.
private Polygon toPolygon(Bbox bbox) {
Double minX = bbox.getMinX();
Double minY = bbox.getMinY();
// Double minZ = bbox.getMinZ();
Double maxX = bbox.getMaxX();
Double maxY = bbox.getMaxY();
// Double maxZ = bbox.getMaxZ();
Polygon polygon = new Polygon();
Position lowerLeft = new Position(minX, minY);
Position upperLeft = new Position(minX, maxY);
Position upperRight = new Position(maxX, maxY);
Position lowerRight = new Position(maxX, minY);
List<List<Position>> coordinates = List.of(List.of(lowerLeft, upperLeft, upperRight, lowerRight, lowerLeft));
polygon.setCoordinates(coordinates);
return polygon;
}
use of mil.nga.sf.geojson.Position in project nldi-services by internetofwater.
the class NetworkController method extractLatitudeAndLongitude.
private Position extractLatitudeAndLongitude(String coords) {
// Only currently supported format is POINT(x y)
String tempCoords = coords.replaceAll("POINT ?\\(|\\)", "");
String[] coordsArray = tempCoords.split(" ");
Double longitude = Double.parseDouble(coordsArray[0]);
Double latitude = Double.parseDouble(coordsArray[1]);
if (longitude < -180 || longitude > 180) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid longitude");
}
if (latitude < -90 || latitude > 90) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid latitude");
}
Position position = new Position(longitude, latitude);
return position;
}
use of mil.nga.sf.geojson.Position in project nldi-services by internetofwater.
the class NetworkController method getFeatureByCoordinates.
// swagger documentation for /linked-data/comid/position endpoint
@Operation(summary = "getFeatureByCoordinates", description = "returns the feature closest to a provided set of coordinates")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Feature.class)) }), @ApiResponse(responseCode = "500", description = "Server error", content = @Content) })
@GetMapping(value = "linked-data/comid/position", produces = MediaType.APPLICATION_JSON_VALUE)
public void getFeatureByCoordinates(HttpServletRequest request, HttpServletResponse response, @Parameter(description = Parameters.COORDS_DESCRIPTION) @Pattern(message = Parameters.POINT_VALIDATION_MESSAGE, regexp = Parameters.POINT_VALIDATION_REGEX) @RequestParam(value = Parameters.COORDS) String coords) throws Exception {
BigInteger logId = logService.logRequest(request);
Position position = extractLatitudeAndLongitude(coords);
try {
Integer comid = lookupDao.getComidByLatitudeAndLongitude(position);
FeatureTransformer transformer = new FeatureTransformer(response, configurationService);
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(LookupDao.FEATURE_SOURCE, parameters.COMID);
parameterMap.put(Parameters.FEATURE_ID, comid);
addContentHeader(response);
streamResults(transformer, BaseDao.FEATURE, parameterMap);
} finally {
logService.logRequestComplete(logId, response.getStatus());
}
}
use of mil.nga.sf.geojson.Position in project nldi-services by internetofwater.
the class LookupDao method getClosestPointOnFlowline.
public Position getClosestPointOnFlowline(String featureSource, String featureID) throws Exception {
if (null == featureSource || null == featureID) {
throw new IllegalArgumentException("A featureSource and featureID are required");
}
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(LookupDao.FEATURE_SOURCE, featureSource);
parameterMap.put(Parameters.FEATURE_ID, featureID);
Map<String, Double> result = getSqlSession().selectOne(NS + ST_CLOSEST_POINT, parameterMap);
if (!result.containsKey("lat") || !result.containsKey("lon")) {
throw new Exception("getClosestPointOnFlowline did not return lat or lon");
}
Position position = new Position(result.get(Parameters.LONGITUDE), result.get(Parameters.LATITUDE));
return position;
}
use of mil.nga.sf.geojson.Position in project nldi-services by internetofwater.
the class NetworkControllerTest method getHydrolocationTest.
@Test
public void getHydrolocationTest() throws Exception {
Integer comid = 15510512;
String lon = "-74.71";
String lat = "43.743";
Position pygeoResponse = new Position(-74.7147222, 43.74305556);
// mock calls to other classes
when(lookupDao.getComidByLatitudeAndLongitude(any(Position.class))).thenReturn(comid);
when(lookupDao.getMeasure(eq(comid), eq(pygeoResponse))).thenReturn("measure");
when(lookupDao.getReachCode(comid)).thenReturn("reachcode");
when(pygeoapiService.getNldiFlowTraceIntersectionPoint(any(Position.class), eq(true), eq(PyGeoApiService.Direction.NONE))).thenReturn(pygeoResponse);
controller.getHydrologicLocation(request, response, String.format("POINT (%s %s)", lon, lat));
verify(logService).logRequest(any(HttpServletRequest.class));
verify(logService).logRequestComplete(any(BigInteger.class), any(int.class));
assertEquals(HttpStatus.OK.value(), response.getStatus());
}
Aggregations