Ejemplo n.º 1
0
  /**
   * This transforms all external graphics references that are relative to absolute. This is a
   * workaround to be able to visualize png and svg in relative mode, which doesn't work right now
   * in geotools. See: http://jira.codehaus.org/browse/GEOT-3235
   *
   * <p>This will not be necessary any more as soon as the geotools bug is fixed.
   *
   * @param relatedFile the related shapefile.
   * @param style the style to check.
   */
  private void makeGraphicsAbsolute(File relatedFile, Style style) {
    File parentFolder = relatedFile.getParentFile();
    Rule[] rules = SLDs.rules(style);
    for (Rule rule : rules) {
      Symbolizer[] onlineResource = rule.getSymbolizers();

      for (Symbolizer symbolizer : onlineResource) {
        if (symbolizer instanceof PointSymbolizer) {
          PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
          Graphic graphic = SLDs.graphic(pointSymbolizer);
          List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();
          for (GraphicalSymbol graphicalSymbol : graphicalSymbols) {
            if (graphicalSymbol instanceof ExternalGraphic) {
              ExternalGraphic externalGraphic = (ExternalGraphic) graphicalSymbol;
              try {
                URL location = externalGraphic.getLocation();
                File urlToFile = URLUtils.urlToFile(location);
                if (urlToFile != null && !urlToFile.exists()) {
                  File newFile = new File(parentFolder, urlToFile.getPath());
                  if (newFile.exists()) {
                    externalGraphic.setLocation(newFile.toURI().toURL());
                  }
                }
              } catch (MalformedURLException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 Symbolizer[] getSymbolizers(Style style) {
   List<Symbolizer> symbs = new ArrayList<Symbolizer>();
   FeatureTypeStyle[] styles = style.getFeatureTypeStyles();
   for (int i = 0; i < styles.length; i++) {
     FeatureTypeStyle fstyle = styles[i];
     Rule[] rules = fstyle.getRules();
     for (int j = 0; j < rules.length; j++) {
       Rule rule = rules[j];
       symbs.addAll(Arrays.asList(rule.getSymbolizers()));
     }
   }
   return symbs.toArray(new Symbolizer[symbs.size()]);
 }
 /**
  * Returns a sample feature for the given rule, with the following criteria: - if a sample is
  * given in input is returned in output - if a sample is not given in input, scan the rule
  * symbolizers to find the one with the max dimensionality, and return a sample for that
  * dimensionality.
  *
  * @param featureType featureType used to create a sample, if none is given as input
  * @param sample feature sample to be returned as is in output, if defined
  * @param rule rule containing symbolizers to scan for max dimensionality
  */
 private Feature getSampleFeatureForRule(
     FeatureType featureType, Feature sample, final Rule rule) {
   Symbolizer[] symbolizers = rule.getSymbolizers();
   // if we don't have a sample as input, we need to create a sampleFeature
   // looking at the requested symbolizers (we chose the one with the max
   // dimensionality and create a congruent sample)
   if (sample == null) {
     int dimensionality = 1;
     for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
       final Symbolizer symbolizer = symbolizers[sIdx];
       if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
         dimensionality = 2;
       }
       if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) {
         dimensionality = 3;
       }
     }
     return createSampleFeature(featureType, dimensionality);
   } else {
     return sample;
   }
 }
Ejemplo n.º 4
0
 Symbolizer[] getSymbolizers(Rule rule) {
   List<Symbolizer> symbs = new ArrayList<Symbolizer>();
   symbs.addAll(Arrays.asList(rule.getSymbolizers()));
   return symbs.toArray(new Symbolizer[symbs.size()]);
 }