I have a postgres table who is using Geometry
column type.
This is my table:
CREATE TABLE areas (
id SERIAL PRIMARY KEY,
name VARCHAR(64),
polygon GEOMETRY
);
And, normally I was inserting data like:
INSERT INTO areas (name, polygon) VALUES (
'A',
ST_GeometryFromText('POLYGON ((-123.11386585235593 49.284015800344065,
-123.11882257461549 49.28074038150665,
-123.11337232589727 49.27721276406796,
-123.1078577041626 49.281104327676616,
-123.10996055603025 49.28152426222755,
-123.11386585235593 49.284015800344065))'));
And currently is working properly if I run the statement from postgres.
But in my NestJS/TypeORM entity I have defined:
@Column('geometry', {nullable: true, name: 'polygon ' }
@ApiProperty()
polygon : string;
And once I assign the value with:
areas .polygon = 'POLYGON ((-123.11386585235593 49.284015800344065, -123.11882257461549 49.28074038150665, -123.11337232589727 49.27721276406796, -123.1078577041626 49.281104327676616, -123.10996055603025 49.28152426222755, -123.11386585235593 49.284015800344065))';
I get this error:
error: error: unknown GeoJSON type at Parser.parseErrorMessage (C:\Users\myuserpath\myproject\node_modules\pg-protocol\dist\parser.js:278:15)
But I notice the raw query is:
INSERT INTO "areas VALUES ('A', ST_GeomFromGeoJSON('POLYGON ((-123.11386585235593 49.284015800344065,
-123.11882257461549 49.28074038150665,
-123.11337232589727 49.27721276406796,
-123.1078577041626 49.281104327676616,
-123.10996055603025 49.28152426222755,
-123.11386585235593 49.284015800344065)))'::geometry)
I'm not sure where the column has defined ST_GeomFromGeoJSON
How can insert that polygon using TypeORM?