Search in sources :

Example 1 with Position

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;
}
Also used : Position(mil.nga.sf.geojson.Position) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(mil.nga.sf.geojson.Polygon)

Example 2 with Position

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;
}
Also used : Position(mil.nga.sf.geojson.Position) ResponseStatusException(org.springframework.web.server.ResponseStatusException)

Example 3 with 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());
    }
}
Also used : BigInteger(java.math.BigInteger) FeatureTransformer(gov.usgs.owi.nldi.transform.FeatureTransformer) Position(mil.nga.sf.geojson.Position) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 4 with Position

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;
}
Also used : HashMap(java.util.HashMap) Position(mil.nga.sf.geojson.Position)

Example 5 with 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());
}
Also used : BigInteger(java.math.BigInteger) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Position(mil.nga.sf.geojson.Position) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

Position (mil.nga.sf.geojson.Position)11 Test (org.junit.jupiter.api.Test)4 BigInteger (java.math.BigInteger)3 HashMap (java.util.HashMap)3 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 FeatureTransformer (gov.usgs.owi.nldi.transform.FeatureTransformer)1 HydrolocationTransformer (gov.usgs.owi.nldi.transform.HydrolocationTransformer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Point (mil.nga.sf.geojson.Point)1 Polygon (mil.nga.sf.geojson.Polygon)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1