Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/pg_featureserv.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ WriteTimeoutSec = 30
# Publish functions from these schemas (default is publish postgisftw)
# FunctionIncludes = [ "postgisftw", "schema2" ]

# Designate a column as the feature ID (where primary key is not available e.g. views/functions)
# IDColumn = "id"

[Paging]
# The default number of features in a response
LimitDefault = 20
Expand Down
5 changes: 3 additions & 2 deletions demo/initdb/02-functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BEGIN
dlat := (lat_max - lat_min) / num_y;
RETURN QUERY
SELECT
x.x::text || '_' || y.y::text AS fid,
x.x::text || '_' || y.y::text AS id,
ST_MakeEnvelope(
lon_min + (x.x - 1) * dlon, lat_min + (y.y - 1) * dlat,
lon_min + x.x * dlon, lat_min + y.y * dlat, 4326
Expand All @@ -35,7 +35,7 @@ COMMENT ON FUNCTION postgisftw.us_grid IS 'Generates a grid of rectangles coveri
CREATE OR REPLACE FUNCTION postgisftw.us_grid_noid(
num_x integer DEFAULT 10,
num_y integer DEFAULT 10)
RETURNS TABLE(geom geometry)
RETURNS TABLE(value text, geom geometry)
AS $$
DECLARE
lon_min CONSTANT numeric := -128;
Expand All @@ -49,6 +49,7 @@ BEGIN
dlat := (lat_max - lat_min) / num_y;
RETURN QUERY
SELECT
x.x::text || '_' || y.y::text AS value,
ST_MakeEnvelope(
lon_min + (x.x - 1) * dlon, lat_min + (y.y - 1) * dlat,
lon_min + x.x * dlon, lat_min + y.y * dlat, 4326
Expand Down
9 changes: 9 additions & 0 deletions hugo/content/installation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ WriteTimeoutSec = 30
# Publish functions from these schemas (default is publish postgisftw)
# FunctionIncludes = [ "postgisftw", "schema2" ]

# Designate a column as the feature ID (where primary key is not available e.g. views/functions)
# IDColumn = "id"

[Paging]
# The default number of features in a response
LimitDefault = 20
Expand Down Expand Up @@ -243,6 +246,12 @@ Overrides items specified in `TableIncludes`.
A list of the schemas to publish functions from.
The default is to publish functions in the `postgisftw` schema.

#### IDColumn

The column to use as the feature ID in cases where a primary key is not available. The default is `id`.

> NOTE: The presence of a primary key will supercede this setting.

#### LimitDefault

The default number of features in a response,
Expand Down
2 changes: 2 additions & 0 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func setDefaultConfig() {
viper.SetDefault("Database.TableIncludes", []string{})
viper.SetDefault("Database.TableExcludes", []string{})
viper.SetDefault("Database.FunctionIncludes", []string{"postgisftw"})
viper.SetDefault("Database.IDColumn", "id")

viper.SetDefault("Paging.LimitDefault", 10)
viper.SetDefault("Paging.LimitMax", 1000)
Expand Down Expand Up @@ -94,6 +95,7 @@ type Database struct {
TableIncludes []string
TableExcludes []string
FunctionIncludes []string
IDColumn string
}

// Metadata config
Expand Down
7 changes: 7 additions & 0 deletions internal/data/catalog_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ func scanTable(rows pgx.Rows) *Table {
colDesc[i] = props.Elements[elmPos+2].String
}

// detect ID column if primary key not defined.
if idColumn == "" && conf.Configuration.Database.IDColumn != "" {
if _, ok := datatypes[conf.Configuration.Database.IDColumn]; ok {
idColumn = conf.Configuration.Database.IDColumn
}
}

// Synthesize a title for now
title := id
// synthesize a description if none provided
Expand Down
11 changes: 9 additions & 2 deletions internal/data/catalog_db_fun.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

// FunctionIDColumnName is the name for a function-supplied ID
const FunctionIDColumnName = "id"

const SchemaPostGISFTW = "postgisftw"

Expand Down Expand Up @@ -116,6 +115,13 @@ func scanFunctionDef(rows pgx.Rows) *Function {

geomCol := geometryColumn(outNames, datatypes)

idColumn := ""
if conf.Configuration.Database.IDColumn != "" {
if _, ok := datatypes[conf.Configuration.Database.IDColumn]; ok {
idColumn = conf.Configuration.Database.IDColumn
}
}

funDef := Function{
ID: id,
Schema: schema,
Expand All @@ -131,6 +137,7 @@ func scanFunctionDef(rows pgx.Rows) *Function {
OutJSONTypes: outJSONTypes,
Types: datatypes,
GeometryColumn: geomCol,
IDColumn: idColumn,
}
//fmt.Printf("DEBUG: Function definitions: %v\n", funDef)
return &funDef
Expand Down Expand Up @@ -191,7 +198,7 @@ func (cat *catalogDB) FunctionFeatures(ctx context.Context, name string, args ma
return nil, errArg
}
propCols := removeNames(param.Columns, fn.GeometryColumn, "")
idColIndex := indexOfName(propCols, FunctionIDColumnName)
idColIndex := indexOfName(propCols, fn.IDColumn)
sql, argValues := sqlGeomFunction(fn, args, propCols, param)
log.Debugf("Function features query: %v", sql)
log.Debugf("Function %v Args: %v", name, argValues)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func writeFunItemsHTML(w http.ResponseWriter, name string, query string, urlBase
context.Group = "Functions"
context.Title = fn.ID
context.Function = fn
context.IDColumn = data.FunctionIDColumnName
context.IDColumn = fn.IDColumn

// features are not needed for items page (page queries for them)
return writeHTML(w, nil, context, ui.PageFunctionItems())
Expand Down
Loading