status array lives in the shpfile, can return MS_SUCCESS/MS_FAILURE/MS_DONE */
| 1741 | |
| 1742 | /* status array lives in the shpfile, can return MS_SUCCESS/MS_FAILURE/MS_DONE */ |
| 1743 | int msShapefileWhichShapes(shapefileObj *shpfile, rectObj rect, int debug) |
| 1744 | { |
| 1745 | int i; |
| 1746 | rectObj shaperect; |
| 1747 | char *filename; |
| 1748 | char *sourcename = 0; /* shape file source string from map file */ |
| 1749 | char *s = 0; /* pointer to start of '.shp' in source string */ |
| 1750 | |
| 1751 | if(shpfile->status) { |
| 1752 | free(shpfile->status); |
| 1753 | shpfile->status = NULL; |
| 1754 | } |
| 1755 | |
| 1756 | shpfile->statusbounds = rect; /* save the search extent */ |
| 1757 | |
| 1758 | /* rect and shapefile DON'T overlap... */ |
| 1759 | if(msRectOverlap(&shpfile->bounds, &rect) != MS_TRUE) |
| 1760 | return(MS_DONE); |
| 1761 | |
| 1762 | if(msRectContained(&shpfile->bounds, &rect) == MS_TRUE) { |
| 1763 | shpfile->status = msAllocBitArray(shpfile->numshapes); |
| 1764 | if(!shpfile->status) { |
| 1765 | msSetError(MS_MEMERR, NULL, "msShapefileWhichShapes()"); |
| 1766 | return(MS_FAILURE); |
| 1767 | } |
| 1768 | msSetAllBits(shpfile->status, shpfile->numshapes, 1); |
| 1769 | } |
| 1770 | else { |
| 1771 | |
| 1772 | /* deal with case where sourcename is of the form 'file.shp' */ |
| 1773 | sourcename = msStrdup(shpfile->source); |
| 1774 | /* TODO: need to add case-insensitive handling! */ |
| 1775 | s = strstr(sourcename, ".shp"); |
| 1776 | if( s ) *s = '\0'; |
| 1777 | |
| 1778 | filename = (char *)malloc(strlen(sourcename)+strlen(MS_INDEX_EXTENSION)+1); |
| 1779 | MS_CHECK_ALLOC(filename, strlen(sourcename)+strlen(MS_INDEX_EXTENSION)+1, MS_FAILURE); |
| 1780 | |
| 1781 | sprintf(filename, "%s%s", sourcename, MS_INDEX_EXTENSION); |
| 1782 | |
| 1783 | shpfile->status = msSearchDiskTree(filename, rect, debug); |
| 1784 | free(filename); |
| 1785 | free(sourcename); |
| 1786 | |
| 1787 | if(shpfile->status) { /* index */ |
| 1788 | msFilterTreeSearch(shpfile, shpfile->status, rect); |
| 1789 | } |
| 1790 | else { /* no index */ |
| 1791 | shpfile->status = msAllocBitArray(shpfile->numshapes); |
| 1792 | if(!shpfile->status) { |
| 1793 | msSetError(MS_MEMERR, NULL, "msShapefileWhichShapes()"); |
| 1794 | return(MS_FAILURE); |
| 1795 | } |
| 1796 | |
| 1797 | for(i=0;i<shpfile->numshapes;i++) { |
| 1798 | if(msSHPReadBounds(shpfile->hSHP, i, &shaperect) == MS_SUCCESS) |
| 1799 | if(msRectOverlap(&shaperect, &rect) == MS_TRUE) msSetBit(shpfile->status, i, 1); |
| 1800 | } |
no test coverage detected