Open
Description
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!
Metadata
Metadata
Assignees
Labels
No labels