liveBook · Manning

Polygon

As explained in Just Use Postgres!

A polygon is a closed two-dimensional geometric figure represented by connected line segments and used to model planar areas.

A polygon is a closed two-dimensional figure formed by connected straight line segments. In geospatial systems, polygons model planar areas such as buildings, parks, lakes, cities, states, and theme parks. section 10.1 section 10.3.3

Use polygons to represent boundaries and query the areas they enclose:

  • Represent a polygon with three or more points; rectangles are polygons whose opposite sides are equal and parallel. section 10.1 section 10.1.1
  • Store polygon boundaries in a PostGIS geometry column, where the SRID determines the units used by measurements such as area. section 10.3.3 section 10.5.2
  • Inspect complexity with ST_NPoints, measure extent with ST_Area, and find contained regions with ST_Within. section 10.5.2
  • Distinguish a polygon from a MultiPolygon, which represents a collection of non-overlapping and non-adjacent polygons. section 10.3.3

Measure a theme-park polygon

Query the Walt Disney World boundary, then convert its SRID-based area from square meters into square kilometers and acres. The result contains 473 points and reports approximately 96.08 square kilometers, or 23,741.93 acres.

Find polygons and objects inside them

Use ST_Within to find distinct theme parks inside the Walt Disney World boundary, excluding the boundary itself with ST_Equals. The same pattern finds attractions or point amenities inside a specific park.

Table 10.1 Postgres geometric data types

Type name

Description

Input format

point

A point on a 2D plane

(x, y)

line

An infinite straight line in 2D space

{A, B, C} where Ax + By + C = 0

lseg

A finite line segment between two points

[(x1, y1), (x2, y2)]

box

A rectangle defined by two opposite corners

((x1, y1), (x2, y2))

path

An open or closed path defined as a sequence of connected points

open path: [(x1, y1), (x2, y2), ...]

closed path: ((x1, y1), (x2, y2), ...)

polygon

A closed polygon with three or more points

((x1, y1), (x2, y2), ...)

circle

A circle with a center and a radius

<(x, y), r>

Use the geometric-type table to compare polygon input syntax with points, line segments, boxes, paths, and circles. section 10.1.1

How Just Use Postgres! covers it

How deep it goes
Defines polygon structure, storage, measurement, point counts, containment, and equality, while deferring deeper GIS and Earth-curvature treatment.
Examples
Uses buildings, parks, lakes, city boundaries, Walt Disney World, nested theme parks, attractions, and amenities.
What it assumes
Assumes basic two-dimensional geometry and SQL familiarity while introducing polygon storage, spatial predicates, and SRID-based measurement.
What you can do after
Apply it via PostGIS functions to measure polygon areas, count boundary points, and identify geometries contained within boundaries.
How it connects
Connects polygons with geometry, MultiPolygon, PostGIS, spatial reference systems, GIS, points, and spatial containment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.