Skip to content

Commit

Permalink
WFS: add support for PropertyName/ValueReference/Filter parameters in…
Browse files Browse the repository at this point in the history
… gml_groups
  • Loading branch information
rouault committed Nov 3, 2013
1 parent 598e223 commit 7c7fdcf
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 82 deletions.
27 changes: 20 additions & 7 deletions mapgml.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR)

static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, char *type);
static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, const char *type);

/*
** Functions that write the feature boundary geometry (i.e. a rectObj).
Expand Down Expand Up @@ -734,7 +734,7 @@ static int gmlWriteGeometry(FILE *stream, gmlGeometryListObj *geometryList,
** GML specific metadata handling functions.
*/

int msItemInGroups(char *name, gmlGroupListObj *groupList)
int msItemInGroups(const char *name, gmlGroupListObj *groupList)
{
int i, j;
gmlGroupObj *group;
Expand All @@ -751,7 +751,7 @@ int msItemInGroups(char *name, gmlGroupListObj *groupList)
return MS_FALSE;
}

static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, char *type)
static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, const char *type)
{
int i;

Expand All @@ -761,10 +761,13 @@ static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, char *type)
if(geometryList->geometries[i].type && (strcasecmp(geometryList->geometries[i].type, type) == 0))
return i;

if( geometryList->numgeometries == 1 && geometryList->geometries[0].type == NULL )
return 0;

return -1; /* not found */
}

gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces)
gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces, int bWithDefaultGeom)
{
int i;

Expand Down Expand Up @@ -826,6 +829,14 @@ gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_nam

msFreeCharArray(names, numnames);
}
else if( bWithDefaultGeom ) {
geometryList->numgeometries = 1;
geometryList->geometries = (gmlGeometryObj *) calloc(1, sizeof(gmlGeometryObj));
geometryList->geometries[0].name = msStrdup(OWS_GML_DEFAULT_GEOMETRY_NAME);
geometryList->geometries[0].type = NULL;
geometryList->geometries[0].occurmin = 0;
geometryList->geometries[0].occurmax = 1;
}

return geometryList;
}
Expand Down Expand Up @@ -1070,7 +1081,8 @@ gmlGroupListObj *msGMLGetGroups(layerObj *layer, const char *metadata_namespaces
groupList->numgroups = 0;

/* list of groups (TODO: make this automatic by parsing metadata) */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "groups")) != NULL) {
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "groups")) != NULL &&
value[0] != '\0' ) {
names = msStringSplit(value, ',', &numnames);

/* allocation an array of gmlGroupObj's */
Expand Down Expand Up @@ -1117,6 +1129,7 @@ void msGMLFreeGroups(gmlGroupListObj *groupList)
msFreeCharArray(groupList->groups[i].items, groupList->groups[i].numitems);
msFree(groupList->groups[i].type);
}
msFree(groupList->groups);

free(groupList);
}
Expand Down Expand Up @@ -1255,7 +1268,7 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
itemList = msGMLGetItems(lp, namespaces);
constantList = msGMLGetConstants(lp, namespaces);
groupList = msGMLGetGroups(lp, namespaces);
geometryList = msGMLGetGeometries(lp, namespaces);
geometryList = msGMLGetGeometries(lp, namespaces, MS_FALSE);
if (itemList == NULL || constantList == NULL || groupList == NULL || geometryList == NULL) {
msSetError(MS_MISCERR, "Unable to populate item and group metadata structures", "msGMLWriteQuery()");
return MS_FAILURE;
Expand Down Expand Up @@ -1448,7 +1461,7 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
itemList = msGMLGetItems(lp, "G");
constantList = msGMLGetConstants(lp, "G");
groupList = msGMLGetGroups(lp, "G");
geometryList = msGMLGetGeometries(lp, "GFO");
geometryList = msGMLGetGeometries(lp, "GFO", MS_FALSE);
if (itemList == NULL || constantList == NULL || groupList == NULL || geometryList == NULL) {
msSetError(MS_MISCERR, "Unable to populate item and group metadata structures", "msGMLWriteWFSQuery()");
return MS_FAILURE;
Expand Down
51 changes: 50 additions & 1 deletion mapogcfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,48 @@ static void FLTStripNameSpacesFromPropertyName(FilterEncodingNode *psFilterNode)

}

static void FLTRemoveGroupName(FilterEncodingNode *psFilterNode,
gmlGroupListObj* groupList)
{
int i;

if (psFilterNode) {
if (psFilterNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) {
if( psFilterNode->pszValue != NULL )
{
const char* pszPropertyName = psFilterNode->pszValue;
const char* pszSlash = strchr(pszPropertyName, '/');
if( pszSlash != NULL ) {
const char* pszColon = strchr(pszPropertyName, ':');
if( pszColon != NULL && pszColon < pszSlash )
pszPropertyName = pszColon + 1;
for(i=0;i<groupList->numgroups;i++) {
const char* pszGroupName = groupList->groups[i].name;
size_t nGroupNameLen = strlen(pszGroupName);
if(strncasecmp(pszPropertyName, pszGroupName, nGroupNameLen) == 0 &&
pszPropertyName[nGroupNameLen] == '/') {
char* pszTmp;
pszPropertyName = pszPropertyName + nGroupNameLen + 1;
pszColon = strchr(pszPropertyName, ':');
if( pszColon != NULL )
pszPropertyName = pszColon + 1;
pszTmp = msStrdup(pszPropertyName);
msFree(psFilterNode->pszValue);
psFilterNode->pszValue = pszTmp;
break;
}
}
}
}
}
if (psFilterNode->psLeftNode)
FLTRemoveGroupName(psFilterNode->psLeftNode, groupList);
if (psFilterNode->psRightNode)
FLTRemoveGroupName(psFilterNode->psRightNode, groupList);
}

}

/************************************************************************/
/* FLTPreParseFilterForAlias */
/* */
Expand All @@ -3241,12 +3283,19 @@ void FLTPreParseFilterForAlias(FilterEncodingNode *psFilterNode,
#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)

if (psFilterNode && map && i>=0 && i<map->numlayers) {
/*strip name speces befor hand*/
/*strip name spaces before hand*/
FLTStripNameSpacesFromPropertyName(psFilterNode);

lp = GET_LAYER(map, i);
layerWasOpened = msLayerIsOpen(lp);
if (msLayerOpen(lp) == MS_SUCCESS && msLayerGetItems(lp) == MS_SUCCESS) {

/* Remove group names from property names if using groupname/itemname syntax */
gmlGroupListObj* groupList = msGMLGetGroups(lp, "G");
if( groupList && groupList->numgroups > 0 )
FLTRemoveGroupName(psFilterNode, groupList);
msGMLFreeGroups(groupList);

for(i=0; i<lp->numitems; i++) {
if (!lp->items[i] || strlen(lp->items[i]) <= 0)
continue;
Expand Down
4 changes: 2 additions & 2 deletions mapows.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ typedef struct {

#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR)

MS_DLL_EXPORT int msItemInGroups(char *name, gmlGroupListObj *groupList);
MS_DLL_EXPORT int msItemInGroups(const char *name, gmlGroupListObj *groupList);
MS_DLL_EXPORT gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces);
MS_DLL_EXPORT void msGMLFreeItems(gmlItemListObj *itemList);
MS_DLL_EXPORT gmlConstantListObj *msGMLGetConstants(layerObj *layer, const char *metadata_namespaces);
MS_DLL_EXPORT void msGMLFreeConstants(gmlConstantListObj *constantList);
MS_DLL_EXPORT gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces);
MS_DLL_EXPORT gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces, int bWithDefaultGeom);
MS_DLL_EXPORT void msGMLFreeGeometries(gmlGeometryListObj *geometryList);
MS_DLL_EXPORT gmlGroupListObj *msGMLGetGroups(layerObj *layer, const char *metadata_namespaces);
MS_DLL_EXPORT void msGMLFreeGroups(gmlGroupListObj *groupList);
Expand Down
Loading

0 comments on commit 7c7fdcf

Please sign in to comment.