| 884 | /* polys -> treat rings as lines */ |
| 885 | |
| 886 | static int force_to_lines(char *wkb, shapeObj *shape) |
| 887 | { |
| 888 | int offset = 0; |
| 889 | int pt_offset; |
| 890 | int ngeoms; |
| 891 | int t, u, v; |
| 892 | int type, nrings, npoints; |
| 893 | lineObj line = {0, NULL}; |
| 894 | |
| 895 | shape->type = MS_SHAPE_NULL; /* nothing in it */ |
| 896 | |
| 897 | memcpy(&ngeoms, &wkb[5], 4); |
| 898 | offset = 9; /* were the first geometry is */ |
| 899 | for(t=0; t < ngeoms; t++) { |
| 900 | memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ |
| 901 | |
| 902 | /* cannot do anything with a point */ |
| 903 | |
| 904 | if(type == 2) { |
| 905 | /* Linestring */ |
| 906 | shape->type = MS_SHAPE_LINE; |
| 907 | |
| 908 | memcpy(&line.numpoints, &wkb[offset + 5], 4); |
| 909 | line.point = (pointObj*) msSmallMalloc(sizeof(pointObj) * line.numpoints ); |
| 910 | for(u=0; u < line.numpoints; u++) { |
| 911 | memcpy(&line.point[u].x, &wkb[offset + 9 + (16 * u)], 8); |
| 912 | memcpy(&line.point[u].y, &wkb[offset + 9 + (16 * u)+8], 8); |
| 913 | } |
| 914 | offset += 9 + 16 * line.numpoints; /* length of object */ |
| 915 | msAddLine(shape, &line); |
| 916 | msFree(line.point); |
| 917 | } else if(type == 3) { |
| 918 | /* polygon */ |
| 919 | shape->type = MS_SHAPE_LINE; |
| 920 | |
| 921 | memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */ |
| 922 | /* add a line for each polygon ring */ |
| 923 | pt_offset = 0; |
| 924 | offset += 9; /* now points at 1st linear ring */ |
| 925 | for(u = 0; u < nrings; u++) { |
| 926 | /* for each ring, make a line */ |
| 927 | memcpy(&npoints, &wkb[offset], 4); |
| 928 | line.numpoints = npoints; |
| 929 | line.point = (pointObj*) msSmallMalloc(sizeof(pointObj) * npoints); |
| 930 | /* point struct */ |
| 931 | for(v = 0; v < npoints; v++) { |
| 932 | memcpy(&line.point[v].x, &wkb[offset + 4 + (16 * v)], 8); |
| 933 | memcpy(&line.point[v].y, &wkb[offset + 4 + (16 * v) + 8], 8); |
| 934 | } |
| 935 | /* make offset point to next linear ring */ |
| 936 | msAddLine(shape, &line); |
| 937 | msFree(line.point); |
| 938 | offset += 4 + 16 * npoints; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | return MS_SUCCESS; |
no test coverage detected