## Top 5 Recent Articles

##### ARTICLES CATEGORIES

- Biography (1)
- Blog (27)
- Changes (1)
- Customers (1)
- Education (2)
- General Software (21)
- Image Catalog (2)
- Licensing (1)
- ManifoldGIS (3)
- MySQL Spatial (2)
- Networking and Routing (including Optimization) (3)
- Oracle Spatial (61)
- PostGIS (20)
- Press Releases (1)
- Source code (6)
- Space Curves (1)
- Spatial DB comparison (1)
- SQL (1)
- SQL Server Blog (17)
- SQL Server Spatial (General) (15)
- SQL Server Spatial (LRS) (37)
- Stored Procedure (2)
- XML (5)

# Reflecting a geometry 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 Function Documentation
- Oracle Spatial Exporter Package Documentation
- Oracle Spatial Object Function Documentation
- Oracle Spatial Object Function Documentation (Multi Page Version)
- PostGIS pl/pgSQL Function Documentation
- SC4O Oracle Java Topology Suite (Stored Procedures) Package Documentation
- SQL Server Spatial General TSQL Function Documentation
- SQL Server Spatial LRS TSQL Function Documentation