geometryUtils
- Description:
Utility functions for fetching, converting, and buffering geometry data.
- Source:
Members
(static, constant) fromProjection :string
- Description:
Projection system for converting coordinates from WKID 3361 to WGS84.
- Source:
Projection system for converting coordinates from WKID 3361 to WGS84.
Type:
- string
(static, constant) toProjection :string
- Description:
WGS84 projection used as the target projection.
- Source:
WGS84 projection used as the target projection.
Type:
- string
Methods
(static) calculateCentroid(polyline) → {Point2d|null}
- Description:
Calculates the centroid of a closed polyline.
- Source:
Example
const polyline = [
{ x: 0, y: 0 },
{ x: 4, y: 0 },
{ x: 4, y: 3 },
{ x: 0, y: 3 },
{ x: 0, y: 0 }
];
const centroid = calculateCentroid(polyline);
console.log(centroid); // { x: 2, y: 1.5 }
Parameters:
Name | Type | Description |
---|---|---|
polyline |
Polyline | An array of points representing the polyline. |
Throws:
-
Throws an error if the polyline has fewer than 3 vertices.
- Type
- Error
Returns:
The centroid as a Point2d, or null
if the polyline is invalid.
- Type
- Point2d | null
(static) convertRingsToPolyline(rings) → {Polyline}
- Description:
Converts a rings array to a Polyline format.
- Source:
Example
const rings = [
[
[0, 0],
[4, 0],
[4, 3],
[0, 3],
[0, 0]
]
];
const polyline = convertRingsToPolyline(rings);
console.log(polyline);
// Output: [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 3 }, { x: 0, y: 3 }, { x: 0, y: 0 }]
Parameters:
Name | Type | Description |
---|---|---|
rings |
Array.<Array.<Array.<number>>> | An array representing rings of points in the form [[[x, y], [x, y], ...]]. |
Throws:
-
Throws an error if the input is invalid.
- Type
- Error
Returns:
A Polyline array with points in {x, y}
format.
- Type
- Polyline
(static) feetToDegrees(feet) → {number}
- Description:
Converts a distance from feet to degrees.
- Source:
Example
const degrees = feetToDegrees(5280); // Convert 1 mile to degrees
console.log(degrees); // Approx. 0.014472
Parameters:
Name | Type | Description |
---|---|---|
feet |
number | The distance in feet to be converted. |
Returns:
The equivalent distance in degrees.
- Type
- number
(async, static) fetchConvertAndBufferGeometry(region, pin, bufferFeet) → {Promise.<Buffer>}
- Description:
Fetches geometry data for a given region and PIN, converts coordinates from WKID 3361 to WGS84, calculates the centroid, and generates a buffered polygon around the centroid.
- Source:
Example
const region = "horry";
const pin = "12345";
const bufferFeet = 100;
const bufferedPolygon = await fetchConvertAndBufferGeometry(region, pin, bufferFeet);
console.log(bufferedPolygon);
// Output: [
// [-79.2, 34.0],
// [-79.2, 34.1],
// [-79.1, 34.1],
// [-79.1, 34.0],
// [-79.2, 34.0]
// ]
Parameters:
Name | Type | Description |
---|---|---|
region |
string | The region identifier for the API request. |
pin |
string | The PIN identifier for the API request. |
bufferFeet |
number | The buffer distance in feet. |
Throws:
-
Throws an error if data fetching or processing fails.
- Type
- Error
Returns:
A promise resolving to a polygon array representing the buffered region.
- Type
- Promise.<Buffer>