Reading-eScience-Centre / edal-java

Environmental Data Abstraction Layer libraries
Other
39 stars 30 forks source link

How to make a new style recognized by a layer? #116

Closed docgregt closed 5 years ago

docgregt commented 5 years ago

I created a new style which is just a copy of vector_wind_barbs.xml and made some minor tweaks and then place it in the .styles folder and then restarted ncWMS server. My sld file is called i4windbarbs.xml so in my WMS params I specified 'STYLES': 'i4windbarbs/default' I also tried: 'STYLES': 'i4windbarbs' I always get the error: 2019-03-20 16:05:47 WARN WmsServlet:2639 - Wms Exception caught: "The layer hist/winddir does not support the style i4windbarbs" from:uk.ac.rdg.resc.edal.wms.GetMapStyleParams:385

The layer works fine with 'STYLES': 'default-arrows/default' but I dont want arrows.

The get metadata query shows this: "supportedStyles": [ "default-arrows", "default-scalar", "arrows", "colored_contours", "contours", "fat_arrows", "meteorological_arrows", "meteorological_fat_arrows", "meteorological_triangle_arrows", "raster", "triangle_arrows", "upstream_dots" ], The documentation says: "Once you have created these templates, you may either place them in a subdirectory of the main config directory named .styles, or override the styleDirs context parameter, similar to the palettes directory above" But it does not work for me. How do I add a style so that it will be recognized or allowed with a layer?

guygriffiths commented 5 years ago

The vector_wind_barbs.xml style, is only compatible with a parent vector layer which contains 2 children - one representing magnitude, and one representing direction (this is what $layerName-mag and $layerName-dir represent. These particular child properties are created when a vector field is automatically detected). winddir sounds like it is a single directional field, and so will not be compatible.

If it works with default-arrows, I would recommend modifying that style. The reason there isn't already a simple direction-only wind barbs style is that wind barbs represent both magnitude and direction.

docgregt commented 5 years ago

I modified it like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld
StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:resc="http://www.resc.reading.ac.uk">
  <NamedLayer>
    <se:Name>hist/winddir</se:Name>
    <UserStyle>
      <se:CoverageStyle>
        <se:Rule>
          <resc:SizedArrowSymbolizer>
            <se:Opacity>$opacity</se:Opacity>
            <resc:ArrowSizeField>hist/windspd</resc:ArrowSizeField>
            <resc:ArrowMinSize>4</resc:ArrowMinSize>
            <resc:ArrowMaxSize>12</resc:ArrowMaxSize>
            <resc:ArrowColour>#FF000000</resc:ArrowColour>
            <resc:ArrowStyle>WIND_BARBS</resc:ArrowStyle>
            <resc:Range>
              <resc:Minimum>$scaleMin</resc:Minimum>
              <resc:Maximum>$scaleMax</resc:Maximum>
              <resc:Spacing>$logarithmic</resc:Spacing>
            </resc:Range>
          </resc:SizedArrowSymbolizer>
        </se:Rule>
      </se:CoverageStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

This follows the edal spec. Why doesnt it work?

guygriffiths commented 5 years ago

I have copied and pasted that into a file named i4windbarbs.xml in ~/.ncWMS2/.styles/. I then started ncWMS, and added the last data file you sent me as hist, and hit the URL:

http://localhost:8080/ncWMS2/wms?REQUEST=GetMap&VERSION=1.3.0&STYLES=i4windbarbs&CRS=CRS:84&WIDTH=1024&HEIGHT=512&FORMAT=image/png&TRANSPARENT=true&LAYERS=hist/winddir&BBOX=-180.0,-90,180.0,90

I got a global image of wind barbs as expected. I'm using version ncWMS v2.4.2-SNAPSHOT, as seen on the admin page.

When I make the request: http://localhost:8080/ncWMS2/wms?REQUEST=GetMetadata&item=layerDetails&VERSION=1.3.0&LAYERNAME=hist/winddir

The returned document contains the following:

    "supportedStyles": [
        "default-arrows",
        "default-scalar",
        "arrows",
        "colored_contours",
        "contours",
        "fat_arrows",
        "i4windbarbs",
        "meteorological_arrows",
        "meteorological_fat_arrows",
        "meteorological_triangle_arrows",
        "raster",
        "triangle_arrows",
        "upstream_dots"
    ],

I'm afraid I have no idea why it is not working on your machine - everything you've done is correct and works perfectly on my installation.

docgregt commented 5 years ago

Thanks for you time in checking it out. I have a couple questions: 1) Is this server is written in Java? 2) Is it self contained or does it depend on some global java libraries? 3) It seems to work differently on my windows than on linux so I am wondering if Java class path or different Java versions are affecting it?

guygriffiths commented 5 years ago
  1. It is written in Java, although technically it's a servlet and requires a servlet container to provide the server capabilities. This is usually Apache Tomcat, but Winstone is used for the standalone version
  2. It is mostly self-contained. It requires the servlet container to provide certain standard classes, but all necessary libraries etc. are contained in the WAR file
  3. That is a possibility, although I'd be surprised if it was causing this issue.

One thing I would recommend doing would be copying a style verbatim, just giving it a different name in your .ncWMS2/.styles/ directory. If you are unable to use that style, it would suggest that the style directory is not being picked up correctly. The other thing to check is any output errors from your servlet container. If you're running the standalone version, they should be output on the command line, otherwise they will be logged to file somewhere. If you see anything there, paste the whole lot here (it might be rather long, but don't worry about that)

docgregt commented 5 years ago

Also, I only have 2.4.1: image

So it seems like you have the good stuff :) Where can I get 2.4.2 standalone?

docgregt commented 5 years ago

Ok. Ignore my last. The 2.4.2 Snapshot is the one you sent me. I am unable to get that one to work with any of my data. So there must be some environmental issue affecting it. For example no matter what I do I cannot get the exact same file i sent you to work. It always looks like: image

If for example i select the temperature layer then it renders in default colors but if I select the xSst colors then I get the following error: [Winstone 2019/03/21 16:59:13] - Untrapped Error in Servlet java.lang.NoSuchMethodError: org.opengis.referencing.datum.Ellipsoid.getAxisUnit()Ljavax/measure/Unit; at org.apache.sis.referencing.datum.DefaultEllipsoid.castOrCopy(DefaultEllipsoid.java:340) at org.apache.sis.internal.referencing.WKTUtilities.toFormattable(WKTUtilities.java:154) at org.apache.sis.referencing.datum.DefaultGeodeticDatum.formatTo(DefaultGeodeticDatum.java:617) at org.apache.sis.io.wkt.Formatter.append(Formatter.java:664) at org.apache.sis.referencing.crs.DefaultGeodeticCRS.formatTo(DefaultGeodeticCRS.java:202) at org.apache.sis.referencing.crs.DefaultGeographicCRS.formatTo(DefaultGeographicCRS.java:318) at org.apache.sis.io.wkt.Formatter.append(Formatter.java:664) at org.apache.sis.io.wkt.FormattableObject.formatWKT(FormattableObject.java:199) at org.apache.sis.io.wkt.FormattableObject.toString(FormattableObject.java:126) at uk.ac.rdg.resc.edal.geometry.BoundingBoxImpl.equals(BoundingBoxImpl.java:251) at uk.ac.rdg.resc.edal.graphics.utils.PlottingDomainParams.equals(PlottingDomainParams.java:160) at uk.ac.rdg.resc.edal.catalogue.DataCatalogue$CacheKey.equals(DataCatalogue.java:533) at net.sf.ehcache.store.chm.SelectableConcurrentHashMap$Segment.get(SelectableConcurrentHashMap.java:726) at net.sf.ehcache.store.chm.SelectableConcurrentHashMap.get(SelectableConcurrentHashMap.java:324) at net.sf.ehcache.store.MemoryStore.get(MemoryStore.java:326) at net.sf.ehcache.Cache.get(Cache.java:1723) at net.sf.ehcache.Cache.get(Cache.java:1696) at uk.ac.rdg.resc.edal.catalogue.DataCatalogue.getFeaturesForLayer(DataCatalogue.java:468) at uk.ac.rdg.resc.edal.graphics.style.GriddedImageLayer$MapFeatureDataReader.extractFeature(GriddedImageLayer.java:86) at uk.ac.rdg.resc.edal.graphics.style.GriddedImageLayer$MapFeatureDataReader.getFeature(GriddedImageLayer.java:77) at uk.ac.rdg.resc.edal.graphics.style.GriddedImageLayer$MapFeatureDataReader.getDataForLayerName(GriddedImageLayer.java:131) at uk.ac.rdg.resc.edal.graphics.style.RasterLayer.drawIntoImage(RasterLayer.java:73) at uk.ac.rdg.resc.edal.graphics.style.GriddedImageLayer.drawIntoImage(GriddedImageLayer.java:180) at uk.ac.rdg.resc.edal.graphics.style.ImageLayer.drawImage(ImageLayer.java:51) at uk.ac.rdg.resc.edal.graphics.style.MapImage.drawImage(MapImage.java:69) at uk.ac.rdg.resc.edal.wms.WmsServlet.getMap(WmsServlet.java:536) at uk.ac.rdg.resc.edal.wms.WmsServlet.dispatchWmsRequest(WmsServlet.java:368) at uk.ac.rdg.resc.edal.ncwms.NcwmsServlet.dispatchWmsRequest(NcwmsServlet.java:212) at uk.ac.rdg.resc.edal.wms.WmsServlet.doGet(WmsServlet.java:303) at javax.servlet.http.HttpServlet.service(HttpServlet.java:104) at javax.servlet.http.HttpServlet.service(HttpServlet.java:45) at winstone.ServletConfiguration.execute(ServletConfiguration.java:249) at winstone.RequestDispatcher.forward(RequestDispatcher.java:335) at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:378) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:168) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:233) at winstone.FilterConfiguration.execute(FilterConfiguration.java:195) at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368) at winstone.RequestDispatcher.forward(RequestDispatcher.java:333) at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:244) at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150) at java.lang.Thread.run(Thread.java:748)

docgregt commented 5 years ago

So I did as you said and just copied a standard sld file and renamed it. For some reason that worked. Then when I looked now my wind barb style is working also. I don't know what happened. I was able to get my wind speed looking exactly like I wanted also: image

All of this is on 2.4.1. I cannot get 2.4.2 to work in a general way. Some things work, but mostly it doesn't work meaning the server spits out the exceptions as in my previous message. But also the grouping doesn't work for me. I don't know why it works for you. Thank you so much for your time as I know you are busy.

docgregt commented 5 years ago

We can close this issue as 2.4.2 is a part of the other issue.