fix: Fix geometry parsing

This commit is contained in:
2026-06-28 00:37:29 +05:00
parent 7c469a524b
commit 1e71b94fdb
5 changed files with 160 additions and 20 deletions

View File

@@ -139,12 +139,23 @@ func (r *DatasetRepository) MarkConverted(ctx context.Context, id uuid.UUID, cog
return nil
}
// SetProperties stores the extracted attribute table (nil -> NULL) and marks the
// dataset ready.
func (r *DatasetRepository) SetProperties(ctx context.Context, id uuid.UUID, properties []byte) error {
// SetProperties stores the extracted attribute table (nil -> NULL) and the
// dissolved feature geometry (GeoJSON in EPSG:4326; nil keeps the existing
// geometry), then marks the dataset ready. The geometry is reduced to the union
// of all features via ST_UnaryUnion.
func (r *DatasetRepository) SetProperties(ctx context.Context, id uuid.UUID, properties, geometry []byte) error {
var geom any // nil -> SQL NULL -> CASE keeps existing geometry
if len(geometry) > 0 {
geom = string(geometry)
}
tag, err := r.pool.Exec(ctx,
`UPDATE datasets SET properties = $2, status = $3, parse_error = NULL, updated_at = now() WHERE id = $1`,
id, nullableJSON(json.RawMessage(properties)), domain.DatasetStatusReady,
`UPDATE datasets
SET properties = $2,
geometry = CASE WHEN $3::text IS NULL THEN geometry
ELSE ST_UnaryUnion(ST_SetSRID(ST_GeomFromGeoJSON($3), 4326)) END,
status = $4, parse_error = NULL, updated_at = now()
WHERE id = $1`,
id, nullableJSON(json.RawMessage(properties)), geom, domain.DatasetStatusReady,
)
if err != nil {
return mapError(err)