{"id":16894278,"url":"https://github.com/jsor/doctrine-postgis","last_synced_at":"2025-05-16T05:04:11.466Z","repository":{"id":15188212,"uuid":"17916279","full_name":"jsor/doctrine-postgis","owner":"jsor","description":"Spatial and Geographic Data with PostGIS and Doctrine.","archived":false,"fork":false,"pushed_at":"2024-09-09T07:04:30.000Z","size":711,"stargazers_count":212,"open_issues_count":12,"forks_count":55,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-16T05:03:32.708Z","etag":null,"topics":["database","doctrine","geography","geometry","php","postgis","postgres","postgresql","spatial"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-19T18:50:16.000Z","updated_at":"2025-03-25T18:17:37.000Z","dependencies_parsed_at":"2024-02-20T15:28:07.130Z","dependency_job_id":"9e0c8709-47ca-4f99-ab8e-d7f8e0bdefcc","html_url":"https://github.com/jsor/doctrine-postgis","commit_stats":{"total_commits":266,"total_committers":11,"mean_commits":"24.181818181818183","dds":0.06015037593984962,"last_synced_commit":"3dac2315d0e398d3029dd862eaedd94298b545cb"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fdoctrine-postgis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fdoctrine-postgis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fdoctrine-postgis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fdoctrine-postgis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsor","download_url":"https://codeload.github.com/jsor/doctrine-postgis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","doctrine","geography","geometry","php","postgis","postgres","postgresql","spatial"],"created_at":"2024-10-13T17:18:13.166Z","updated_at":"2025-05-16T05:04:11.411Z","avatar_url":"https://github.com/jsor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PostGIS extension for Doctrine\n==============================\n\n[![Build Status](https://github.com/jsor/doctrine-postgis/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsor/doctrine-postgis/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/jsor/doctrine-postgis/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/jsor/doctrine-postgis?branch=main)\n\nThis library allows you to use [Doctrine](https://www.doctrine-project.org/)\n(ORM or DBAL) with [PostGIS](https://postgis.net/), the spatial database\nextension for [PostgreSQL](https://www.postgresql.org/).\n\n* [Supported Versions](#supported-versions)\n* [Installation](#installation)\n* [Setup](#setup)\n  * [Symfony](#symfony)\n* [Property Mapping](#property-mapping)\n* [Spatial Indexes](#spatial-indexes)\n* [Schema Tool](#schema-tool)\n* [DQL Functions](#dql-functions)\n* [Known Problems](#known-problems)\n* [Running the Tests](#running-the-tests)\n\nSupported Versions\n--\n\nThe following table shows the versions which are officially supported by this\nlibrary.\n\n| Dependency    | Supported Versions  |\n|:--------------|:--------------------|\n| PostGIS       | 3.0 and 3.1         |\n| PostgreSQL    | 11, 12 and 13       |\n| Doctrine ORM  | ^2.9                |\n| Doctrine DBAL | ^2.13 and ^3.1      |\n\nInstallation\n--\n\nInstall the latest version with [Composer](https://getcomposer.org).\n\n```bash\ncomposer require jsor/doctrine-postgis\n```\n\nCheck the [Packagist page](https://packagist.org/packages/jsor/doctrine-postgis)\nfor all available versions.\n\nSetup\n--\n\nTo use the library with the Doctrine ORM, register the\n`ORMSchemaEventSubscriber` event subscriber.\n\n```php\nuse Jsor\\Doctrine\\PostGIS\\Event\\ORMSchemaEventSubscriber;\n\n$entityManager-\u003egetEventManager()-\u003eaddEventSubscriber(new ORMSchemaEventSubscriber());\n```\n\nTo use it with the DBAL only, register the `DBALSchemaEventSubscriber` event\nsubscriber.\n\n```php\nuse Jsor\\Doctrine\\PostGIS\\Event\\DBALSchemaEventSubscriber;\n\n$connection-\u003egetEventManager()-\u003eaddEventSubscriber(new DBALSchemaEventSubscriber());\n```\n### Symfony\n\nFor integrating this library into a Symfony project, read the dedicated\n[Symfony Documentation](docs/symfony.md).\n\nProperty Mapping\n--\n\nOnce the event subscriber is registered, the column types `geometry` and\n`geography` can be used in property mappings (please read the\n[PostGIS docs](https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography)\nto understand the difference between these two types).\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Jsor\\Doctrine\\PostGIS\\Types\\PostGISType;\n\n#[ORM\\Entity]\nclass MyEntity\n{\n    #[ORM\\Column(type: PostGISType::GEOMETRY)]\n    private string $geometry;\n\n    #[ORM\\Column(type: PostGISType::GEOGRAPHY)]\n    private string $geography;\n}\n```\n\nThere are 2 options to configure the geometry.\n\n* `geometry_type`\n   This defines the type of the geometry, like `POINT`, `LINESTRING` etc.\n   If you omit this option, the generic type `GEOMETRY` is used.\n* `srid`\n   This defines the Spatial Reference System Identifier (SRID) of the geometry.\n\n### Example\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Jsor\\Doctrine\\PostGIS\\Types\\PostGISType;\n\n#[ORM\\Entity]\nclass MyEntity\n{\n    #[ORM\\Column(\n        type: PostGISType::GEOMETRY, \n        options: ['geometry_type' =\u003e 'POINT'],\n    )]\n    public string $point;\n\n    #[ORM\\Column(\n        type: PostGISType::GEOMETRY, \n        options: ['geometry_type' =\u003e 'POINTZM'],\n   )]\n    public string $point4D;\n\n    #[ORM\\Column(\n        type: PostGISType::GEOMETRY, \n        options: ['geometry_type' =\u003e 'POINT', 'srid' =\u003e 3785],\n    )]\n    public string $pointWithSRID;\n\n    public function __construct(\n        string $point,\n        string $point4D,\n        string $pointWithSRID,\n    ) {\n        $this-\u003epoint = $point;\n        $this-\u003epoint4D = $point4D;\n        $this-\u003epointWithSRID = $pointWithSRID;\n    }\n}\n```\n\nValues provided for the properties must be in the [WKT](https://en.wikipedia.org/wiki/Well-known_text)\nformat. Please note, that the values returned from database may differ from the\nvalues you have set. The library uses [ST_AsEWKT](https://postgis.net/docs/ST_AsEWKT.html)\nto retain as much information as possible (like SRID's). Read more in the\n[PostGIS docs](https://postgis.net/docs/using_postgis_dbmanagement.html#RefObject).\n\n### Example\n\n```php\n$entity = new MyEntity(\n    point: 'POINT(-122.0845187 37.4220761)',\n    point4D: 'POINT(1 2 3 4)',\n    pointWithSRID: 'SRID=3785;POINT(-122.0845187 37.4220761)',\n);\n```\n\nSpatial Indexes\n--\n\n[Spatial indexes](https://postgis.net/docs/using_postgis_dbmanagement.html#gist_indexes)\ncan be defined for geometry fields by setting the `spatial` flag.\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\n\n#[ORM\\Entity]\n#[ORM\\Index(\n    fields: ['pointWithSRID'],\n    flags: ['spatial'],\n)]\nclass MyEntity\n{\n}\n```\n\nSchema Tool\n--\n\nFull support for the [ORM Schema Tool](https://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html)\nand the [DBAL Schema Manager](https://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html)\nis provided.\n\nDQL Functions\n--\n\nMost [PostGIS functions](https://postgis.net/docs/reference.html) are also\navailable for the [Doctrine Query Language](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html)\n(DQL) under the `Jsor\\Doctrine\\PostGIS\\Functions` namespace.\n\nFor a full list of all supported functions, see the\n[Function Index](docs/function-index.md).\n\n\u003e Read the dedicated [Symfony documentation](docs/symfony.md#dql-functions) on\n\u003e how to configure the functions with Symfony.\n\nThe functions must be registered with the `Doctrine\\ORM\\Configuration` instance.\n \n```php\n$configuration = new Doctrine\\ORM\\Configuration();\n\n$configuration-\u003eaddCustomStringFunction(\n    'ST_Within',\n    Jsor\\Doctrine\\PostGIS\\Functions\\ST_Within::class\n);\n\n$configuration-\u003eaddCustomNumericFunction(\n    'ST_Distance',\n    Jsor\\Doctrine\\PostGIS\\Functions\\ST_Distance::class\n);\n\n$dbParams = [/***/];\n$entityManager = Doctrine\\ORM\\EntityManager::create($dbParams, $configuration);\n```\n\nThere's a convenience Configurator class which can be used to register all\nfunctions at once.\n\n```php\n$configuration = new Doctrine\\ORM\\Configuration();\n\nJsor\\Doctrine\\PostGIS\\Functions\\Configurator::configure($configuration);\n\n$dbParams = [/***/];\n$entityManager = Doctrine\\ORM\\EntityManager::create($dbParams, $configuration);\n```\n\nKnown Problems\n--\n\n\u003e Read the dedicated [Symfony documentation](docs/symfony.md#known-problems) on\n\u003e how to handle those problems with Symfony.\n\n### PostGIS Schema Exclusion\n\nSince PostGIS can add a few new schemas, like `topology`, `tiger` and\n`tiger_data`, you might want to exclude them from being handled by Doctrine.\n\nThis can be done by configuring a schema assets filter.\n\n```php\n$configuration = new Doctrine\\ORM\\Configuration();\n\n$configuration-\u003esetSchemaAssetsFilter(static function ($assetName): bool {\n     if ($assetName instanceof AbstractAsset) {\n         $assetName = $assetName-\u003egetName();\n     }\n\n     return (bool) preg_match('/^(?!tiger)(?!topology)/', $assetName);\n});\n\n$dbParams = [/***/];\n$entityManager = Doctrine\\ORM\\EntityManager::create($dbParams, $configuration);\n```\n\n### Unknown Database Types\n\nSometimes, the schema tool stumbles upon database types it can't handle.\nA common exception is something like\n\n```\nDoctrine\\DBAL\\Exception: Unknown database type _text requested, Doctrine\\DBAL\\Platforms\\PostgreSQL100Platform may not support it.\n```\n\nTo solve this, the unknown database types can be mapped to known types.\n\n```php\n$configuration = new Doctrine\\ORM\\Configuration();\n\n$dbParams = [/***/];\n$entityManager = Doctrine\\ORM\\EntityManager::create($dbParams, $configuration);\n\n$entityManager-\u003egetConnection()-\u003egetDatabasePlatform()-\u003eregisterDoctrineTypeMapping('_text', 'string');\n```\n\n**Note:** This type is then not suited to be used in entity mappings.\nIt just prevents \"Unknown database type...\" exceptions thrown during database\ninspections by the schema tool.\n\nIf you want to use this type in your entities, you have to configure real\ndatabase types, e.g. with the [PostgreSQL for Doctrine](https://github.com/martin-georgiev/postgresql-for-doctrine)\npackage.\n\nRunning the Tests\n--\n\nA simple Docker setup is included to run the test suite against the different\nPostgreSQL / PostGIS combinations.\n\nAll commands here should be run from the project root.\n\nFirst, build the PHP container. This must be done only once.\n\n```bash\n./docker/build-php.sh\n```\n\nInstall dependencies via Composer.\n\n```bash\n./docker/run-php.sh composer install\n```\n\nNext, start the database containers.\n\n```bash\ndocker compose -f ./docker/docker-compose.yml up -d\n```\n\nThere are a number of shortcut scripts available to execute commands inside the\nPHP container connected to specific database containers.\n\nThe script names follow the pattern\n`run-\u003cPOSTGRESQL_VERSION\u003e-\u003cPOSTGIS_VERSION\u003e.sh`.\n\nTo run the test suite against PostgreSQL 13 with PostGIS 3.1, use the script \n`./docker/run-13-31.sh`.\n\n```bash\n./docker/run-13-31.sh vendor/bin/phpunit --exclude-group=postgis-3.0\n```\n\nNote, that we exclude tests targeted at PostGIS 3.0 here. When running tests\nagainst PostGIS 3.0, exclude the tests for 3.1.\n\n```bash\n./docker/run-13-30.sh vendor/bin/phpunit --exclude-group=postgis-3.1\n```\n\nLicense\n--\n\nCopyright (c) 2014-2024 Jan Sorgalla.\nReleased under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fdoctrine-postgis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsor%2Fdoctrine-postgis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fdoctrine-postgis/lists"}