From a367850f6f7648561ebb3c078d67bd55eedc088a Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Tue, 21 Nov 2017 09:18:44 +0100 Subject: [PATCH] writer: do not check for validity of simple polygons Skips slow GEOS IsValid calls for polygons with only 4 corners. They can be invalid, but its more unlikely to get simple polygons wrong and even if, it should affect only small polygons like buildings. --- geom/geos/geos.go | 5 +++++ writer/ways.go | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/geom/geos/geos.go b/geom/geos/geos.go index e311b6f..559cb13 100644 --- a/geom/geos/geos.go +++ b/geom/geos/geos.go @@ -112,6 +112,11 @@ func (this *Geos) NumGeoms(geom *Geom) int32 { return count } +func (this *Geos) NumCoordinates(geom *Geom) int32 { + count := int32(C.GEOSGetNumCoordinates_r(this.v, geom.v)) + return count +} + func (this *Geos) Geoms(geom *Geom) []*Geom { count := this.NumGeoms(geom) var result []*Geom diff --git a/writer/ways.go b/writer/ways.go index 3ba3af4..5ca184a 100644 --- a/writer/ways.go +++ b/writer/ways.go @@ -139,7 +139,10 @@ func (ww *WayWriter) buildAndInsert(g *geos.Geos, w *element.Way, matches []mapp if isPolygon { geosgeom, err = geomp.Polygon(g, way.Nodes) if err == nil { - geosgeom, err = g.MakeValid(geosgeom) + if g.NumCoordinates(geosgeom) > 5 { + // only check for valididty for non-simple geometries + geosgeom, err = g.MakeValid(geosgeom) + } } } else { geosgeom, err = geomp.LineString(g, way.Nodes)