MCPcopy Create free account
hub / github.com/MapServer/MapServer / msOGRFileWhichShapes

Function msOGRFileWhichShapes

mapogr.cpp:1577–1658  ·  view source on GitHub ↗

* msOGRFileWhichShapes() * * Init OGR layer structs ready for calls to msOGRFileNextShape(). * * Returns MS_SUCCESS/MS_FAILURE, or MS_DONE if no shape matching the * layer's FILTER overlaps the selected region. **********************************************************************/

Source from the content-addressed store, hash-verified

1575 * layer's FILTER overlaps the selected region.
1576 **********************************************************************/
1577static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
1578 msOGRFileInfo *psInfo )
1579{
1580 if (psInfo == NULL || psInfo->hLayer == NULL)
1581 {
1582 msSetError(MS_MISCERR, "Assertion failed: OGR layer not opened!!!",
1583 "msOGRFileWhichShapes()");
1584 return(MS_FAILURE);
1585 }
1586
1587/* ------------------------------------------------------------------
1588 * Set Spatial filter... this may result in no features being returned
1589 * if layer does not overlap current view.
1590 *
1591 * __TODO__ We should return MS_DONE if no shape overlaps the selected
1592 * region and matches the layer's FILTER expression, but there is currently
1593 * no _efficient_ way to do that with OGR.
1594 * ------------------------------------------------------------------ */
1595 ACQUIRE_OGR_LOCK;
1596
1597 OGRGeometryH hSpatialFilterPolygon = OGR_G_CreateGeometry( wkbPolygon );
1598 OGRGeometryH hRing = OGR_G_CreateGeometry( wkbLinearRing );
1599
1600#if GDAL_VERSION_NUM >= 1310
1601 OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
1602 OGR_G_AddPoint_2D( hRing, rect.maxx, rect.miny);
1603 OGR_G_AddPoint_2D( hRing, rect.maxx, rect.maxy);
1604 OGR_G_AddPoint_2D( hRing, rect.minx, rect.maxy);
1605 OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
1606#else
1607 OGR_G_AddPoint( hRing, rect.minx, rect.miny, 0);
1608 OGR_G_AddPoint( hRing, rect.maxx, rect.miny, 0);
1609 OGR_G_AddPoint( hRing, rect.maxx, rect.maxy, 0);
1610 OGR_G_AddPoint( hRing, rect.minx, rect.maxy, 0);
1611 OGR_G_AddPoint( hRing, rect.minx, rect.miny, 0);
1612#endif
1613
1614 OGR_G_AddGeometryDirectly( hSpatialFilterPolygon, hRing );
1615
1616 OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterPolygon );
1617
1618 OGR_G_DestroyGeometry( hSpatialFilterPolygon );
1619
1620 psInfo->rect = rect;
1621
1622 if (layer->debug >= MS_DEBUGLEVEL_VVV)
1623 msDebug("msOGRFileWhichShapes: Setting spatial filter to %f %f %f %f\n",
1624 rect.minx, rect.miny, rect.maxx, rect.maxy );
1625
1626/* ------------------------------------------------------------------
1627 * Apply an attribute filter if we have one prefixed with a WHERE
1628 * keyword in the filter string. Otherwise, ensure the attribute
1629 * filter is clear.
1630 * ------------------------------------------------------------------ */
1631 if( layer->filter.string && EQUALN(layer->filter.string,"WHERE ",6) )
1632 {
1633 CPLErrorReset();
1634 if( OGR_L_SetAttributeFilter( psInfo->hLayer, layer->filter.string+6 )

Callers 2

msOGRFileReadTileFunction · 0.85
msOGRLayerWhichShapesFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msDebugFunction · 0.85

Tested by

no test coverage detected