-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from EURODEO/get_extents_issue_63
Added GetExtents method
- Loading branch information
Showing
5 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dsimpl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"datastore/datastore" | ||
) | ||
|
||
func (svcInfo *ServiceInfo) GetExtents( | ||
ctx context.Context, request *datastore.GetExtentsRequest) ( | ||
*datastore.GetExtentsResponse, error) { | ||
|
||
response, err := svcInfo.Sbe.GetExtents(request) | ||
if err != nil { | ||
return nil, fmt.Errorf("svcInfo.Sbe.GetExtents() failed: %v", err) | ||
} | ||
|
||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package postgresql | ||
|
||
import ( | ||
"database/sql" | ||
"datastore/datastore" | ||
"fmt" | ||
"time" | ||
|
||
_ "github.com/lib/pq" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
// getTemporalExtent gets the current temporal extent of all observations in the storage. | ||
func getTemporalExtent(db *sql.DB) (*datastore.TimeInterval, error) { | ||
query := "SELECT min(obstime_instant), max(obstime_instant) FROM observation" | ||
row := db.QueryRow(query) | ||
|
||
var start, end time.Time | ||
|
||
err := row.Scan(&start, &end) | ||
if err != nil { | ||
return nil, fmt.Errorf("row.Scan() failed: %v", err) | ||
} | ||
|
||
return &datastore.TimeInterval{ | ||
Start: timestamppb.New(start), | ||
End: timestamppb.New(end), | ||
}, nil | ||
} | ||
|
||
// getSpatialExtent gets the current horizontally spatial extent of all observations in the storage. | ||
func getSpatialExtent(db *sql.DB) (*datastore.BoundingBox, error) { | ||
query := ` | ||
SELECT ST_XMin(ext), ST_YMin(ext), ST_XMax(ext), ST_YMax(ext) | ||
FROM (SELECT ST_Extent(point::geometry) AS ext FROM geo_point) t | ||
` | ||
row := db.QueryRow(query) | ||
|
||
var xmin, ymin, xmax, ymax float64 | ||
|
||
err := row.Scan(&xmin, &ymin, &xmax, &ymax) | ||
if err != nil { | ||
return nil, fmt.Errorf("row.Scan() failed: %v", err) | ||
} | ||
|
||
return &datastore.BoundingBox{ | ||
Left: xmin, | ||
Bottom: ymin, | ||
Right: xmax, | ||
Top: ymax, | ||
}, nil | ||
} | ||
|
||
// GetExtents ... (see documentation in StorageBackend interface) | ||
func (sbe *PostgreSQL) GetExtents(request *datastore.GetExtentsRequest) ( | ||
*datastore.GetExtentsResponse, error) { | ||
|
||
var err error | ||
|
||
temporalExtent, err := getTemporalExtent(sbe.Db) | ||
if err != nil { | ||
return nil, fmt.Errorf("getTemporalExtent() failed: %v", err) | ||
} | ||
|
||
spatialExtent, err := getSpatialExtent(sbe.Db) | ||
if err != nil { | ||
return nil, fmt.Errorf("getSpatialExtent() failed: %v", err) | ||
} | ||
|
||
return &datastore.GetExtentsResponse{ | ||
TemporalExtent: temporalExtent, | ||
SpatialExtent: spatialExtent, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters