Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to store empty polygon in Postgres? #220

Open
tec4 opened this issue Feb 9, 2022 · 0 comments
Open

Any way to store empty polygon in Postgres? #220

tec4 opened this issue Feb 9, 2022 · 0 comments

Comments

@tec4
Copy link

tec4 commented Feb 9, 2022

Is there any way to store an empty polygon?

What I am trying to do is have a geometry column in Postgres that has a spatial index, so I cannot set the column to be nullable. In raw SQL, it would be something like this:

-- Create Dummy Table
CREATE TABLE poly_testing
(
    id SERIAL NOT NULL,
    poly geometry(Polygon,4326) NOT NULL,
    CONSTRAINT poly_testing_pkey PRIMARY KEY (id)
);

-- Insert empty polygon
insert into poly_testing (poly) 
values ('SRID=4326;POLYGON EMPTY')

I've tried to create an empty Polygon object by passing it no rings, like this but it fails:

    /**
     * @ORM\Column(name="poly", type="polygon", options={"srid": 4326})
     */
    protected ?Polygon $polygon = null;

    // ......

    $this->polygon = new Polygon([], 4326);

I get the following error:
Error: Method CrEOF\Spatial\PHP\Types\Geometry\Polygon::__toString() must return a string value

My Doctrine config looks like:

doctrine:
    dbal:
        driver: 'pdo_pgsql'
        server_version: '12.1'
        charset: utf8
        default_table_options:
            charset: utf8
            collate: utf8_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'
        types:
            geometry:  CrEOF\Spatial\DBAL\Types\GeometryType
            point:         CrEOF\Spatial\DBAL\Types\Geometry\PointType
            polygon:    CrEOF\Spatial\DBAL\Types\Geometry\PolygonType

Any suggestions on how to go about storing an empty polygon or other geometry?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant