# HG changeset patch # User Thomas Junk # Date 1539782558 -7200 # Node ID e0825645f00e089831bdf61fa2ef80cc2384b8b9 # Parent d7f34791b18d4cb78ba9c8deb50395d7e405d08f# Parent a4c92e0ef2e1a434b5bb04f7bf9dbebba3033613 merge diff -r d7f34791b18d -r e0825645f00e pkg/imports/sr.go --- a/pkg/imports/sr.go Wed Oct 17 15:22:21 2018 +0200 +++ b/pkg/imports/sr.go Wed Oct 17 15:22:38 2018 +0200 @@ -28,14 +28,47 @@ const SoundingResultDateFormat = "2006-01-02" -type SoundingResultDate struct{ time.Time } +type ( + SoundingResultDate struct{ time.Time } + + SoundingResultMeta struct { + Date SoundingResultDate `json:"date"` + Bottleneck string `json:"bottleneck"` + EPSG uint `json:"epsg"` + DepthReference string `json:"depth-reference"` + } + + Point struct { + X float64 + Y float64 + } + LineString []Point + Polygon []LineString +) -type SoundingResultMeta struct { - Date SoundingResultDate `json:"date"` - Bottleneck string `json:"bottleneck"` - EPSG uint `json:"epsg"` - DepthReference string `json:"depth-reference"` -} +const ( + insertPointsSQL = ` +INSERT INTO waterway.sounding_results ( + bottleneck_id, + date_info, + depth_reference, + point_cloud, + area +) VALUES ( + (SELECT bottleneck_id from waterway.bottlenecks where objnam = $1), + $2::date, + $3, + ST_Transform(ST_GeomFromWKB($4, $6::integer), 4326)::geography, + (SELECT CASE $5 IS NULL THEN + ST_Transform( + ST_ConcaveHull( + ST_Force2D(ST_GeomFromWKB($4, $6::integer)), 0.7), 4326)::geography + ELSE + ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326)::geography + END) +) +RETURNING id` +) func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error { var s string @@ -94,7 +127,7 @@ } err = conn.QueryRowContext(context.Background(), - `SELECT true FROM waterway.bottlenecks WHERE bottleneck_id = $1`, + `SELECT true FROM waterway.bottlenecks WHERE objnam = $1`, m.Bottleneck).Scan(&b) switch { case err == sql.ErrNoRows: @@ -159,15 +192,6 @@ return loadXYZReader(r) } -type ( - Point struct { - X float64 - Y float64 - } - LineString []Point - Polygon []LineString -) - func toPolygon(numParts int32, parts []int32, points []shp.Point) Polygon { out := make(Polygon, numParts) pos := 0 @@ -269,9 +293,36 @@ return err } - _ = polygon + tx, err := conn.BeginTx(context.Background(), nil) + if err != nil { + return err + } + defer tx.Rollback() + + var id int64 + + err = tx.QueryRow(insertPointsSQL, + m.Bottleneck, + m.Date.Time, + m.DepthReference, + xyz.AsWKB(), + polygon.AsWBK(), + m.EPSG).Scan(&id) - // TODO: Send to database. + if err != nil { + return err + } + + // TODO: Build octree + // TODO: Generate iso-lines + return tx.Commit() +} + +func (p Polygon) AsWBK() []byte { + if len(p) == 0 { + return nil + } + // TODO: Implement me! return nil }