gws.lib.uom

Source code: gws.lib.uom

Package Contents

gws.lib.uom.DEFAULT_PRECISION
gws.lib.uom.MM_PER_IN = 25.4

Conversion factor from inch to millimetre

gws.lib.uom.mm_to_px(x: _number, ppi: int) float

Converts millimetres to pixel.

Parameters:
  • x – Millimetres.

  • ppi – Pixels per inch.

Returns:

Amount of pixels.

gws.lib.uom.OGC_M_PER_PX = 0.00028

1px = 0.28mm).

Type:

OGC meter per pixel (OGC 06-042, 7.2.4.6.9

gws.lib.uom.OGC_SCREEN_PPI

Pixel per inch on screen using the Open Geospatial Consortium standard

gws.lib.uom.parse(s: str | int | float, default_unit: gws.Uom = None) gws.UomValue

Parse a measurement in the string or numeric form.

Parameters:
  • s – A measurement to parse.

  • default_unit – Default unit.

Returns:

A measurement.

Raises:

ValueError – if the unit is missing, if the formatting is wrong or if the unit is invalid.

gws.lib.uom.PDF_DPI = 96

Dots per inch in a pdf file

gws.lib.uom.PT_PER_IN = 72

Conversion factor from inch to points

gws.lib.uom.px_to_mm(x: _number, ppi: int) float

Converts pixel to millimetres.

Parameters:
  • x – Amount of pixels.

  • ppi – Pixel per inch.

Returns:

Amount of millimetres.

gws.lib.uom.res_to_scale(x: _number) int

Converts the user’s resolution to the scale.

Parameters:

x – Resolution in pixel per inch.

Returns:

Scale.

gws.lib.uom.scale_to_res(x: _number) float

Converts the scale to the user’s resolution.

Parameters:

x – Scale.

Returns:

Resolution in pixel.

gws.lib.uom.size_mm_to_px(xy: gws.Size, ppi: int) gws.Size

Converts a rectangle description in millimetres to pixels.

Parameters:
  • xy – A rectangle measurements in mm.

  • ppi – Pixels per inch.

Returns:

A rectangle in pixel.

gws.lib.uom.size_px_to_mm(xy: gws.Size, ppi: int) gws.Size

Converts a rectangle description in pixel to millimetres.

Parameters:
  • xy – A rectangle measurements in pixels.

  • ppi – Pixel per inch

Returns:

The rectangle measurements in millimetres.

gws.lib.uom.size_to_mm(xyu: gws.UomSize, ppi: int) gws.UomSize

Converts a rectangle description of any unit to millimetres.

Parameters:
  • xyu – A rectangle measurements with its unit.

  • ppi – Pixels per inch.

Returns:

The rectangle measurements in millimetres.

Raises:

ValueError – if the unit is invalid.

gws.lib.uom.size_to_px(xyu: gws.UomSize, ppi: int) gws.UomSize

Converts a rectangle description of any unit to pixels.

Parameters:
  • xyu – A rectangle measurements with its unit.

  • ppi – Pixels per inch.

Returns:

The rectangle measurements in pixels.

gws.lib.uom.to_mm(xu: gws.UomValue, ppi: int) gws.UomValue

Converts a measurement of any unit to millimetres.

Parameters:
  • xu – A measurement to convert.

  • ppi – Pixels per inch.

Returns:

A measurement.

gws.lib.uom.to_px(xu: gws.UomValue, ppi: int) gws.UomValue

Converts a measurement to amount of pixels.

Parameters:
  • xu – A measurement to convert to pixels.

  • ppi – Pixels per inch.

Returns:

A measurement.

gws.lib.uom.to_str(xu: gws.UomValue) str

Converts a to a string.

Parameters:

xu – A measurement to convert.

Returns:

The input tuple as a string, like ‘5mm’.