do not validate all generalized geometries by default

validation with st_buffer fails for linestrings
add new validated_geometry column type that validates geometries
(st_buffer) on generalization
master
Oliver Tonnhofer 2014-01-30 10:31:34 +01:00
parent fed6c026cd
commit 48486e7280
5 changed files with 51 additions and 9 deletions

View File

@ -42,6 +42,16 @@ func (t *geometryType) PrepareInsertSql(i int, spec *TableSpec) string {
}
func (t *geometryType) GeneralizeSql(colSpec *ColumnSpec, spec *GeneralizedTableSpec) string {
return fmt.Sprintf(`ST_SimplifyPreserveTopology("%s", %f) as "%s"`,
colSpec.Name, spec.Tolerance, colSpec.Name,
)
}
type validatedGeometryType struct {
geometryType
}
func (t *validatedGeometryType) GeneralizeSql(colSpec *ColumnSpec, spec *GeneralizedTableSpec) string {
return fmt.Sprintf(`ST_Buffer(ST_SimplifyPreserveTopology("%s", %f), 0) as "%s"`,
colSpec.Name, spec.Tolerance, colSpec.Name,
)
@ -51,12 +61,13 @@ var pgTypes map[string]ColumnType
func init() {
pgTypes = map[string]ColumnType{
"string": &simpleColumnType{"VARCHAR"},
"bool": &simpleColumnType{"BOOL"},
"int8": &simpleColumnType{"SMALLINT"},
"int32": &simpleColumnType{"INT"},
"int64": &simpleColumnType{"BIGINT"},
"float32": &simpleColumnType{"REAL"},
"geometry": &geometryType{"GEOMETRY"},
"string": &simpleColumnType{"VARCHAR"},
"bool": &simpleColumnType{"BOOL"},
"int8": &simpleColumnType{"SMALLINT"},
"int32": &simpleColumnType{"INT"},
"int64": &simpleColumnType{"BIGINT"},
"float32": &simpleColumnType{"REAL"},
"geometry": &geometryType{"GEOMETRY"},
"validated_geometry": &validatedGeometryType{geometryType{"GEOMETRY"}},
}
}

View File

@ -24,6 +24,7 @@ func init() {
"mapping_key": {"mapping_key", "string", Key, nil},
"mapping_value": {"mapping_value", "string", Value, nil},
"geometry": {"geometry", "geometry", Geometry, nil},
"validated_geometry": {"validated_geometry", "validated_geometry", Geometry, nil},
"wayzorder": {"wayzorder", "int32", WayZOrder, nil},
"pseudoarea": {"pseudoarea", "float32", PseudoArea, nil},
"zorder": {"zorder", "int32", nil, MakeZOrder},

View File

@ -418,6 +418,23 @@ def test_generalized_banana_polygon_is_valid():
park = query_row(db_conf, 'osm_landusages_gen1', 7101)
assert park['geometry'].is_valid, park
def test_generalized_linestring_is_valid():
"""Generalized linestring is valid."""
road = query_row(db_conf, 'osm_roads', 7201)
# geometry is not simple, but valid
# check that geometry 'survives' simplification
assert not road['geometry'].is_simple, road['geometry'].wkt
assert road['geometry'].is_valid, road['geometry'].wkt
assert road['geometry'].length > 1000000
road = query_row(db_conf, 'osm_roads_gen0', 7201)
# but simplified geometies are simple
assert road['geometry'].is_valid, road['geometry'].wkt
assert road['geometry'].length > 1000000
road = query_row(db_conf, 'osm_roads_gen1', 7201)
assert road['geometry'].is_valid, road['geometry'].wkt
assert road['geometry'].length > 1000000
#######################################################################
def test_update():
"""Diff import applies"""

View File

@ -327,6 +327,19 @@
<tag k="name" v="banana"/>
</way>
<!-- test self-intersecting ways -->
<node id="7201" version="1" timestamp="2011-11-11T00:11:11Z" lat="60" lon="60"/>
<node id="7202" version="1" timestamp="2011-11-11T00:11:11Z" lat="62" lon="62"/>
<node id="7203" version="1" timestamp="2011-11-11T00:11:11Z" lat="62" lon="60"/>
<node id="7204" version="1" timestamp="2011-11-11T00:11:11Z" lat="60" lon="62"/>
<way id="7201" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="7201"/>
<nd ref="7202"/>
<nd ref="7203"/>
<nd ref="7204"/>
<tag k="highway" v="motorway"/>
<tag k="name" v="self-intersecting"/>
</way>
<!-- test that single node ways or incomplete polygons are _not_ inserted -->
<node id="30001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="80"/>

View File

@ -50,7 +50,7 @@
"key": null
},
{
"type": "geometry",
"type": "validated_geometry",
"name": "geometry",
"key": null
},
@ -835,7 +835,7 @@
"key": null
},
{
"type": "geometry",
"type": "validated_geometry",
"name": "geometry",
"key": null
},