Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalGraphic's Format not set (geostyyler -> sld) #895

Open
joserwan opened this issue Oct 14, 2023 · 3 comments
Open

ExternalGraphic's Format not set (geostyyler -> sld) #895

joserwan opened this issue Oct 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@joserwan
Copy link

joserwan commented Oct 14, 2023

Bug

Describe the bug

The <Format> tag is missing when converting from geostyler to SLD.

To Reproduce

const { SldStyleParser } = await import("geostyler-sld-parser");
const geostyle = {
  rules: [
    {
      name: 'MissingFormat',
      symbolizers: [{kind: "Icon", image: '/path/to/icon.png'}],
    },
  ]
}
const parser = new SldStyleParser({ builderOptions: { format: true }});

parser.writeStyle(geostyle).then(({ output: sld }) => console.log(sld));

Result:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se">
  <NamedLayer>
    <Name/>
    <UserStyle>
      <Name/>
      <Title/>
      <FeatureTypeStyle>
        <Rule>
          <Name>MissingFormat</Name>
          <PointSymbolizer>
            <Graphic>
              <ExternalGraphic>
                <OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/path/to/icon.png"/>
              </ExternalGraphic>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Expected behavior

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se">
  <NamedLayer>
    <Name/>
    <UserStyle>
      <Name/>
      <Title/>
      <FeatureTypeStyle>
        <Rule>
          <Name>MissingFormat</Name>
          <PointSymbolizer>
            <Graphic>
              <ExternalGraphic>
                <OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/path/to/icon.png"/>
                <Format>image/png</Format>
              </ExternalGraphic>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Additional context
Node v20.8.0
Debian
geostler-sld-parser v5.1.0

My fix

diff --git a/src/SldStyleParser.ts b/src/SldStyleParser.ts
index 0373158..eb0ccfa 100644
--- a/src/SldStyleParser.ts
+++ b/src/SldStyleParser.ts
@@ -1739,13 +1739,13 @@ export class SldStyleParser implements StyleParser<string> {
         case 'png':
         case 'jpeg':
         case 'gif':
-          graphic[0][ExternalGraphic][0][Format] = [`image/${iconExt}`];
+          graphic[0][ExternalGraphic][1] = { [Format]:  [{ '#text': `image/${iconExt}` }] };
           break;
         case 'jpg':
-          graphic[0][ExternalGraphic][0][Format] = ['image/jpeg'];
+          graphic[0][ExternalGraphic][1] = { [Format]:  [{ '#text': `image/jpeg` }] };
           break;
         case 'svg':
-          graphic[0][ExternalGraphic][0][Format] = ['image/svg+xml'];
+          graphic[0][ExternalGraphic][1] = { [Format]:  [{ '#text': `image/svg+xml` }] };
           break;
         default:
           break;

PS: Thank you for your awesome work !!

@joserwan joserwan added the bug Something isn't working label Oct 14, 2023
@jansule
Copy link
Contributor

jansule commented Oct 16, 2023

Thanks for the info @joserwan!

We actually do provide a format property in geostyler-style (see https://github.com/geostyler/geostyler-style/blob/master/style.ts#L431). However, it seems like we do not use it yet in geostyler-sld-parser.

I would suggest to adjust following things:

  • could you make use of this.getTagName('format'), so that we support both SLD versions?
  • could you also check if the format property on the geostyler style is set, and only derive the format from the file name as fallback?

Also, it would be great if you could create a Pull Request for this 🚀

@joserwan
Copy link
Author

Sorry for the delay, I missed the notification.

I'll have a look on that in the next weeks, for now I'm too busy. Thank you for your feedback !

@KaiVolland
Copy link
Contributor

@joserwan are you still planing on providing a PR here? Otherwise we might have the chance to fix this during the next codes sprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants