* msBuildWFSLayerPostRequest() * * Build a WFS GetFeature xml document for a Post Request. * * Returns a reference to a newly allocated string that should be freed * by the caller. **********************************************************************/
| 223 | * by the caller. |
| 224 | **********************************************************************/ |
| 225 | static char *msBuildWFSLayerPostRequest(mapObj *map, layerObj *lp, |
| 226 | rectObj *bbox, wfsParamsObj *psParams) |
| 227 | { |
| 228 | char *pszPostReq = NULL; |
| 229 | char *pszFilter = NULL; |
| 230 | size_t bufferSize = 0; |
| 231 | |
| 232 | if (psParams->pszVersion == NULL || |
| 233 | (strncmp(psParams->pszVersion, "0.0.14", 6) != 0 && |
| 234 | strncmp(psParams->pszVersion, "1.0.0", 5)) != 0) |
| 235 | { |
| 236 | msSetError(MS_WFSCONNERR, "MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).", "msBuildWFSLayerPostRequest()"); |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | if (psParams->pszTypeName == NULL) |
| 243 | { |
| 244 | msSetError(MS_WFSCONNERR, "Metadata wfs_typename must be set in the layer", "msBuildWFSLayerPostRequest()"); |
| 245 | return NULL; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | |
| 250 | if (psParams->pszFilter) |
| 251 | pszFilter = psParams->pszFilter; |
| 252 | else |
| 253 | { |
| 254 | bufferSize = 500; |
| 255 | pszFilter = (char *)msSmallMalloc(bufferSize); |
| 256 | snprintf(pszFilter, bufferSize, "<ogc:Filter>\n" |
| 257 | "<ogc:BBOX>\n" |
| 258 | "<ogc:PropertyName>Geometry</ogc:PropertyName>\n" |
| 259 | "<gml:Box>\n" |
| 260 | "<gml:coordinates>%f,%f %f,%f</gml:coordinates>\n" |
| 261 | "</gml:Box>\n" |
| 262 | "</ogc:BBOX>\n" |
| 263 | "</ogc:Filter>",bbox->minx, bbox->miny, bbox->maxx, bbox->maxy); |
| 264 | } |
| 265 | |
| 266 | bufferSize = strlen(pszFilter)+500; |
| 267 | pszPostReq = (char *)msSmallMalloc(bufferSize); |
| 268 | if (psParams->nMaxFeatures > 0) |
| 269 | snprintf(pszPostReq, bufferSize, "<?xml version=\"1.0\" ?>\n" |
| 270 | "<wfs:GetFeature\n" |
| 271 | "service=\"WFS\"\n" |
| 272 | "version=\"1.0.0\"\n" |
| 273 | "maxFeatures=\"%d\"\n" |
| 274 | "outputFormat=\"GML2\">\n" |
| 275 | "<wfs:Query typeName=\"%s\">\n" |
| 276 | "%s" |
| 277 | "</wfs:Query>\n" |
| 278 | "</wfs:GetFeature>\n", psParams->nMaxFeatures, psParams->pszTypeName, pszFilter); |
| 279 | else |
| 280 | snprintf(pszPostReq, bufferSize, "<?xml version=\"1.0\" ?>\n" |
| 281 | "<wfs:GetFeature\n" |
| 282 | "service=\"WFS\"\n" |
no test coverage detected