Code Monkey home page Code Monkey logo

fluent-postgis's Introduction

FluentPostGIS

Platforms Package Managers

A fork of the FluentPostGIS package which adds support for geographic queries. FluentPostGIS provides PostGIS support for fluent-postgres-driver and Vapor 4.

Installation

Swift Package Manager

Add this line to your dependencies in Package.swift:

.package(url: "https://github.com/brokenhandsio/fluent-postgis.git", from: "0.3.0")

Then add this line to a target's dependencies:

.product(name: "FluentPostGIS", package: "fluent-postgis"),

Setup

Import module

import FluentPostGIS

Optionally, you can add a Migration to enable PostGIS:

app.migrations.add(EnablePostGISMigration())

Models

Add a type to your model

final class User: Model {
    static let schema = "user"
    
    @ID(key: .id)
    var id: UUID?

    @Field(key: "location")
    var location: GeometricPoint2D
}

Then use its data type in the Migration:

struct UserMigration: AsyncMigration {
    func prepare(on database: Database) async throws -> {
        try await database.schema(User.schema)
            .id()
            .field("location", .geometricPoint2D)
            .create()
    }
    func revert(on database: Database) async throws -> {
        try await database.schema(User.schema).delete()
    }
}
Geometric Types Geographic Types
GeometricPoint2D GeographicPoint2D
GeometricLineString2D GeographicLineString2D
GeometricPolygon2D GeographicPolygon2D
GeometricMultiPoint2D GeographicMultiPoint2D
GeometricMultiLineString2D GeographicMultiLineString2D
GeometricMultiPolygon2D GeographicMultiPolygon2D
GeometricGeometryCollection2D GeographicGeometryCollection2D

Queries

Query using any of the filter functions:

let eiffelTower = GeographicPoint2D(longitude: 2.2945, latitude: 48.858222)
try await User.query(on: database)
    .filterGeographyDistanceWithin(\.$location, eiffelTower, 1000)
    .all()
Queries
filterGeometryContains
filterGeometryCrosses
filterGeometryDisjoint
filterGeometryDistance
filterGeometryDistanceWithin
filterGeographyDistanceWithin
filterGeometryEquals
filterGeometryIntersects
filterGeometryOverlaps
filterGeometryTouches
filterGeometryWithin
sortByDistance

๐Ÿ’ Contributing

Please create an issue with a description of your problem or open a pull request with a fix.

โœŒ๏ธ License

MIT

๐Ÿ‘ฝ Author

BrokenHands, Tim Condon, Nikolai Guyot - https://www.brokenhands.io/ Ricardo Carvalho - https://rabc.github.io/ Phil Larson - http://dizm.com

fluent-postgis's People

Contributors

0xtim avatar joeblau avatar plarson avatar poshalpaca avatar rabc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.