Skip to content

Commit

Permalink
Enhanced Layer Metadata implementation (RFC 82)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Mar 30, 2017
1 parent bbe192c commit c8190e5
Show file tree
Hide file tree
Showing 79 changed files with 3,384 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -257,7 +257,7 @@ mapprojhack.c maptree.c mapdebug.c maplexer.c mapquantization.c mapunion.c
mapdraw.c maplibxml2.c mapquery.c maputil.c strptime.c mapdrawgdal.c
mapraster.c mapuvraster.c mapdummyrenderer.c mapobject.c maprasterquery.c
mapwcs.c maperror.c mapogcfilter.c mapregex.c mapwcs11.c mapfile.c
mapogcfiltercommon.c maprendering.c mapwcs20.c mapogcsld.c
mapogcfiltercommon.c maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c
mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c
mapgeomtransform.c mapogroutput.c mapwfslayer.c mapagg.cpp mapkml.cpp
mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c maputfgrid.cpp
Expand Down
902 changes: 902 additions & 0 deletions mapmetadata.c

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion mapows.c
Expand Up @@ -264,7 +264,11 @@ int msOWSDispatch(mapObj *map, cgiRequestObj *request, int ows_mode)
}

if (ows_request.service == NULL) {

if (ows_request.request && EQUAL(ows_request.request, "GetMetadata")) {
status = msMetadataDispatch(map, request, &ows_request);
msOWSClearRequestObj(&ows_request);
return status;
}
#ifdef USE_WFS_SVR
if( msOWSLookupMetadata(&(map->web.metadata), "FO", "cite_wfs2") != NULL ) {
status = msWFSException(map, "service", MS_OWS_ERROR_MISSING_PARAMETER_VALUE, NULL );
Expand Down
20 changes: 19 additions & 1 deletion mapows.h
Expand Up @@ -119,6 +119,13 @@ typedef struct {
char *httpcookiedata;
} wmsParamsObj;

/* metadataParamsObj: Represent a metadata specific request with its enabled layers */
typedef struct {
char *pszRequest;
char *pszLayer;
char *pszOutputSchema;
} metadataParamsObj;

/* owsRequestObj: Represent a OWS specific request with its enabled layers */
typedef struct {
int numlayers;
Expand Down Expand Up @@ -460,6 +467,16 @@ MS_DLL_EXPORT char *msWMSGetFeatureInfoURL(mapObj *map, layerObj *lp,
int msWMSLayerExecuteRequest(mapObj *map, int nOWSLayers, int nClickX, int nClickY,
int nFeatureCount, const char *pszInfoFormat, int type);

/*====================================================================
* mapmetadata.c
*====================================================================*/
metadataParamsObj *msMetadataCreateParamsObj(void);
void msMetadataFreeParamsObj(metadataParamsObj *metadataparams);
int msMetadataParseRequest(mapObj *map, cgiRequestObj *request, owsRequestObj *ows_request,
metadataParamsObj *metadataparams);
int msMetadataDispatch(mapObj *map, cgiRequestObj *requestobj, owsRequestObj *ows_request);
void msMetadataSetGetMetadataURL(layerObj *lp, const char *url);

/*====================================================================
* mapwfs.c
*====================================================================*/
Expand All @@ -484,7 +501,8 @@ int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *wfsparams,
cgiRequestObj *req, owsRequestObj *ows_request);
#ifdef USE_LIBXML2
xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws,
int nWFSVersion, const char* validate_language);
int nWFSVersion, const char* validate_language,
char *script_url);
#endif
char *msWFSGetOutputFormatList(mapObj *map, layerObj *layer, int nWFSVersion);

Expand Down
32 changes: 22 additions & 10 deletions mapwcs.c
Expand Up @@ -819,7 +819,7 @@ static int msWCSGetCapabilities_Capability(mapObj *map, wcsParamsObj *params, cg
/* msWCSGetCapabilities_CoverageOfferingBrief() */
/************************************************************************/

static int msWCSGetCapabilities_CoverageOfferingBrief(layerObj *layer, wcsParamsObj *params)
static int msWCSGetCapabilities_CoverageOfferingBrief(layerObj *layer, wcsParamsObj *params, char *script_url_encoded)
{
coverageMetadataObj cm;
int status;
Expand All @@ -833,6 +833,9 @@ static int msWCSGetCapabilities_CoverageOfferingBrief(layerObj *layer, wcsParams
msIO_printf(" <CoverageOfferingBrief>\n"); /* is this tag right? (I hate schemas without ANY examples) */

/* optional metadataLink */
if (! msOWSLookupMetadata(&(layer->metadata), "CO", "metadatalink_href"))
msMetadataSetGetMetadataURL(layer, script_url_encoded);

msOWSPrintURLType(stdout, &(layer->metadata), "CO", "metadatalink",
OWS_NOERR,
" <metadataLink%s%s%s%s xlink:type=\"simple\"%s/>",
Expand Down Expand Up @@ -869,9 +872,12 @@ static int msWCSGetCapabilities_CoverageOfferingBrief(layerObj *layer, wcsParams
/* msWCSGetCapabilities_ContentMetadata() */
/************************************************************************/

static int msWCSGetCapabilities_ContentMetadata(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request)
static int msWCSGetCapabilities_ContentMetadata(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request, cgiRequestObj *req)
{
int i;
char *script_url_encoded=NULL;

script_url_encoded = msEncodeHTMLEntities(msOWSGetOnlineResource(map, "CO", "onlineresource", req));

/* start the ContentMetadata section, only need the full start tag if this is the only section requested */
/* TODO: add Xlink attributes for other sources of this information */
Expand All @@ -894,7 +900,7 @@ static int msWCSGetCapabilities_ContentMetadata(mapObj *map, wcsParamsObj *param
if (!msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers))
continue;

if( msWCSGetCapabilities_CoverageOfferingBrief((GET_LAYER(map, i)), params) != MS_SUCCESS ) {
if(msWCSGetCapabilities_CoverageOfferingBrief((GET_LAYER(map, i)), params, script_url_encoded) != MS_SUCCESS ) {
msIO_printf("</ContentMetadata>\n");
return MS_FAILURE;
}
Expand Down Expand Up @@ -1006,12 +1012,12 @@ static int msWCSGetCapabilities(mapObj *map, wcsParamsObj *params, cgiRequestObj
msWCSGetCapabilities_Capability(map, params, req);

if(!params->section || strcasecmp(params->section, "/WCS_Capabilities/ContentMetadata") == 0)
msWCSGetCapabilities_ContentMetadata(map, params, ows_request);
msWCSGetCapabilities_ContentMetadata(map, params, ows_request, req);

if(params->section && strcasecmp(params->section, "/") == 0) {
msWCSGetCapabilities_Service(map, params);
msWCSGetCapabilities_Capability(map, params, req);
msWCSGetCapabilities_ContentMetadata(map, params, ows_request);
msWCSGetCapabilities_ContentMetadata(map, params, ows_request, req);
}

/* done */
Expand Down Expand Up @@ -1094,7 +1100,7 @@ static int msWCSDescribeCoverage_AxisDescription(layerObj *layer, char *name)
/* msWCSDescribeCoverage_CoverageOffering() */
/************************************************************************/

static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj *params)
static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj *params, char *script_url_encoded)
{
char **tokens;
int numtokens;
Expand All @@ -1119,6 +1125,9 @@ static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj
msIO_printf(" <CoverageOffering>\n");

/* optional metadataLink */
if (! msOWSLookupMetadata(&(layer->metadata), "CO", "metadatalink_href"))
msMetadataSetGetMetadataURL(layer, script_url_encoded);

msOWSPrintURLType(stdout, &(layer->metadata), "CO", "metadatalink",
OWS_NOERR,
" <metadataLink%s%s%s%s xlink:type=\"simple\"%s/>",
Expand Down Expand Up @@ -1306,14 +1315,17 @@ static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj
/* msWCSDescribeCoverage() */
/************************************************************************/

static int msWCSDescribeCoverage(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request)
static int msWCSDescribeCoverage(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request, cgiRequestObj *req)
{
int i = 0,j = 0, k = 0;
const char *updatesequence=NULL;
char **coverages=NULL;
int numcoverages=0;

char *coverageName=NULL;
char *script_url_encoded=NULL;

script_url_encoded = msEncodeHTMLEntities(msOWSGetOnlineResource(map, "CO", "onlineresource", req));

/* -------------------------------------------------------------------- */
/* 1.1.x is sufficiently different we have a whole case for */
Expand Down Expand Up @@ -1384,7 +1396,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSDescribeCoverage()"
}
msFree(coverageName);
}
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params);
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params, script_url_encoded);
}
msFreeCharArray(coverages,numcoverages);
}
Expand All @@ -1393,7 +1405,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSDescribeCoverage()"
if (!msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers))
continue;

msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params);
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params, script_url_encoded);
}
}

Expand Down Expand Up @@ -2242,7 +2254,7 @@ int msWCSDispatch(mapObj *map, cgiRequestObj *request, owsRequestObj *ows_reques
if (operation == MS_WCS_GET_CAPABILITIES) {
retVal = msWCSGetCapabilities(map, params, request, ows_request);
} else if (operation == MS_WCS_DESCRIBE_COVERAGE) {
retVal = msWCSDescribeCoverage(map, params, ows_request);
retVal = msWCSDescribeCoverage(map, params, ows_request, request);
} else if (operation == MS_WCS_GET_COVERAGE) {
retVal = msWCSGetCoverage(map, request, params, ows_request);
}
Expand Down
9 changes: 6 additions & 3 deletions mapwfs.c
Expand Up @@ -545,7 +545,7 @@ static layerObj* msWFSGetLayerByName(mapObj* map, owsRequestObj *ows_request, co
/*
** msWFSDumpLayer()
*/
int msWFSDumpLayer(mapObj *map, layerObj *lp)
int msWFSDumpLayer(mapObj *map, layerObj *lp, const char *script_url_encoded)
{
rectObj ext;
char *pszWfsSrs = NULL;
Expand Down Expand Up @@ -613,8 +613,11 @@ int msWFSDumpLayer(mapObj *map, layerObj *lp)
msIO_printf("<!-- WARNING: Optional LatLongBoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement -->\n");
}

if (! msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href"))
msMetadataSetGetMetadataURL(lp, script_url_encoded);

msOWSPrintURLType(stdout, &(lp->metadata), "FO", "metadataurl",
OWS_NOERR, NULL, "MetadataURL", " type=\"%s\"",
OWS_WARN, NULL, "MetadataURL", " type=\"%s\"",
NULL, NULL, " format=\"%s\"", "%s",
MS_TRUE, MS_FALSE, MS_FALSE, MS_TRUE, MS_TRUE,
NULL, NULL, NULL, NULL, NULL, " ");
Expand Down Expand Up @@ -869,7 +872,7 @@ int msWFSGetCapabilities(mapObj *map, wfsParamsObj *wfsparams, cgiRequestObj *re
continue;

if (msWFSIsLayerAllowed(lp, ows_request)) {
msWFSDumpLayer(map, lp);
msWFSDumpLayer(map, lp, script_url_encoded);
}
}

Expand Down
7 changes: 5 additions & 2 deletions mapwfs11.c
Expand Up @@ -94,7 +94,8 @@ int msWFSException11(mapObj *map, const char *locator,
/* msWFSDumpLayer11 */
/************************************************************************/
xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws,
int nWFSVersion, const char* validate_language)
int nWFSVersion, const char* validate_language,
char *script_url)
{
rectObj ext;

Expand Down Expand Up @@ -222,6 +223,8 @@ xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws,
xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement"));
}

if (! msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href"))
msMetadataSetGetMetadataURL(lp, script_url);
value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href");

if (value) {
Expand Down Expand Up @@ -454,7 +457,7 @@ int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params,

/* List only vector layers in which DUMP=TRUE */
if (msWFSIsLayerSupported(lp))
xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws, OWS_1_1_0, NULL));
xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws, OWS_1_1_0, NULL, script_url));
}


Expand Down
2 changes: 1 addition & 1 deletion mapwfs20.c
Expand Up @@ -711,7 +711,7 @@ int msWFSGetCapabilities20(mapObj *map, wfsParamsObj *params,
if (msWFSIsLayerSupported(lp))
{
if( psFtNode != NULL ) {
xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws, OWS_2_0_0, validated_language));
xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws, OWS_2_0_0, validated_language, script_url));
}

/* As soon as at least one layer supports sorting, advertize sorting */
Expand Down
3 changes: 3 additions & 0 deletions mapwms.c
Expand Up @@ -2260,6 +2260,9 @@ int msDumpLayer(mapObj *map, layerObj *lp, int nVersion, const char *script_url_
}

if(nVersion >= OWS_1_1_0)
if (! msOWSLookupMetadata(&(lp->metadata), "MO", "metadataurl_href"))
msMetadataSetGetMetadataURL(lp, script_url_encoded);

msOWSPrintURLType(stdout, &(lp->metadata), "MO", "metadataurl",
OWS_NOERR, NULL, "MetadataURL", " type=\"%s\"",
NULL, NULL, ">\n <Format>%s</Format",
Expand Down
28 changes: 28 additions & 0 deletions msautotest/misc/expected/runtime_sub_test_caps.xml
Expand Up @@ -51,18 +51,30 @@ Content-Type: text/xml; charset=UTF-8
<!-- WARNING: Mandatory metadata '..._title' was missing in this context. -->
<Title>layer1</Title>
<!-- WARNING: Optional Ex_GeographicBoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wms_extent metadata. Also check that your data exists in the DATA statement -->
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer1"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer2</Name>
<!-- WARNING: Mandatory metadata '..._title' was missing in this context. -->
<Title>layer2</Title>
<!-- WARNING: Optional Ex_GeographicBoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wms_extent metadata. Also check that your data exists in the DATA statement -->
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer2"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer3</Name>
<!-- WARNING: Mandatory metadata '..._title' was missing in this context. -->
<Title>layer3</Title>
<!-- WARNING: Optional Ex_GeographicBoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wms_extent metadata. Also check that your data exists in the DATA statement -->
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer3"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer5</Name>
Expand All @@ -76,6 +88,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:3857"
minx="123446" miny="4.76081e+06" maxx="801225" maxy="5.48737e+06" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer5"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer6</Name>
Expand All @@ -89,6 +105,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:3857"
minx="123446" miny="4.76081e+06" maxx="801225" maxy="5.48737e+06" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer6"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer7</Name>
Expand All @@ -102,6 +122,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:3857"
minx="123446" miny="4.76081e+06" maxx="801225" maxy="5.48737e+06" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer7"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>layer8</Name>
Expand All @@ -115,6 +139,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:3857"
minx="123446" miny="4.76081e+06" maxx="801225" maxy="5.48737e+06" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/?request=GetMetadata&amp;layer=layer8"/>
</MetadataURL>
</Layer>
</Layer>
</Capability>
Expand Down
8 changes: 8 additions & 0 deletions msautotest/wxs/expected/ows_all_wms_capabilities.xml
Expand Up @@ -148,6 +148,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:43204"
minx="2.25898e+06" miny="-70747.9" maxx="2.61535e+06" maxy="495481" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/path/to/ows?request=GetMetadata&amp;layer=road"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
Expand All @@ -167,6 +171,10 @@ Content-Type: text/xml; charset=UTF-8
<southBoundLatitude>41.7705</southBoundLatitude>
<northBoundLatitude>48.4773</northBoundLatitude>
</EX_GeographicBoundingBox>
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/path/to/ows?request=GetMetadata&amp;layer=province"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
Expand Down
8 changes: 8 additions & 0 deletions msautotest/wxs/expected/ows_all_wms_capabilities_post.xml
Expand Up @@ -148,6 +148,10 @@ Content-Type: text/xml; charset=UTF-8
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:43204"
minx="2.25898e+06" miny="-70747.9" maxx="2.61535e+06" maxy="495481" />
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/path/to/ows?request=GetMetadata&amp;layer=road"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
Expand All @@ -167,6 +171,10 @@ Content-Type: text/xml; charset=UTF-8
<southBoundLatitude>41.7705</southBoundLatitude>
<northBoundLatitude>48.4773</northBoundLatitude>
</EX_GeographicBoundingBox>
<MetadataURL type="ISOTC211/19115">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/path/to/ows?request=GetMetadata&amp;layer=province"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
Expand Down
3 changes: 3 additions & 0 deletions msautotest/wxs/expected/ows_metadata_302_layer_param.xml
@@ -0,0 +1,3 @@
Status: 301 Moved Permanently
Location: http://localhost/md

0 comments on commit c8190e5

Please sign in to comment.