Class: QgsClipper

class qgis.core.QgsClipper

Bases: sip.wrapper

A class to trim lines and polygons to within a rectangular region.

The functions in this class are likely to be called from within a render loop and hence need to as CPU efficient as possible. The main purpose of the functions in this class are to trim lines and polygons to lie within a rectangular region. This is necessary for drawing items to an X11 display which have a limit on the magnitude of the screen coordinates (+/- 32768, i.e. 16 bit integer).

Methods

clipLineSegment

Clips a line segment to a rectangle.

clippedLine

Takes a linestring and clips it to clipExtent

trimFeature

Trims the given feature to a rectangular box.

trimPolygon

Trims the given polygon to a rectangular box, by modifying the given polygon in place.

Attributes

MAX_X

MAX_Y

MIN_X

MIN_Y

XMax

XMin

YMax

YMin

ZMax

ZMin

class Boundary

Bases: int

MAX_X = 16000.0
MAX_Y = 16000.0
MIN_X = -16000.0
MIN_Y = -16000.0
XMax = 0
XMin = 1
YMax = 2
YMin = 3
ZMax = 4
ZMin = 5
clipLineSegment(left: float, right: float, bottom: float, top: float, x0: float, y0: float, x1: float, y1: float)

Clips a line segment to a rectangle.

An implementation of the ‘Fast clipping’ algorithm (Sobkow et al. 1987, Computers & Graphics Vol.11, 4, p.459-467).

Parameters:
  • left (float) – x-coordinate of left side of rectangle

  • right (float) – x-coordinate of right side of rectangle

  • bottom (float) – y-coordinate of bottom side of rectangle

  • top (float) – y-coordinate of top side of rectangle

  • x0 (float) – x-coordinate of start of line

  • y0 (float) – y-coordinate of start of line

  • x1 (float) – x-coordinate of end of line

  • y1 (float) -> (bool) – y-coordinate of end of line

Returns:

True if line was clipped.

Added in version 3.26.

clippedLine(curve: QgsCurve, clipExtent: QgsRectangle) QPolygonF

Takes a linestring and clips it to clipExtent

Parameters:
Returns:

clipped line coordinates

clippedLine(curve: QPolygonF, clipExtent: QgsRectangle) -> QPolygonF Takes a 2D curve and clips it to clipExtent.

Parameters:
  • curve – the linestring

  • clipExtent – clipping bounds

Return type:

QPolygonF

Returns:

clipped line coordinates

Added in version 3.16.

trimFeature(x: Iterable[float], y: Iterable[float], shapeOpen: bool)

Trims the given feature to a rectangular box. Returns the trimmed feature in x and y. The shapeOpen parameter determines whether the function treats the points as a closed shape (polygon), or as an open shape (linestring).

Note

not available in Python bindings on android

Parameters:
  • x (Iterable[float])

  • y (Iterable[float])

  • shapeOpen (bool)

trimPolygon(pts: QPolygonF, clipRect: QgsRectangle)

Trims the given polygon to a rectangular box, by modifying the given polygon in place.

Parameters:
  • pts (QPolygonF) – polygon as 2D coordinates

  • clipRect (QgsRectangle) – clipping rectangle