Estoy utilizando las APIs REST para publicar y cambiar el estilo por defecto de las capas publicadas en GeoServer. Cuando copio el SLD y lo pego directamente en los estilos de GeoServer funciona bien. pero al usar la API REST omite la simbología completa y no se asigna ningún estilo. la simbología importada es como sigue
<sld:PolygonSymbolizer>
<sld:Fill/>
<sld:Stroke/>
</sld:PolygonSymbolizer>
El siguiente script carga el sld desde un archivo local y lo publica utilizando la API REST:
async function loadSld(urls) {
try {
const response = await fetch(urls);
sld = await response.text();
} catch (err) {
console.error(err, 'error loading sld');
}
const url = "http://localhost:8080/geoserver/rest/styles";
await fetch(url, {
method: "POST",
headers: {
"Content-type": "application/vnd.ogc.sld+xml",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
Authorization: "Basic YWRtaW46Z2Vvc2VydmVy",
},
body: sld,
})
.then((response) => {
res = response;
console.log(res, 'response after sld');
console.log(sld, 'sld');
if (res.statusText !== "Created") {
console.log(res, 'response');
}
})
.catch((error) => {
console.error("Error:", error);
});
}
el sld es el siguiente:
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1.0" xmlns:se="http://www.opengis.net/se">
<NamedLayer>
<se:Name>Pakistan_with_Kashmir</se:Name>
<UserStyle>
<se:Name>Pakistan_with_Kashmir</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>0 - 1.6</se:Name>
<se:Description>
<se:Title>0 - 1.6</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>1.60000000000000009</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:And>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name="fill">#ffffff</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">1</se:SvgParameter>
<se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
</se:Stroke>
</se:PolygonSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>1.6 - 3.2</se:Name>
<se:Description>
<se:Title>1.6 - 3.2</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>1.60000000000000009</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>3.20000000000000018</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:And>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name="fill">#ffbfbf</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">1</se:SvgParameter>
<se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
</se:Stroke>
</se:PolygonSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>3.2 - 4.8</se:Name>
<se:Description>
<se:Title>3.2 - 4.8</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>3.20000000000000018</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>4.79999999999999982</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:And>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name="fill">#ff8080</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">1</se:SvgParameter>
<se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
</se:Stroke>
</se:PolygonSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>4.8 - 6.4</se:Name>
<se:Description>
<se:Title>4.8 - 6.4</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>4.79999999999999982</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>6.40000000000000036</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:And>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name="fill">#ff4040</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">1</se:SvgParameter>
<se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
</se:Stroke>
</se:PolygonSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>6.4 - 8</se:Name>
<se:Description>
<se:Title>6.4 - 8</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>6.40000000000000036</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>PROVINCE_C</ogc:PropertyName>
<ogc:Literal>8</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:And>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name="fill">#ff0000</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">1</se:SvgParameter>
<se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
</se:Stroke>
</se:PolygonSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>