Point
What is a Point?
Section titled “What is a Point?”A Point represents a single geographic location on Earth’s surface defined by a longitude and latitude pair.
- Longitude (east-west position): ranges from -180° to 180°
- Latitude (north-south position): ranges from -90° to 90°
Use Points to represent discrete locations like addresses, landmarks, device positions, or any fixed geographic location.
Creating a Point
Section titled “Creating a Point”Create a point with longitude and latitude:
import { Point } from '@cratis/fundamentals';
const location = new Point(10.5, 20.3);
console.log(location.longitude); // 10.5console.log(location.latitude); // 20.3The first parameter is longitude, the second is latitude.
Using Points in Classes
Section titled “Using Points in Classes”Points work as properties in your classes:
import { Point, field } from '@cratis/fundamentals';
class Location { @field(String) name!: string;
@field(Point) position!: Point;}
const office = new Location();office.name = 'Headquarters';office.position = new Point(10.7522, 59.9139); // Oslo, NorwayAccessing Coordinates
Section titled “Accessing Coordinates”Access and work with a Point’s coordinates:
import { Point } from '@cratis/fundamentals';
const location = new Point(10.5, 20.3);const longPart = location.longitude;const latPart = location.latitude;
// Create new Point from existingconst adjusted = new Point(longPart + 0.1, latPart + 0.1);Serialization
Section titled “Serialization”Points automatically serialize to GeoJSON format. See Geospatial Serialization for details on JSON handling.