Permalink
Browse files

msLayerGetShapeCount(): add intersection and not only BBOX testing

  • Loading branch information...
rouault committed Feb 3, 2016
1 parent 1bf85cf commit cd1e4b30481943efa13d794bae121272903d7e47
Showing with 248 additions and 39 deletions.
  1. +64 −8 maplayer.c
  2. +135 −21 mappostgis.c
  3. +1 −1 mappostgis.h
  4. +44 −7 mapquery.c
  5. +4 −2 mapserver.h
@@ -409,13 +409,15 @@ int msLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
/*
** Returns the number of shapes that match the potential filter and extent.
* rectProjection is the projection in which rect is expressed, or can be NULL if
* rect should be considered in the layer projection.
* This should be equivalent to calling msLayerWhichShapes() and counting the
* number of shapes returned by msLayerNextShape(), honouring layer->maxfeatures
* limitation if layer->maxfeatures>=0, and honouring layer->startindex if
* layer->startindex >= 1 and paging is enabled.
* Returns -1 in case of failure.
*/
int msLayerGetShapeCount(layerObj *layer, rectObj rect)
int msLayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection)
{
int rv;
@@ -425,7 +427,7 @@ int msLayerGetShapeCount(layerObj *layer, rectObj rect)
return -1;
}
return layer->vtable->LayerGetShapeCount(layer, rect);
return layer->vtable->LayerGetShapeCount(layer, rect, rectProjection);
}
@@ -1526,26 +1528,80 @@ int LayerDefaultGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
return MS_FAILURE;
}
int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect)
int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection)
{
int status;
shapeObj shape;
shapeObj shape, searchshape;
int nShapeCount = 0;
rectObj searchrect = rect;
status = msLayerWhichShapes(layer, rect, MS_TRUE) ;
msInitShape(&searchshape);
msRectToPolygon(searchrect, &searchshape);
#ifdef USE_PROJ
if( rectProjection != NULL )
{
if(layer->project && msProjectionsDiffer(&(layer->projection), rectProjection))
msProjectRect(rectProjection, &(layer->projection), &searchrect); /* project the searchrect to source coords */
else
layer->project = MS_FALSE;
}
#endif
status = msLayerWhichShapes(layer, searchrect, MS_TRUE) ;
if( status == MS_FAILURE )
{
msFreeShape(&searchshape);
return -1;
if( status == MS_DONE )
}
else if( status == MS_DONE )
{
msFreeShape(&searchshape);
return 0;
}
msInitShape(&shape);
while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) {
nShapeCount++ ;
while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS)
{
if( rectProjection != NULL )
{
#ifdef USE_PROJ
if(layer->project && msProjectionsDiffer(&(layer->projection), rectProjection))
msProjectShape(&(layer->projection), rectProjection, &shape);
else
layer->project = MS_FALSE;
#endif
if(msRectContained(&shape.bounds, &rect) == MS_TRUE) { /* if the whole shape is in, don't intersect */
status = MS_TRUE;
} else {
switch(shape.type) { /* make sure shape actually intersects the qrect (ADD FUNCTIONS SPECIFIC TO RECTOBJ) */
case MS_SHAPE_POINT:
status = msIntersectMultipointPolygon(&shape, &searchshape);
break;
case MS_SHAPE_LINE:
status = msIntersectPolylinePolygon(&shape, &searchshape);
break;
case MS_SHAPE_POLYGON:
status = msIntersectPolygons(&shape, &searchshape);
break;
default:
break;
}
}
}
else
status = MS_TRUE;
if( status == MS_TRUE )
nShapeCount++ ;
msFreeShape(&shape);
if(layer->maxfeatures > 0 && layer->maxfeatures == nShapeCount)
break;
}
msFreeShape(&searchshape);
return nShapeCount;
}
Oops, something went wrong.

0 comments on commit cd1e4b3

Please sign in to comment.