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)
Reflecting a Geometry Object Around a Line
I had need, in SQL Server Spatial, for a function that reflected a geometry object around a supplied line.
So I wrote one, and this post describes how that function enables the reflecting of a geometry around a line.
SYNOPSIS
The function is called STReflect and its header is:
CREATE FUNCTION [$(Owner)].[STReflect] ( @p_geometry geometry, @p_reflection_line geometry, @p_round_xy int = 8, @p_round_zm int = 8 ) RETURNS geometry
DESCRIPTION
The function does as it describes. For any geometry object it reflects it about the supplied line of reflection.
The line of reflection can only be a LineString with 2-points.
Since the function computes new locations for all the points in the supplied geometry, its computed ordinate values can be restricted (rounded) to the supplied integer decimal digits of precision (eg 3 is 1mm or 0.001 for metric data).
EXAMPLES
The following three examples are offered to show how the function works.
EXAMPLE 1: Point
SELECT [dbo].[STReflect] ( geometry::STGeomFromText('POINT(1 -2)',0), geometry::STGeomFromText('LINESTRING(3 2,2 6)',0), 2,2 ).AsTextZM() as rPoint; rPoint POINT (6.65 -0.59)
EXAMPLE 2: Line
SELECT [dbo].[STReflect] ( geometry::STGeomFromText('LINESTRING(1 -2, 1.5 0)',0), geometry::STGeomFromText('LINESTRING(3 2,2 6)',0), 2,2 ).AsTextZM() as rLine; rLine LINESTRING (6.65 -0.59, 5.26 0.94)
EXAMPLE 3: Polygon
WITH data AS ( SELECT geometry::STGeomFromText('POLYGON((1 4, 2 4, 1.5 3,1 4))',0) as polygon, geometry::STGeomFromText('LINESTRING(-5 0,5 0)',0) as rLine ) SELECT [$(Owner)].[STReflect] ( c.polygon, c.rLine, 4,4 ).AsTextZM() as rPolygon FROM data as c; GO rPolygon POLYGON ((1 -4, 2 -4, 1.5 -3, 1 -4))
FINAL EXAMPLE: Multiple Reflections Of A Polygon around a rotating line of reflection
with data as ( SELECT i.IntValue as angle, geometry::STGeomFromText('POLYGON((1 4, 2 4, 1.5 3,1 4))',0) as geom, [dbo].[STRotate](geometry::STGeomFromText('LINESTRING(3 2,2 6)',0),2.5,4,i.IntValue,4,4) as rLine FROM [dbo].[generate_series](0,155,25) as i ) SELECT -1 as angle, geometry::STGeomFromText('POLYGON((1 4, 2 4, 1.5 3,1 4))',0) as geom union all select angle, a.rline from data as a union all SELECT a.angle, [dbo].[STReflect] ( a.geom,a.rLine,4,4 ) as rPoint FROM data as a; GO
STRotate is documented in the SQL Server Spatial General Documentation.
The function is available with the 200+ TSQL functions available by donation from this website.
I hope this function is of use to someone.
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