PostGIS support for fluent-postgres-driver and Vapor 4
.package(url: "https://github.com/rafaellevy/fluent-postgis.git", .branch("master"))
Import module
import FluentPostGIS
Optionally, you can add a Migration
to enable PostGIS:
app.migrations.add(EnablePostGISMigration())
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 |
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 |
Please create an issue with a description of your problem or open a pull request with a fix.
MIT
Ricardo Carvalho - https://rabc.github.io/ Phil Larson - http://dizm.com
fluent-postgis's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.