Skip to content

Issue 54 location generic geometry#151

Open
perrymanmd wants to merge 19 commits into
mainfrom
issue_54-location_generic_geometry
Open

Issue 54 location generic geometry#151
perrymanmd wants to merge 19 commits into
mainfrom
issue_54-location_generic_geometry

Conversation

@perrymanmd
Copy link
Copy Markdown
Contributor

@perrymanmd perrymanmd commented May 12, 2026

PR Notes

Closes #54

TABLES

  1. Addtional table AT_LOCATION_GEOMETRY

    Column_Name Data_Type Nullable Comments
    LOCATION_CODE NUMBER(14) No References location in AT_PHYSICAL_LOCATION table
    GEOMETRY SDO_GEOMETRY No Geometry of location1
    GEOMETRY_TYPE NUMBER(2) Yes Type of geometry2, 3
    LATITUDE NUMBER Yes Latitude if geometry type is 1, otherwise NULL2, 4
    LONGITUDE NUMBER Yes Longitude if geometry type is 1, otherwise NULL2, 4

    1 All GEOMETRY values are WGS 84 2-dimensional (SRID 4326).

    2 These fields are populated by trigger AT_LOCATION_GEOMETRY_T01.

    3 Value will be one of:

    Value Description
    1 GEOMETRY is a single point
    2 GEOMETRY is a single line string
    3 GEOMETRY is a single polygon
    4 GEOMETRY is a heterogeneous collection of elements
    5 GEOMETRY is multiple points
    6 GEOMETRY is multiple line strings
    7 GEOMETRY is multiple disjoint polygons

    4 Values are in the datum specified in AT_PHYSICAL_LOCATION.HORIZONTAL_DATUM, if recognized. Otherwise they will be in WGS 84.

  2. Modified table AT_PHYSICAL_LOCATION

  • The columns LATITUDE and LONGITUDE are removed
  • Trigger AT_PHYSICAL_LOCATION_T02 is dropped; it's function (populating COUNTY_CODE, NATION_CODE, NEAREST_CITY and OFFICE_CODE from LATITUDE and LONGITUDE) is replaced by trigger AT_LOCATION_GEOMETRY_T01

VIEWS

  1. AV_LOC

    Added columns GEOMETRY and GEOMETRY_TYPE (from AT_LOCATION_GEOMETRY) at end. Columns LATITUDE and LONGITUDE are NULL if GEOMETRY_TYPE is NULL or != 1

  2. AV_LOC2

    Added columns GEOMETRY and GEOMETRY_TYPE (from AT_LOCATION_GEOMETRY) at end. Columns LATITUDE and LONGITUDE are NULL if GEOMETRY_TYPE is NULL or != 1

TYPES

  1. Modified LOCATION_OBJ_T
  • Removed LATITUDE and LONGITUDE fields
  • Added GEOMETRY and GEOMETRY_TYPE fields

PACKAGE SPECIFICATIONS

CWMS_LOC

  • Added STORE_LOCATION3 procedure which replaces the P_LATITUDE and P_LONGITUDE parameters of STORE_LOCATION2 with a single P_GEOMETRY parameter

  • Added RETRIEVE_LOCATION3 procedure which replaces the P_LATITUDE and P_LONGITUDE parameters of STORE_LOCATION2 with a single P_GEOMETRY parameter

  • Added STORE_GEOMETRY procedures

      procedure store_geometry(
          p_location_code  in number,
          p_geometry       in sdo_geometry,
          p_fail_if_exists in varchar2 default 'T');
    
      procedure store_geometry(
          p_location_id    in varchar2,
          p_geometry       in sdo_geometry,
          p_fail_if_exists in varchar2 default 'T',
          p_db_office_id   in varchar2);
    
  • Added RETRIEVE_GEOMETRY functions

      function retrieve_geometry(
          p_location_code in number)
          return sdo_geometry;
    
      function retrieve_geometry(
          p_location_id  in varchar2,
          p_db_office_id in varchar2)
          return sdo_geometry;
    
  • Added DELETE_GEOMETRY procedures

      procedure delete_geometry(
          p_location_code in number);
    
      procedure delete_geometry(
          p_location_id  in varchar2,
          p_db_office_id in varchar2);
    
  • Added GET_LOCATION_SRID function to retrieve a location's SRID based on its hoizontal datum (returns NULL if not recognized)

      function get_location_srid(
          p_location_code in number)
          return number;
    
  • Added GET_LOCATION_LAT_LON procedure, and GET_LOCATION_LAT and GET_LOCATION_LON functions to retrieve location latitude/longitude in various contexts.

      procedure get_location_lat_lon(
          p_lat in out nocopy at_location_geometry.latitude%type,
          p_lon in out nocopy at_location_geometry.latitude%type,
          p_location_code in number);
    
      function get_location_lat(
          p_location_code in at_physical_location.location_code%type)
          return at_location_geometry.latitude%type deterministic;
    
      function get_location_lon(
          p_location_code in at_physical_location.location_code%type)
          return at_location_geometry.latitude%type deterministic;
    

PACKAGE BODIES

CWMS_CAT

  • Modified query for CAT_LOCATION procedure
  • Modified query for CAT_LOCATION2 procedure

CWMS_EMBANK

  • Modified query for CAT_EMBANKMENT procedure

CWMS_LOC

  • Modified code in CREATE_LOCATION_RAW2 procedure
  • Modified code in UPDATE_LOCATION procedure
  • Modified code in UPDATE_LOCATION2 procedure
  • Modified code in RETRIEVE_LOCATION procedure
  • Modified code in RETRIEVE_LOCATION2 procedure
  • Modified code in RETRIEVE_LOCATIONS procedure
  • Modified code in GET_BOUNDING_OFC_CODE_FOR_LOC function
  • Modified code in GET_COUNTY_CODE_FOR_LOC function
  • Modified code in GET_NATION_ID_FOR_LOC function
  • Modified code in GET_NEAREST_CITY_FOR_LOC function
  • Modified code in GET_VERTICAL_DATUM_INFO procedure
  • Modified code in GET_VERTICAL_DATUM_OFFSET procedure
  • Added STORE_LOCATION3 procedure
  • Added RETRIEVE_LOCATION3 procedure
  • Added STORE_GEOMETRY procedures
  • Added RETRIEVE_GEOMETRY functions
  • Added DELETE_GEOMETRY procedures
  • Added GET_LOCATION_LAT_LON procedure
  • Added GET_LOCATION_LAT function
  • Added GET_LOCATION_LON function
  • Added GET_LOCATION_SRID function

CWMS_LOCK

  • Modified query for CAT_LOCK procedure
  • Modified code in RETRIEVE_LOCK_OLD procedure

CWMS_PROJECT

  • Modified query for CAT_PROJECT procedure
  • Modified code in RETRIEVE_PROJECT procedure

Update Script

  • Unlike a version update script, this one does not verify or update the CWMS schema version

  • The update script will transfer all LATITUDE and LONGITUDE values in the AT_PHYSICAL_LOCATION table to GEOMETRY values in the AT_LOCATION_GEOMETRY table.

    • If the LATITUDE or LONGITUDE value is null, the location will not have an entry in AT_LOCATION_GEOMETRY

    • If AT_PHYSICAL_LOCATION.HORIZONTAL_DATUM is recognized as valid, the GEOMETRY value will be properly converted to WGS 84.

    • If AT_PHYSICAL_LOCATION.HORIZONTAL_DATUM is NULL or not recognized, the GEOMETRY value will be created as if LATITUDE and LONGITUDE are in WGS 84.

    • The script stores a conversion note in AT_LATLON_CONVERSION, which can be dropped when it is no longer needed

    • The script outputs (via dbms_output) a summary of the conversions, similar to:

      Latitude/Longitude to Geometry Conversion Results
      ================================================================================
        3988 locations	[okay   ] Already in WGS 84 (4326) - no conversion necessary
        1072 locations	[warning] No lat/long - geometry not created
         616 locations	[okay   ] Converted from NAD83 (4269) to WGS 84 (4326)
         588 locations	[warning] No horizontal datum - created geometry as WGS 84 (4326)
         429 locations	[okay   ] Converted from NAD27 (4267) to WGS 84 (4326)
          19 locations	[warning] Unknown horizontal datum (WSG84) - created geometry as WGS 84 (4326)
           1 locations	[warning] Unknown horizontal datum (WGS 83) - created geometry as WGS 84 (4326)
      
      See table AT_LATLON_CONVERSION for details
      

@perrymanmd perrymanmd marked this pull request as draft May 12, 2026 13:55
@perrymanmd perrymanmd marked this pull request as ready for review May 12, 2026 16:44
Copy link
Copy Markdown
Contributor

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

I have a few comments.

Going to need to come back to it later though... that was long.

l_srid mdsys.sdo_coord_ref_sys.srid%type;
l_geometry sdo_geometry;
begin
if :new.geometry is null then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the column is not null, shouldn't this just fail before it gets to here?

location_code number(14) not null,
geometry sdo_geometry not null,
geometry_type number(2),
latitude number,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would it be better, perhaps from a index perspective to duplicate the centroid, to another geometry object so 2nd spatial index could be used?

NOTE: I'm assuming this is duplicated/shortcutting so the lat/long rendering is easier in the view for the lat/long columsn, so maybe both, or likely just overthinking it.

:new.longitude := l_geometry.sdo_point.x;
end if;
else
------------------------
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't pulling out the centroid here still be useful to get the nearest city?

loc.search_doc,
nvl (ll.geometry, bll.geometry) as geometry,
nvl (ll.geometry_type, bll.geometry_type) as geometry_type
from -- join the base location metadata (bas) with the location (loc)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
from -- join the base location metadata (bas) with the location (loc)
from cwms_20.at_physical_location loc
-- join the base location metadata (bas) with the location (loc)
left join cwms_20.at_physical_location bas on ( bas.location_code = loc.base_location_code )
left join cwms_20.at_base_location blo on ( blo.base_location_code = loc.base_location_code )
left outer join cwms_20.at_location_geometry ll on ( ll.location_code = loc.location_code )
left outer join cwms_20.at_location_geometry bll on ( bll.location_code = loc.base_location_code)

That was rather difficult to reason about with the joins all basically inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Location lat/long to more generic geometry and move to own table

2 participants