| 711 | } |
| 712 | |
| 713 | gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces) |
| 714 | { |
| 715 | int i; |
| 716 | |
| 717 | const char *value=NULL; |
| 718 | char tag[64]; |
| 719 | |
| 720 | char **names=NULL; |
| 721 | int numnames=0; |
| 722 | |
| 723 | gmlGeometryListObj *geometryList=NULL; |
| 724 | gmlGeometryObj *geometry=NULL; |
| 725 | |
| 726 | /* allocate memory and initialize the item collection */ |
| 727 | geometryList = (gmlGeometryListObj *) malloc(sizeof(gmlGeometryListObj)); |
| 728 | MS_CHECK_ALLOC(geometryList, sizeof(gmlGeometryListObj), NULL) ; |
| 729 | geometryList->geometries = NULL; |
| 730 | geometryList->numgeometries = 0; |
| 731 | |
| 732 | if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "geometries")) != NULL) { |
| 733 | names = msStringSplit(value, ',', &numnames); |
| 734 | |
| 735 | /* allocation an array of gmlGeometryObj's */ |
| 736 | geometryList->numgeometries = numnames; |
| 737 | geometryList->geometries = (gmlGeometryObj *) malloc(sizeof(gmlGeometryObj)*geometryList->numgeometries); |
| 738 | if (geometryList->geometries == NULL) |
| 739 | { |
| 740 | msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGMLGetGeometries()", |
| 741 | sizeof(gmlGeometryObj)*geometryList->numgeometries); |
| 742 | free(geometryList); |
| 743 | return NULL; |
| 744 | } |
| 745 | |
| 746 | for(i=0; i<geometryList->numgeometries; i++) { |
| 747 | geometry = &(geometryList->geometries[i]); |
| 748 | |
| 749 | geometry->name = msStrdup(names[i]); /* initialize a few things */ |
| 750 | geometry->type = NULL; |
| 751 | geometry->occurmin = 0; |
| 752 | geometry->occurmax = 1; |
| 753 | |
| 754 | snprintf(tag, 64, "%s_type", names[i]); |
| 755 | if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) |
| 756 | geometry->type = msStrdup(value); /* TODO: validate input value */ |
| 757 | |
| 758 | snprintf(tag, 64, "%s_occurances", names[i]); |
| 759 | if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) { |
| 760 | char **occur; |
| 761 | int numoccur; |
| 762 | |
| 763 | occur = msStringSplit(value, ',', &numoccur); |
| 764 | if(numoccur == 2) { /* continue (TODO: throw an error if != 2) */ |
| 765 | geometry->occurmin = atof(occur[0]); |
| 766 | if(strcasecmp(occur[1], "UNBOUNDED") == 0) |
| 767 | geometry->occurmax = OWS_GML_OCCUR_UNBOUNDED; |
| 768 | else |
| 769 | geometry->occurmax = atof(occur[1]); |
| 770 | } |
no test coverage detected