# SQL Extensions

HEAVY.AI implements a number of custom extension functions to SQL.

## Rendering

The following table describes SQL extensions available for the HEAVY.AI implementation of Vega.

### SQL SELECT

| Function                                                                                                                  | Arguments and Return                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `convert_meters_to_merc_pixel_width(meters, lon, lat,` *`min_lon`*`,` *`max_lon`*`,` *`img_width`*`,` *`min_width`*`)`    | <p>Converts a distance in meters in a longitudinal direction from a latitude/longitude coordinate to a pixel size using mercator projection:</p><ul><li><code>meters</code>: Distance in meters in a longitudinal direction to convert to pixel units.</li><li><code>lon</code>: Longitude coordinate of the center point to size from.</li><li><code>lat</code>: Latitude coordinate of the center point to size from.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>img\_width</code>: The width in pixels of the view.</li><li><code>min\_width</code>: Clamps the returned pixel size to be at least this width.</li></ul><p><strong>Returns:</strong> Floating-point value in pixel units. Can be used for the width of a symbol or a point in Vega.</p>                                                                                                                                                   |
| `convert_meters_to_merc_pixel_height(meters, lon, lat,` *`min_lat`*`,` *`max_lat`*`,` *`img_height`*`,` *`min_height`*`)` | <p>Converts a distance in meters in a latitudinal direction from a latitude/longitude coordinate to a pixel size, using mercator projection:</p><ul><li><code>meters</code>: Distance in meters in a longitudinal direction to convert to pixel units.</li><li><code>lon</code>: Longitude coordinate of the center point to size from.</li><li><code>lat</code>: Latitude coordinate of the center point to size from.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li><li><code>img\_height</code>: The height in pixels of the view.</li><li><code>min\_height</code>: Clamps the returned pixel size to be at least this height.</li></ul><p><strong>Returns:</strong> Floating-point value in pixel units. Can be used for the height of a symbol or a point in Vega.</p>                                                                                                                                                |
| `convert_meters_to_pixel_width(meters,` *`pt`*`,` *`min_lon`*`,` *`max_lon`*`,` *`img_width`*`,` *`min_width`*`)`         | <p>Converts a distance in meters in a longitudinal direction from a latitude/longitude POINT to a pixel size. Supports only mercator-projected points.</p><ul><li><code>meters</code>: Distance in meters in a latitudinal direction to convert to pixel units.</li><li><code>pt</code>: The center POINT to size from. The point must be defined in the EPSG:4326 spatial reference system.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>img\_width</code>: The width in pixels of the view.</li><li><code>min\_width</code>: Clamps the returned pixel size to be at least this width.</li></ul><p><strong>Returns:</strong> Floating-point value in pixel units. Can be used for the width of a symbol or a point in Vega.</p>                                                                                                                                                                              |
| `convert_meters_to_pixel_height(meters, pt,` *`min_lat`*`,` *`max_lat`*`,` *`img_height`*`,` *`min_height`*`)`            | <p>Converts a distance in meters in a latitudinal direction from an EPSG:4326 POINT to a pixel size. Currently only supports mercator-projected points:</p><ul><li><code>meters</code>: Distance in meters in a longitudinal direction to convert to pixel units.</li><li><code>pt</code>: The center POINT to size from. The point must be defined in the EPSG:4326 spatial reference system.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li><li><code>img\_height</code>: The height in pixels of the view.</li><li><code>min\_height</code>: Clamps the returned pixel size to be at least this height.</li></ul><p><strong>Returns:</strong> Floating-point value in pixel units. Can be used for the height of a symbol or a point in Vega.</p>                                                                                                                                                                         |
| `is_point_in_merc_view(lon, lat,` *`min_lon`*`,` *`max_lon`*`,` *`min_lat`*`,` *`max_lat`*`)`                             | <p>Returns true if a latitude/longitude coordinate is within a mercator-projected view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>.</p><ul><li><code>lon</code>: Longitude coordinate of the point.</li><li><code>lat</code>: Latitude coordinate of the point.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li></ul><p><strong>Returns:</strong>True if the point is within the view defined by the <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>; otherwise, false.</p>                                                                                                                                                          |
| `is_point_size_in_merc_view(lon, lat,` *`meters`*`,` *`min_lon`*`,` *`max_lon`*`,` *`min_lat`*`,` *`max_lat`*`)`          | <p>Returns true if a latitude/longitude coordinate, offset by a distance in meters, is within a mercator-projected view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>.</p><ul><li><code>lon</code>: Longitude coordinate of the point.</li><li><code>lat</code>: Latitude coordinate of the point.</li><li><code>meters</code>: Distance in meters to offset the point by, in any direction.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li></ul><p><strong>Returns:</strong> True if the point is within the view defined by the <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>; otherwise, false.</p>                              |
| `is_point_in_view(pt,` *`min_lon`*`,` *`max_lon`*`,` *`min_lat`*`,` *`max_lat`*`)`                                        | <p>Returns true if a latitude/longitude POINT defined in EPSG:4326 is within a mercator-projected view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>.</p><ul><li><code>pt</code>: The POINT to check. Must be defined in EPSG:4326 spatial reference system.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li></ul><p><strong>Returns:</strong> True if the point is within the view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>; otherwise, false.</p>                                                                                                                                                                  |
| `is_point_size_in_view(pt, meters,` *`min_lon`*`,` *`max_lon`*`,` *`min_lat`*`,` *`max_lat`*`)`                           | <p>Returns true if a latitude/longitude POINT defined in EPSG:4326 is within a mercator-projected view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>.</p><ul><li><code>pt</code>: The POINT to check. Must be defined in EPSG:4326 spatial reference system.</li><li><code>meters</code>: Distance in meters to offset the point by, in any direction.</li><li><code>min\_lon</code>: Minimum longitude coordinate of the mercator-projected view.</li><li><code>max\_lon</code>: Maximum longitude coordinate of the mercator-projected view.</li><li><code>min\_lat</code>: Minimum latitude coordinate of the mercator-projected view.</li><li><code>max\_lat</code>: Maximum latitude coordinate of the mercator-projected view.</li></ul><p><strong>Returns:</strong> True if a latitude/longitude POINT defined in EPSG:4326, offset by a distance in meters, is within the view defined by <code>min\_lon</code>/<code>max\_lon</code>, <code>min\_lat</code>/<code>max\_lat</code>; otherwise, false.</p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heavy.ai/v8.5.0/sql/data-manipulation-dml/sql-extensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
