USACE / USACE/cwms-data-api

Various Endpoints for POST/DELETE/UPDATE do NOT Respect Unit System

Open
#1,191 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Meeting Issue
Dominant language
Java
Stars
28
Forks
25
Avg merge
4d 22h
Merged PRs (30d)
20

Description

When making a POST to
/stream-locations
and an UPDATE to /locations both resulted in an incorrect value being stored.

ORIGINALLY posted here (Locations):
@msweier has an issue on discourse here:
https://discourse.hecdev.net/t/cwms-vue-location-table-unit-issue/3444

In stream-locations if you provide 3 with "mi" for the units you get 4.82 back. This value was stored in CMA's stream-location page. It was also stored using CDA. Both resulted in this. It appears when you store something even if you say "ft" or "mi" it results in the database default units of metric or "m" or "km".
EDIT: I do not know how/why but this endpoint in both CDA and what can be input into CMA is working now. If you run the below payload it will return the correct value for units. Location UPDATE is still having issues.

Click to expand Stream-Location (working now)
{
"stream-location-node": {
  "id": {
    "office-id": "SWT",
    "name": "AARK"
  },
  "stream-node": {
    "stream-id": {
      "office-id": "SWT",
      "name": "Arkansas_R"
    },
    "station": 3,
    "station-units": "mi"
  }
}
}

Results in:

{
  "stream-location-node": {
    "id": {
      "office-id": "SWT",
      "name": "AARK"
    },
    "stream-node": {
      "stream-id": {
        "office-id": "SWT",
        "name": "Arkansas_R"
      },
      "station": 4.82803,
      "station-units": "mi"
    }
  },
  "area-units": "mi2",
  "stage-units": "ft"
}

/Locations

In a recent CDA workshop (07/14/2025) where we went through the locations endpoint and the same was true for the elevation in the locations PATCH method.

PATCH (issue shows here) I store as 1 *ft*
curl -X 'PATCH' \
  'https://wm.swt.ds.usace.army.mil:8243/swt-data/locations/BEAR' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "office-id": "SWT",
  "name": "BEAR",
  "latitude": 36.1336111,
  "longitude": -95.1166667,
  "active": true,
  "public-name": "Bear Lake of the Ozarks, USA",
  "long-name": "BEAR",
  "description": "Bear Lake in USA Test 4",
  "timezone-name": "US/Central",
  "location-kind": "SITE",
  "nation": "US",
  "state-initial": "OK",
  "county-name": "Tulsa",
  "nearest-city": "Sand Springs, OK",
  "horizontal-datum": "NAD83",
  "vertical-datum": "NGVD29",
  "elevation": 1,
  "elevation-units": "ft"
}'
{
  "office-id": "SWT",
  "name": "BEAR",
  "latitude": 36.1336111,
  "longitude": -95.1166667,
  "active": true,
  "public-name": "Bear Lake of the Ozarks, USA",
  "long-name": "BEAR",
  "description": "Bear Lake in USA Test 4",
  "timezone-name": "US/Central",
  "location-kind": "SITE",
  "nation": "US",
  "state-initial": "OK",
  "county-name": "Tulsa",
  "nearest-city": "Sand Springs, OK",
  "horizontal-datum": "NAD83",
  "vertical-datum": "NGVD29",
  "elevation": 1,
  "elevation-units": "ft"
}
But then I get back *3.28ft*
curl -X 'GET' \
  'https://t7/swt-data/locations/BEAR?office=SWT' \
  -H 'accept: application/json;version=2'
{
  "office-id": "SWT",
  "name": "BEAR",
  "latitude": 36.1336111,
  "longitude": -95.1166667,
  "active": true,
  "public-name": "Bear Lake of the Ozarks, USA",
  "long-name": "BEAR",
  "description": "Bear Lake in USA Test 4",
  "timezone-name": "US/Central",
  "location-kind": "SITE",
  "nation": "US",
  "state-initial": "OK",
  "county-name": "Tulsa",
  "nearest-city": "Sand Springs, OK",
  "horizontal-datum": "NAD83",
  "vertical-datum": "NGVD29",
  "elevation": 3.280839895013123,
  "bounding-office-id": "SWT",
  "elevation-units": "ft"
}
I have not tested all endpoints exhaustively, and some like #1180 do not allow you to specify units and assume you are entering metric.

This might be a Database issue but I have not confirmed that yet with @JeremyDKellett for what CMA is using (if the PL/SQL is the same for stream-locations)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the /locations PATCH request with elevation 1 ft, then GET the location and compare the returned value. Compare this behavior with the currently working /stream-locations example and trace the endpoint's unit-conversion and storage path. Done means specified units are respected consistently for the affected endpoint behavior and regression coverage exists for the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.