Geometric and spatial data types for location-based applications.
Geometry classes provide support for spatial and geographic data using GeoJSON-compatible structures. These types are essential for location-based applications and geospatial queries.
line.close(); // Line now ends with GeometryPoint([0, 0])
Example
// Create a line (path between two cities) constline=newGeometryLine([ newGeometryPoint([-122.4194,37.7749]),// San Francisco newGeometryPoint([-118.2437,34.0522])// Los Angeles ]);
The underlying array of GeometryLine objects (outer boundary and optional holes).
Type:GeometryLine[]
coordinates
GeoJSON-compatible coordinates for this polygon.
Type:[number, number][][]
Example
// Create a triangle consttriangle=newGeometryPolygon([ newGeometryLine([ newGeometryPoint([0,0]), newGeometryPoint([4,0]), newGeometryPoint([2,3]), newGeometryPoint([0,0])// Close the polygon ]) ]);
GeoJSON-compatible coordinates for this multi-point.
Type:[number, number][]
Example
// Multiple store locations conststores=newGeometryMultiPoint([ newGeometryPoint([-122.4194,37.7749]),// SF newGeometryPoint([-118.2437,34.0522]),// LA newGeometryPoint([-87.6298,41.8781])// Chicago ]);
// Define service coverage area (polygon) constserviceArea=newGeometryPolygon([ newGeometryLine([ newGeometryPoint([-122.5,37.7]), newGeometryPoint([-122.3,37.7]), newGeometryPoint([-122.3,37.8]), newGeometryPoint([-122.5,37.8]), newGeometryPoint([-122.5,37.7])// Close the polygon ]) ]);
// Find locations near a point constcenterPoint=newGeometryPoint([-122.4194,37.7749]);
constnearbyLocations=awaitdb.query(` SELECT * FROM locations WHERE geo::distance(position, $center) < 5000 ORDER BY geo::distance(position, $center) `,{ center:centerPoint }).collect();
console.log('Nearby locations:',nearbyLocations);
Polygon Containment
// Check if a point is within a polygon constregion=newGeometryPolygon([ newGeometryLine([ newGeometryPoint([0,0]), newGeometryPoint([10,0]), newGeometryPoint([10,10]), newGeometryPoint([0,10]), newGeometryPoint([0,0]) ]) ]);
// Store multiple branch locations constbranches=newGeometryMultiPoint([ newGeometryPoint([-122.4194,37.7749]),// SF newGeometryPoint([-118.2437,34.0522]),// LA newGeometryPoint([-87.6298,41.8781]),// Chicago newGeometryPoint([-74.0060,40.7128])// NYC ]);
// Calculate distance between two points constpointA=newGeometryPoint([-122.4194,37.7749]);// SF constpointB=newGeometryPoint([-118.2437,34.0522]);// LA
// Good: First and last points are the same constpolygon=newGeometryPolygon([ newGeometryLine([ newGeometryPoint([0,0]), newGeometryPoint([10,0]), newGeometryPoint([10,10]), newGeometryPoint([0,10]), newGeometryPoint([0,0])// Closes the polygon ]) ]);
// The library automatically closes polygons if needed
3. Use Appropriate Geometry Type
// Good: Single location constoffice=newGeometryPoint([-122.4194,37.7749]);
// Avoid: Invalid coordinates (out of range) // Longitude: -180 to 180, Latitude: -90 to 90 constinvalid=newGeometryPoint([200,100]);// Will create but may cause issues
Use Cases
Location-based Services - Store and query business locations
Delivery Systems - Define delivery routes and service areas
Real Estate - Property boundaries and service zones
Transportation - Transit routes and coverage areas