## Top 5 Recent Articles

##### ARTICLES CATEGORIES

- Algorithms (15)
- All (399)
- Biography (1)
- Blog (44)
- Business Requirements (1)
- Commentary (1)
- Customers (2)
- Data Models (1)
- Education (2)
- GeoRaptor (13)
- Image Processing (2)
- Import Export (8)
- Licensing (2)
- Linear Referencing (4)
- Manifold GIS (3)
- Mapping (1)
- MySQL Spatial (7)
- Networking and Routing (including Optimization) (3)
- Open Source (18)
- Oracle Spatial and Locator (192)
- PostGIS (34)
- Published Articles (1)
- qGIS (1)
- Recommendations (1)
- Services (1)
- Software Change Log (1)
- Source Code (35)
- Space Curves (9)
- Spatial Database Functions (107)
- Spatial DB comparison (1)
- Spatial XML Processing (10)
- SQL Server Spatial (85)
- Standards (2)
- Stored Procedure (15)
- Tessellation or Gridding (10)
- Tools (2)
- Topological Relationships (1)
- Training (2)
- Triangulation (2)

# Identifying Quadrilateral Polygon Geometries in SQL Server Spatial

# Introduction

This article introduces a a function to identify quadrilaterally shaped polygon objects in SQL Server Spatial

## Discussion

Some geometric processing cannot, or should not, be carried out on quadrilateral polygon geometries.

An situation where one does not want to process quadrilateral polygons is where one uses the STLineToCurve function to convert a LineString/Polygon to a geometry with CircularStrings and the passed geometry is a 5 point polygon that is a **square **not a stroked square (impossible).

It seems strange to create a function that is mainly to be used in the negative, but at the moment the current use case is just that.

## What are Quadrilateral Polygon Geometries

Here is a list of quadrilateral objects.

The quadrilateral polygons this function detects are:

1. Square,

2. Rectangle,

3. Rhomboid,

4. Isosceles Trapezium,

4. Parallelogram.

## STIsQuadrilateral

The identification of quadrilaterial polygons is encapsulated in the STisQuadrilateral function.

This is defined as follows.

Function STIsQuadrilateral ( @p_polygon geometry, @p_precision integer = 3 ) Returns bit /* True if is a Quadrilateral geometry, 0 otherwise. */ The parameters are: @p_polygon (geometry) - A 5 point polygon @p_precision (integer) - Precision of length of a side or diagonal

The function detects any of the above quadrilateral polygon objects at any angle, but does not detect Irregular Quadrilaterals.

Detection is done via comparing sides or diagonals (to desired precision).

## Examples.

with data as ( select 'Square' as qType, geometry::STGeomFromText('POLYGON((50 0,65 0,65 15,50 15,50 0))',0) as geom union all select 'Rectangle' as qType, geometry::STGeomFromText('POLYGON((80 0,110 0,110 10,80 10,80 0))',0) union all select 'Isosceles Trapezium' as qType, geometry::STGeomFromText('POLYGON ((60 20, 70 20, 68 30, 62 30, 60 20))',0) union all select 'Rhombus' as qType, geometry::STGeomFromText('POLYGON((20 0,40 10, 20 20,0 10, 20 0))',0) union all select 'Rectangle at Angle' as qType, geometry::STGeomFromText('POLYGON ((72.929 -15.355, 83.536 -4.749, 72.929 5.858, 62.322 -4.749, 72.929 -15.355))',0) union all select 'Complicated Polygon' as qType, geometry::STGeomFromText('POLYGON ((24.23 -10.83, 32.17 -12.89, 22.13 -29.44, 47.39 -35.11, 65.19 -21.21, 46.66 -27.6, 53.1 -12.5, 37.91 -17.61, 44.3 -4.65, 32.04 1.44, 24.23 -10.83))',0) ) select qType, [dbo].[STIsQuadrilateral](geom,1) as isQuadrilateral from data as a; GO qType isQuadrilateral Square 1 Rectangle 1 Isosceles Trapezium 1 Rhombus 1 Rectangle at Angle 1 Complicated Polygon 0

And here’s what each of these look like.

## Dependency

This function is used by STLineToCurve.

## Documentation

- MySQL Spatial General Function Documentation
- Oracle LRS Object 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