I have a table with a geom column which has the datatype of geometry. I need to save data into this table and the request being sent has the type wkt for this column. Currently there are some existing rows in the table with data in this format:
SRID=4326;POLYGON((-82.42186119969756 35.50904833429925,-82.41310709710558 35.5138338218795,-82.40448173131567 35.50461189763692,-82.41851404282427 35.500629375676766,-82.42186119969756 35.509013402684445,-82.42186119969756 35.50904833429925))
Is the "SRID=4326" portion of the data autogenerated?
Currently I have the follow set up:
dto:
@IsString()
geom: string; //geometry
entity:
@Column('geometry', {spatialFeatureType: 'Polygon', srid: 4326 })
geom: string;
And I and inserting the data like this, with dto.geom as a wtk string:
create(dto: CreatePlaceDto): Promise<number> {
return <any>this.repository
.insert(dto)
.then((data) => data.identifiers[0][Object.keys(data.identifiers[0])[0]])
.catch((err) => {
console.error(err);
});
}
When I send through a request, I get the QueryFailedError: unknown GeoJSON type
error. When checking the raw sql query from the logs, it looks like the that the wkt is getting an extra set of quotes. And typeorm is trying to convert a geojson from to geom. I think i'd need typeorm to use ST_GeomFromText right? Since wkt isn't geojson.
INSERT INTO "place"("customerId", "geom", "industry", "createdAt", "updatedAt")
VALUES ($1, ST_SetSRID(ST_GeomFromGeoJSON($2), 4326)::geometry, DEFAULT, DEFAULT)
RETURNING "placeId", "createdAt", "updatedAt"
-- PARAMETERS: [13,"\"POLYGON ((-82.42186119969756 35.50904833429925, -82.41310709710558 35.5138338218795, -82.40448173131567 35.50461189763692, -82.41851404282427 35.500629375676766, -82.42186119969756 35.509013402684445, -82.42186119969756 35.50904833429925))\"","industry1"]
Am I correct in typing geom as string in dto and entity? How do I get the format with "SRID=4326;POLYGON((-8 etc etc"
?