All Projects → jsor → Doctrine Postgis

jsor / Doctrine Postgis

Licence: mit
Spatial and Geographic Data with PostGIS and Doctrine.

Projects that are alternatives of or similar to Doctrine Postgis

Docker Postgres
A docker container running PostgreSQL
Stars: ✭ 22 (-86.34%)
Mutual labels:  postgis, database, postgresql, postgres
Squid
🦑 Provides SQL tagged template strings and schema definition functions.
Stars: ✭ 57 (-64.6%)
Mutual labels:  database, postgresql, postgres
Postgres Meta
A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries
Stars: ✭ 146 (-9.32%)
Mutual labels:  database, postgresql, postgres
Laravel Scout Postgres
PostgreSQL Full Text Search Engine for Laravel Scout
Stars: ✭ 140 (-13.04%)
Mutual labels:  database, postgresql, postgres
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+511.18%)
Mutual labels:  database, postgresql, postgres
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-75.78%)
Mutual labels:  database, postgresql, postgres
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+686.96%)
Mutual labels:  database, postgresql, postgres
Pg flame
A flamegraph generator for Postgres EXPLAIN ANALYZE output.
Stars: ✭ 1,391 (+763.98%)
Mutual labels:  database, postgresql, postgres
Activerecord Clean Db Structure
Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
Stars: ✭ 101 (-37.27%)
Mutual labels:  database, postgresql, postgres
Pgcli
Postgres CLI with autocompletion and syntax highlighting
Stars: ✭ 9,985 (+6101.86%)
Mutual labels:  database, postgresql, postgres
Awesome Postgres
A curated list of awesome PostgreSQL software, libraries, tools and resources, inspired by awesome-mysql
Stars: ✭ 7,468 (+4538.51%)
Mutual labels:  database, postgresql, postgres
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (-31.68%)
Mutual labels:  database, postgresql, postgres
Go Kallax
Kallax is a PostgreSQL typesafe ORM for the Go language.
Stars: ✭ 853 (+429.81%)
Mutual labels:  database, postgresql, postgres
Postgresclientkit
A PostgreSQL client library for Swift. Does not require libpq.
Stars: ✭ 49 (-69.57%)
Mutual labels:  database, postgresql, postgres
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+420.5%)
Mutual labels:  database, postgresql, postgres
Plv8
V8 Engine Javascript Procedural Language add-on for PostgreSQL
Stars: ✭ 1,195 (+642.24%)
Mutual labels:  database, postgresql, postgres
Metabase
The simplest, fastest way to get business intelligence and analytics to everyone in your company 😋
Stars: ✭ 26,803 (+16547.83%)
Mutual labels:  database, postgresql, postgres
Efcore.pg
Entity Framework Core provider for PostgreSQL
Stars: ✭ 838 (+420.5%)
Mutual labels:  database, postgresql, postgres
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+11184.47%)
Mutual labels:  database, postgresql, postgres
Libpq.jl
A Julia wrapper for libpq
Stars: ✭ 109 (-32.3%)
Mutual labels:  database, postgresql, postgres

PostGIS extension for Doctrine

Build Status Coverage Status

This library allows you to use Doctrine with PostGIS, the spatial database extension for PostgreSQL. Both PostGIS 1.5 and 2.x are supported.

Installation

Install the latest version with Composer.

composer require jsor/doctrine-postgis

Check the Packagist page for all available versions.

Setup

All you have to do is, to register an event subscriber.

use Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber;

$entityManager->getEventManager()->addEventSubscriber(new ORMSchemaEventSubscriber());

You can also use this library with the DBAL only.

use Jsor\Doctrine\PostGIS\Event\DBALSchemaEventSubscriber;

$connection->getEventManager()->addEventSubscriber(new DBALSchemaEventSubscriber());

Symfony 5

If you use Symfony, see the documentation on how to register event subscribers.

A setup could look like this in the services.yml.

services:
    Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber:
        tags:
            - { name: doctrine.event_subscriber, connection: default }

It is also recommended to register the DBAL types in the doctrine section of the config/packages/doctrine.yaml config file.

doctrine:
    dbal:
        types:
            geography:
                class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
                commented: false
            geometry:
                class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
                commented: false
            raster:
                class: 'Jsor\Doctrine\PostGIS\Types\RasterType'
                commented: false

Migrations (🔥 important 🔥)

By default, Symfony's console commands make:migrations and doctrine:migrations:diff would try to drop everything in the tiger, tiger_data and topology schemas. This can be avoided by using the schema_filter option to the aforementioned config/packages/doctrine.yaml file, e.g. like this:

doctrine:
    dbal:
        schema_filter: ~^(?!tiger)(?!topology)~

The above value (~^(?!tiger)(?!topology)~) uses lookahead regular expressions to filter out all the namespaced tables beginning with "tiger" and "topology".

See also: Manual tables in Symfony Docs.

Mapping types

In the aforementioned config/packages/doctrine.yaml file, please add the following lines:

doctrine:
    dbal:
        mapping_types:
            _text: string

Property Mapping

Once the event subscriber is registered, you can use the column types geometry and geography in your property mappings (please read the PostGIS docs to understand the difference between these two types).

/** @Entity */
class MyEntity
{
    /**
     * @Column(type="geometry")
     */
    private $geometry;

    /**
     * @Column(type="geography")
     */
    private $geography;
}

There are 2 options you can set to define the geometry.

  • geometry_type This defines the type of the geometry, like POINT, LINESTRING etc. If you omit this option, the generic type GEOMETRY is used.
  • srid This defines the Spatial Reference System Identifier (SRID) of the geometry.

Example

/** @Entity */
class MyEntity
{
    /**
     * @Column(type="geometry", options={"geometry_type"="POINT"})
     */
    private $point;

    /**
     * @Column(type="geometry", options={"geometry_type"="POINTZM"})
     */
    private $point4D;

    /**
     * @Column(type="geometry", options={"geometry_type"="POINT", "srid"=3785})
     */
    private $pointWithSRID;
}

Values provided for the properties must be in the WKT format. Please note, that the values returned from database may differ from the values you have set. The library uses ST_AsEWKT to retain as much information as possible (like SRID's). Read more in the PostGIS docs.

Example

$entity = new MyEntity();

$entity->setPoint('POINT(37.4220761 -122.0845187)');
$entity->setPoint4D('POINT(1 2 3 4)');
$entity->setPointWithSRID('SRID=3785;POINT(37.4220761 -122.0845187)');

Spatial Indexes

You can define spatial indexes for your geometry columns.

Simply set the spatial flag for indexes.

/**
 * @Entity
 * @Table(
 *     indexes={
 *         @Index(name="idx_point", columns={"point"}, flags={"spatial"}),
 *         @Index(name="idx_polygon", columns={"polygon"}, flags={"spatial"})
 *     }
 * )
 */
class MyEntity
{
}

This uses index flags introduced in Doctrine ORM 2.5.

If you need to support Doctrine versions < 2.5, you have to define which indexes should be spatial indexes through the table options.

/**
 * @Entity
 * @Table(
 *     options={"spatial_indexes"={"idx_point", "idx_polygon"}},
 *     indexes={
 *         @Index(name="idx_point", columns={"point"}),
 *         @Index(name="idx_polygon", columns={"polygon"})
 *     }
 * )
 */
class MyEntity
{
}

Schema Tool

Full support for the ORM Schema Tool and the DBAL Schema Manager is provided.

DQL Functions

Most PostGIS functions are also available for the DQL under the Jsor\Doctrine\PostGIS\Functions namespace.

For a full list of all supported functions, see the Function Index.

You can register the functions with a Doctrine\ORM\Configuration instance.

$configuration = new Doctrine\ORM\Configuration();

$configuration->addCustomStringFunction(
    'ST_Distance',
    'Jsor\Doctrine\PostGIS\Functions\ST_Distance'
);

$dbParams = [/***/];
$entityManager = Doctrine\ORM\EntityManager::create($dbParams, $configuration);

There's a convenience Configurator class which can be used to register all at once.

$configuration = new Doctrine\ORM\Configuration();

Jsor\Doctrine\PostGIS\Functions\Configurator::configure($configuration);

$dbParams = [/***/];
$entityManager = Doctrine\ORM\EntityManager::create($dbParams, $configuration);

Symfony

If you use Symfony, you need to setup the functions in the doctrine section of the config.yml.

doctrine:
    orm:
        dql:
            string_functions:
                ST_Distance: Jsor\Doctrine\PostGIS\Functions\ST_Distance

License

Copyright (c) 2014-2019 Jan Sorgalla. Released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].