All examples
Scientific computing

Checked positions and geographic bounds

Construct WGS84 positions, test wrapped extents and calculate an explicitly spherical distance.

geo_positions.aner
// Requires the updated native development runtime with aner.geo.
// Coordinates are illustrative city centers, not survey or GPS observations.
import aner.geo
import aner.units

let boulder: GeoPosition = geo.position(longitude: -105.2705, latitude: 40.0150)
let sanFrancisco = geo.position(longitude: -122.4194, latitude: 37.7749)
let losAngeles = geo.position(longitude: -118.2437, latitude: 34.0522)
let paloAlto = geo.position(longitude: -122.1430, latitude: 37.4419)
let boulderView: GeoExtent = geo.extent(west: -105.35, south: 39.95, east: -105.18, north: 40.10)

print(type(boulder))
print(boulder)
print(boulder.longitude())
print(boulder.latitude())
print(boulder.geojson())
print(boulderView.contains(boulder))
print(boulderView.contains(sanFrancisco))

// A named spherical model returns physical units rather than raw degrees.
let separation: Quantity<m> = geo.great_circle_distance(sanFrancisco, paloAlto)
print(separation.to("km"))
print(losAngeles.great_circle_distance(boulder).to("km"))
print(boulder.great_circle_distance(boulder) == 0.0@m)

// A wrapped extent represents a narrow Pacific interval around the dateline.
let pacific = geo.extent(170.0, -20.0, -170.0, 20.0)
print(pacific.contains(geo.position(179.0, 0.0)))
print(pacific.contains(geo.position(-179.0, 0.0)))
print(pacific.contains(geo.position(0.0, 0.0)))

// Keep station identity and observation metadata separate from its location.
class Station {
    public let id: String
    public let position: GeoPosition
    public let temperature: Point<degC>
}
let station = Station(id: "synthetic-boulder-01", position: boulder, temperature: 20.0@degC)
print(station.id)
print(station.position.geojson())
print(station.temperature)
let locations = List(boulder, sanFrancisco, losAngeles, paloAlto)
let restored: GeoPosition = cast<GeoPosition>(locations.get(0))
print(restored == boulder)

// No longitude/latitude vector arithmetic, geocoder or implicit CRS conversion.
// Great-circle distance uses a 6371008.8m sphere, ignoring altitude/ellipsoid.
// See docs/GEOGRAPHIC_TYPES.md before selecting a method for scientific analysis.

Make it your experiment.

With Aner 0.0.3 or newer installed, save this program as examples/geo_positions.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/geo_positions.aner
aner run examples/geo_positions.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires the current native Aner runtime with the documented API. Keep the source directory structure and review the guide for data, optional map packs and output files before running. Earlier release binaries may predate these features.

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner