I'm running GEOS C++ Library v 3.6 on Fedora. I have a list of geometries I loaded from a shapefile and converted to geos polygons. The shapefile is large and I may be overlaying several ones to make a complete picture. I want to extract all the polygons that overlap the "viewport" which is a polygon I pass in that is just a square (Polygon) so I dont have to do as much work during the intersection call and I already have the pulled apart. The shapes coming in are MultiPolygons.

            geos::geom::MultiPolygon *mp = shapeData[files];
            bool found = false;
            size_t n_shps = mp->getNumGeometries();
            for (size_t i = 0; i < n_shps; i++)
                // Prefilter geometries returned to only include ones inside your envelope
                const geos::geom::Geometry *thisShp = mp->getGeometryN(i);
                geos::geom::Geometry *shpEnv = thisShp->getEnvelope();
                if (envelope && shpEnv->overlaps(envelope))
                    found = true; // Never gets here even though I know some intersect

I've tried intersects, overlaps, touches, ... they all never return true.

What am I doing wrong?

Again, I'm sure that some of the polygons overlap my envelope Geometry.


It was my fault. I had lat and lon swapped. The correct function seems to be envelope->intersects(thisShp).

Not the answer you're looking for? Browse other questions tagged or ask your own question.