** msOWSGetProjURN() ** ** Fetch an OGC URN for this layer or map. Similar to msOWSGetEPSGProj() ** but returns the result in the form "urn:ogc:def:crs:EPSG::27700". ** The returned buffer is dynamically allocated, and must be freed by the ** caller. */
| 1891 | ** caller. |
| 1892 | */ |
| 1893 | char *msOWSGetProjURN(projectionObj *proj, hashTableObj *metadata, const char *namespaces, int bReturnOnlyFirstOne) |
| 1894 | { |
| 1895 | char *result; |
| 1896 | char **tokens; |
| 1897 | int numtokens, i; |
| 1898 | size_t bufferSize = 0; |
| 1899 | |
| 1900 | const char *oldStyle = msOWSGetEPSGProj( proj, metadata, namespaces, |
| 1901 | bReturnOnlyFirstOne ); |
| 1902 | |
| 1903 | if( oldStyle == NULL || strncmp(oldStyle,"EPSG:",5) != 0 ) |
| 1904 | return NULL; |
| 1905 | |
| 1906 | result = msStrdup(""); |
| 1907 | |
| 1908 | tokens = msStringSplit(oldStyle, ' ', &numtokens); |
| 1909 | for(i=0; tokens != NULL && i<numtokens; i++) |
| 1910 | { |
| 1911 | char urn[100]; |
| 1912 | |
| 1913 | if( strncmp(tokens[i],"EPSG:",5) == 0 ) |
| 1914 | snprintf( urn, sizeof(urn), "urn:ogc:def:crs:EPSG::%s", tokens[i]+5 ); |
| 1915 | else if( strcasecmp(tokens[i],"imageCRS") == 0 ) |
| 1916 | snprintf( urn, sizeof(urn), "urn:ogc:def:crs:OGC::imageCRS" ); |
| 1917 | else if( strncmp(tokens[i],"urn:ogc:def:crs:",16) == 0 ) { |
| 1918 | strlcpy( urn, tokens[i], sizeof(urn)); |
| 1919 | } |
| 1920 | else { |
| 1921 | strlcpy( urn, "", sizeof(urn)); |
| 1922 | } |
| 1923 | |
| 1924 | if( strlen(urn) > 0 ) |
| 1925 | { |
| 1926 | bufferSize = strlen(result)+strlen(urn)+2; |
| 1927 | result = (char *) realloc(result, bufferSize); |
| 1928 | |
| 1929 | if( strlen(result) > 0 ) |
| 1930 | strlcat( result, " ", bufferSize); |
| 1931 | strlcat( result, urn , bufferSize); |
| 1932 | } |
| 1933 | else |
| 1934 | { |
| 1935 | msDebug( "msOWSGetProjURN(): Failed to process SRS '%s', ignored.", |
| 1936 | tokens[i] ); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | msFreeCharArray(tokens, numtokens); |
| 1941 | |
| 1942 | if( strlen(result) == 0 ) |
| 1943 | { |
| 1944 | msFree( result ); |
| 1945 | return NULL; |
| 1946 | } |
| 1947 | else |
| 1948 | return result; |
| 1949 | } |
| 1950 |
no test coverage detected