| 468 | } |
| 469 | |
| 470 | int msQueryByIndex(mapObj *map) |
| 471 | { |
| 472 | layerObj *lp; |
| 473 | int status; |
| 474 | |
| 475 | resultObj record; |
| 476 | |
| 477 | shapeObj shape; |
| 478 | double minfeaturesize = -1; |
| 479 | |
| 480 | if(map->query.type != MS_QUERY_BY_INDEX) { |
| 481 | msSetError(MS_QUERYERR, "The query is not properly defined.", "msQueryByIndex()"); |
| 482 | return(MS_FAILURE); |
| 483 | } |
| 484 | |
| 485 | if(map->query.layer < 0 || map->query.layer >= map->numlayers) { |
| 486 | msSetError(MS_QUERYERR, "No query layer defined.", "msQueryByIndex()"); |
| 487 | return(MS_FAILURE); |
| 488 | } |
| 489 | |
| 490 | lp = (GET_LAYER(map, map->query.layer)); |
| 491 | |
| 492 | if(!msIsLayerQueryable(lp)) { |
| 493 | msSetError(MS_QUERYERR, "Requested layer has no templates defined.", "msQueryByIndex()"); |
| 494 | return(MS_FAILURE); |
| 495 | } |
| 496 | |
| 497 | if(map->query.clear_resultcache) { |
| 498 | if(lp->resultcache) { |
| 499 | if(lp->resultcache->results) free(lp->resultcache->results); |
| 500 | free(lp->resultcache); |
| 501 | lp->resultcache = NULL; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | msLayerClose(lp); /* reset */ |
| 506 | status = msLayerOpen(lp); |
| 507 | if(status != MS_SUCCESS) return(MS_FAILURE); |
| 508 | |
| 509 | /* build item list, we want *all* items */ |
| 510 | status = msLayerWhichItems(lp, MS_TRUE, NULL); |
| 511 | if(status != MS_SUCCESS) return(MS_FAILURE); |
| 512 | |
| 513 | if(map->query.clear_resultcache || lp->resultcache == NULL) { |
| 514 | lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */ |
| 515 | MS_CHECK_ALLOC(lp->resultcache, sizeof(resultCacheObj), MS_FAILURE); |
| 516 | initResultCache( lp->resultcache); |
| 517 | } |
| 518 | |
| 519 | msInitShape(&shape); |
| 520 | |
| 521 | record.shapeindex = map->query.shapeindex; |
| 522 | record.tileindex = map->query.tileindex; |
| 523 | |
| 524 | status = msLayerGetShape(lp, &shape, &record); |
| 525 | if(status != MS_SUCCESS) { |
| 526 | msSetError(MS_NOTFOUND, "Not valid record request.", "msQueryByIndex()"); |
| 527 | return(MS_FAILURE); |
no test coverage detected