1

I'd like to import several SLD files into GeoServer (Various styles for OS Open Zoomstack, thanks @OrdnanceSurvey!)

Is the only option to import them one at at time using the GeoServer interface? I copied the files into the Styles folder, but that didn't work.

Am I missing something, or is this it?

2 Answers 2

2

You can also write a script talking to the REST API: https://docs.geoserver.org/latest/en/user/rest/styles.html

Or you can generate the necessary XML files with a custom script as well, it's not hard, I did so recently writing a small Java class (as it's my programming language of trade). And nope, I cannot share the source code of it, sorry....

0

I wrote some code last year that should get you started, see my blog for more details.

It uses GeoServer Manager to handle the rest calls:

 private void createStyle(String table, File styleDir) {
    // We always search for name + "." otherwise rail matches railstations etc.
    File styleFile = null;
    for (File file : styleDir.listFiles()) {
      if (file.getName().toLowerCase().startsWith(table + ".")) {
        styleFile = file;
        break;
      }
    }
    if (styleFile == null) {
      // try with out an s on the end of the layername
      for (File file : styleDir.listFiles()) {
        if (file.getName().toLowerCase().startsWith(table.substring(0, table.length() - 2) + ".")) {
          styleFile = file;
          break;
        }
      }

    }
    if (styleFile != null) {
      if (reader.existsStyle(table)) {
        publisher.updateStyle(styleFile, table);
      } else {
        publisher.publishStyle(styleFile, table);
      }
    } else {
      System.err.println("no style found for " + table);
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.