Top 5 Recent Articles
ARTICLES CATEGORIES
- Algorithms (22)
- All (399)
- Biography (1)
- Blog (44)
- Business Requirements (1)
- Commentary (1)
- Conversion (2)
- Customers (2)
- Data Models (1)
- Education (2)
- GeoRaptor (13)
- GPS (1)
- Image Processing (2)
- Import Export (8)
- Licensing (2)
- LiDAR (1)
- Linear Referencing (4)
- Manifold GIS (3)
- Mapping (1)
- MySQL Spatial (7)
- Networking and Routing (including Optimization) (5)
- Open Source (18)
- Oracle Spatial and Locator (194)
- Partitioning (1)
- PostGIS (36)
- Projections (1)
- Published Articles (1)
- qGIS (1)
- Recommendations (1)
- Services (1)
- Software Change Log (1)
- Source Code (37)
- Space Curves (9)
- Spatial Database Functions (109)
- Spatial DB comparison (1)
- Spatial XML Processing (11)
- SQL Server Spatial (92)
- Standards (3)
- Stored Procedure (17)
- Tessellation or Gridding (10)
- Tools (2)
- Topological Relationships (1)
- Training (2)
- Triangulation (2)
STUpdate: Replace all points equal to the supplied point with replacement point.
SQL Server Spatial, unlike spatial database type systems such as PostGIS, does not provide coordinate editing functions:
- STAddPoint
- STUpdatePoint
- STDeletePoint
These functions are not a part of either the SQL or OGC standards. In fact neither provide an API for the SQL editing of geometry objects. If one wishes to do so, one must program replacement functions. For SQL based solutions (eg based on TSQL) one must manipulate a geometry’s Well Know Text (WKT) description. This is pretty ugly (unless you are an Oracle Locator/Spatial user and so can access the array holding the ordinate values), so to wrap such access in specific SQL accessible functions is of use.
This article introduces the STUpdate function, which updates (replaces) all geometry points that are equal to the supplied point with the replacement point.
CREATE FUNCTION [$(owner)].[STUpdate] ( @p_geometry geometry, @p_original_pt geometry, @p_replace_pt geometry, @p_round_xy INT = 3, @p_round_zm INT = 2 ) RETURNS geometry AS BEGIN -- Implementation END GO
Description
Function that updates all coordinates that equal p_point with the supplied p_replace_point.
The p_round_xy value is used when comparing geometry point’s XY ordinates to p_point’s.
The updated coordinate’s XY ordinates are rounded to p_round_xy number of decimal digits of precision. The updated coordinate’s ZM ordinates are rounded to p_round_ZM number of decimal digits of precision.
Arguments
@p_geometry (geometry) - supplied geometry OF any TYPE. @p_point (geometry) - Original coordinate TO be replaced. @p_replace_point (geometry) - Replacement coordinate @p_round_xy (INT) - DECIMAL degrees OF PRECISION TO which calculated XY ordinates are rounded. @p_round_zm (INT) - DECIMAL degrees OF PRECISION TO which calculated ZM ordinates are rounded.
Examples
SELECT [dbo].[STUpdate](geometry::STGeomFromText('POINT(0 0 1 1)',0), geometry::STGeomFromText('POINT(0 0 1 1)',0), geometry::STGeomFromText('POINT(1 1 1 1)',0),2,1).AsTextZM() AS WKT GO WKT POINT (1 1 1 1) SELECT [dbo].[STUpdate](geometry::STGeomFromText('MULTIPOINT((1 1 1 1),(2 2 2 2),(3 3 3 3))',0), geometry::STGeomFromText('POINT(2 2 2 2)',0), geometry::STGeomFromText('POINT(2.1 2.1 2 2)',0),2,1).AsTextZM() AS WKT GO WKT MULTIPOINT ((1 1 1 1), (2.1 2.1 2 2), (3 3 3 3)) SELECT [dbo].[STUpdate](geometry::STGeomFromText('LINESTRING(1 1, 2 2, 3 3, 4 4)',0), geometry::STGeomFromText('POINT(3 3)',0), geometry::STGeomFromText('POINT(2.1 2.5)',0),2,1).AsTextZM() AS WKT GO WKT LINESTRING (1 1, 2 2, 2.1 2.5, 4 4) SELECT [dbo].[STUpdate](geometry::STGeomFromText('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))',0), geometry::STGeomFromText('POINT(3 3)',0), geometry::STGeomFromText('POINT(3.1 3.3)',0),2,1).AsTextZM() AS WKT GO WKT MULTILINESTRING ((1 1, 2 2, 3.1 3.3), (4 4, 5 5, 6 6)) SELECT [dbo].[STUpdate](geometry::STGeomFromText('COMPOUNDCURVE(CIRCULARSTRING(9.962 -0.872,10.1 0,9.962 0.872),(9.962 0.872,0 0,9.962 -0.872))',0), geometry::STGeomFromText('POINT(9.962 0.872)',0), geometry::STGeomFromText('POINT(9.9 0.9)',0),2,1).AsTextZM() AS WKT GO WKT COMPOUNDCURVE (CIRCULARSTRING (9.962 -0.872, 10.1 0, 9.9 0.9), (9.9 0.9, 0 0, 9.962 -0.872)) -- 'Polygon - First and lat point of ring update. SELECT [dbo].[STUpdate](geometry::STGeomFromText('POLYGON((1 1,10 1,10 10,1 10,1 1),(2 2,9 2,9 9,2 9,2 2))',0), geometry::STGeomFromText('POINT(1 1)',0), geometry::STGeomFromText('POINT(1.1 1.1)',0),2,1).AsTextZM() AS WKT GO WKT POLYGON ((1.1 1.1, 10 1, 10 10, 1 10, 1.1 1.1), (2 2, 9 2, 9 9, 2 9, 2 2)) SELECT [dbo].[STUpdate](geometry::STGeomFromText('POLYGON((326000.0 5455000.0,327000.0 5455000.0,326500.0 5456000.0,326000.0 5455000.0))',28355), geometry::STGeomFromText('POINT(326000.0 5455000.0)',28355), geometry::STGeomFromText('POINT(326100.0 5455100.0)',28355),2,1).AsTextZM() AS WKT GO WKT POLYGON ((326100 5455100, 327000 5455000, 326500 5456000, 326100 5455100)) SELECT [dbo].[STUpdate](geometry::STGeomFromText('GEOMETRYCOLLECTION(POINT(2 3 4),LINESTRING(2 3 4,3 4 5),POLYGON((326000.0 5455000.0,327000.0 5455000.0,326500.0 5456000.0,326000.0 5455000.0)))',0), geometry::STGeomFromText('POINT(3 4 5)',0), geometry::STGeomFromText('POINT(3.1 4.1 5.1)',0),2,1).AsTextZM() AS WKT GO WKT GEOMETRYCOLLECTION (POINT (2 3 4), LINESTRING (2 3 4, 3.1 4.1 5.1), POLYGON ((326000 5455000, 327000 5455000, 326500 5456000, 326000 5455000)))
The function can be downloaded from here
Documentation
- MySQL Spatial General Functions
- Oracle LRS Objects
- Oracle Spatial Exporter (Java + pl/SQL)
- Oracle Spatial Object Functions
- Oracle Spatial Object Functions (Multi Page)
- PostGIS pl/pgSQL Functions
- SC4O Oracle Java Topology Suite (Java + pl/SQL)
- SQL Server Spatial General TSQL Functions
- SQL Server Spatial LRS TSQL Functions