Giter VIP home page Giter VIP logo

fluent-postgis's Introduction

FluentPostGIS

Platforms Package Managers Twitter rabc

PostGIS support for fluent-postgres-driver and Vapor 4

Installation

Swift Package Manager

.package(url: "https://github.com/rafaellevy/fluent-postgis.git", .branch("master"))

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 UserLocation: Model {
    static let schema = "user_location"
    
    @ID(custom: "id", generatedBy: .database)
    var id: Int?
    @Field(key: "location")
    var location: GeometricPoint2D
}

Then use its data type in the Migration:

struct UserLocationMigration: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return database.schema(UserLocation.schema)
            .field("id", .int, .identifier(auto: true))
            .field("location", GeometricPoint2D.dataType)
            .create()
    }
    func revert(on database: Database) -> EventLoopFuture<Void> {
        return database.schema(UserLocation.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 searchLocation = GeometricPoint2D(x: 1, y: 2)
try UserLocation.query(on: conn).filterGeometryDistanceWithin(\.$location, user.location, 1000).all().wait()
Queries
filterGeometryContains
filterGeometryCrosses
filterGeometryDisjoint
filterGeometryDistance
filterGeometryDistanceWithin
filterGeometryEquals
filterGeometryIntersects
filterGeometryOverlaps
filterGeometryTouches
filterGeometryWithin

💝 Contributing

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

✌️ License

MIT

👽 Author

Ricardo Carvalho - https://rabc.github.io/ Phil Larson - http://dizm.com

fluent-postgis's People

Contributors

plarson avatar rabc avatar rafaellevy avatar joeblau avatar

Stargazers

Mikk Rätsep 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.