2013-05-15 15:00:42 +04:00
|
|
|
package postgis
|
2013-05-15 10:15:33 +04:00
|
|
|
|
2013-05-15 13:05:02 +04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ColumnType interface {
|
|
|
|
Name() string
|
|
|
|
PrepareInsertSql(i int,
|
|
|
|
spec *TableSpec) string
|
2013-05-22 13:48:34 +04:00
|
|
|
GeneralizeSql(colSpec *ColumnSpec, spec *GeneralizedTableSpec) string
|
2013-05-15 13:05:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type simpleColumnType struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *simpleColumnType) Name() string {
|
|
|
|
return t.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *simpleColumnType) PrepareInsertSql(i int, spec *TableSpec) string {
|
|
|
|
return fmt.Sprintf("$%d", i)
|
|
|
|
}
|
|
|
|
|
2013-05-22 13:48:34 +04:00
|
|
|
func (t *simpleColumnType) GeneralizeSql(colSpec *ColumnSpec, spec *GeneralizedTableSpec) string {
|
|
|
|
return colSpec.Name
|
|
|
|
}
|
|
|
|
|
2013-05-15 13:05:02 +04:00
|
|
|
type geometryType struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *geometryType) Name() string {
|
|
|
|
return t.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *geometryType) PrepareInsertSql(i int, spec *TableSpec) string {
|
|
|
|
return fmt.Sprintf("ST_GeomFromWKB($%d, %d)",
|
|
|
|
i, spec.Srid,
|
|
|
|
)
|
2013-05-15 10:15:33 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 13:48:34 +04:00
|
|
|
func (t *geometryType) GeneralizeSql(colSpec *ColumnSpec, spec *GeneralizedTableSpec) string {
|
|
|
|
return fmt.Sprintf(`ST_SimplifyPreserveTopology("%s", %f) as "%s"`,
|
|
|
|
colSpec.Name, spec.Tolerance, colSpec.Name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-05-15 10:15:33 +04:00
|
|
|
var pgTypes map[string]ColumnType
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pgTypes = map[string]ColumnType{
|
2013-05-15 13:05:02 +04:00
|
|
|
"id": &simpleColumnType{"BIGINT"},
|
|
|
|
"geometry": &geometryType{"GEOMETRY"},
|
|
|
|
"bool": &simpleColumnType{"BOOL"},
|
2013-05-22 13:48:34 +04:00
|
|
|
"boolint": &simpleColumnType{"SMALLINT"},
|
2013-05-15 13:05:02 +04:00
|
|
|
"string": &simpleColumnType{"VARCHAR"},
|
|
|
|
"name": &simpleColumnType{"VARCHAR"},
|
|
|
|
"direction": &simpleColumnType{"SMALLINT"},
|
|
|
|
"integer": &simpleColumnType{"INTEGER"},
|
|
|
|
"wayzorder": &simpleColumnType{"INTEGER"},
|
2013-05-21 16:39:24 +04:00
|
|
|
"zorder": &simpleColumnType{"INTEGER"},
|
2013-05-15 13:05:02 +04:00
|
|
|
"pseudoarea": &simpleColumnType{"REAL"},
|
|
|
|
"mapping_key": &simpleColumnType{"VARCHAR"},
|
|
|
|
"mapping_value": &simpleColumnType{"VARCHAR"},
|
2013-05-15 10:15:33 +04:00
|
|
|
}
|
|
|
|
}
|