do not add prepared geometries to index

master
Oliver Tonnhofer 2013-11-11 09:41:41 +01:00
parent 390edea938
commit aa632e2bd6
2 changed files with 10 additions and 19 deletions

View File

@ -19,11 +19,9 @@ import (
)
// IndexGeom is a struct for indexed geometries used by Index
// and returned by IndexQuery. Access to Prepared requires acquiring .Lock()
// and returned by IndexQuery.
type IndexGeom struct {
*sync.Mutex // Mutex for Prepared
Geom *Geom
Prepared *PreparedGeom
Geom *Geom
}
type Index struct {
v *C.GEOSSTRtree
@ -45,8 +43,7 @@ func (this *Geos) IndexAdd(index *Index, geom *Geom) {
defer index.mu.Unlock()
id := len(index.geoms)
C.IndexAdd(this.v, index.v, geom.v, C.size_t(id))
prep := this.Prepare(geom)
index.geoms = append(index.geoms, IndexGeom{&sync.Mutex{}, geom, prep})
index.geoms = append(index.geoms, IndexGeom{geom})
}
// IndexQuery queries the index for intersections with geom.

View File

@ -287,19 +287,13 @@ func (l *Limiter) Clip(geom *geos.Geom) ([]*geos.Geom, error) {
var intersections []*geos.Geom
// intersect with each part...
for _, hit := range hits {
hit.Lock()
if g.PreparedIntersects(hit.Prepared, geom) {
hit.Unlock()
newPart := g.Intersection(hit.Geom, geom)
if newPart == nil {
continue
}
newParts := filterGeometryByType(g, newPart, geomType)
for _, p := range newParts {
intersections = append(intersections, p)
}
} else {
hit.Unlock()
newPart := g.Intersection(hit.Geom, geom)
if newPart == nil {
continue
}
newParts := filterGeometryByType(g, newPart, geomType)
for _, p := range newParts {
intersections = append(intersections, p)
}
}
// and merge parts back to our clipped intersection