1 |
|
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
|
* |
4 |
|
* This file is part of the SCHMITZM library - a collection of utility |
5 |
|
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
|
* and the Geotools library. |
7 |
|
* |
8 |
|
* The SCHMITZM project is hosted at: |
9 |
|
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
* |
11 |
|
* This program is free software; you can redistribute it and/or |
12 |
|
* modify it under the terms of the GNU Lesser General Public License |
13 |
|
* as published by the Free Software Foundation; either version 3 |
14 |
|
* of the License, or (at your option) any later version. |
15 |
|
* |
16 |
|
* This program is distributed in the hope that it will be useful, |
17 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
* GNU General Public License for more details. |
20 |
|
* |
21 |
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
* along with this program; if not, write to the Free Software |
23 |
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
|
* |
26 |
|
* Contributors: |
27 |
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
|
* Stefan A. Krüger - additional utility classes |
29 |
|
******************************************************************************/ |
30 |
/** |
/** |
31 |
Copyright 2008 Stefan Alfons Krüger and parts from some Geotools code |
Copyright 2008 Stefan Alfons Krüger and parts from some Geotools code |
32 |
|
|
60 |
import org.geotools.factory.GeoTools; |
import org.geotools.factory.GeoTools; |
61 |
import org.geotools.factory.Hints; |
import org.geotools.factory.Hints; |
62 |
import org.geotools.feature.AttributeType; |
import org.geotools.feature.AttributeType; |
|
import org.geotools.feature.Feature; |
|
|
import org.geotools.feature.FeatureType; |
|
63 |
import org.geotools.feature.IllegalAttributeException; |
import org.geotools.feature.IllegalAttributeException; |
64 |
import org.geotools.geometry.jts.LiteShape2; |
import org.geotools.geometry.jts.LiteShape2; |
65 |
import org.geotools.renderer.lite.StyledShapePainter; |
import org.geotools.renderer.lite.StyledShapePainter; |
74 |
import org.geotools.styling.Symbolizer; |
import org.geotools.styling.Symbolizer; |
75 |
import org.geotools.styling.TextSymbolizer; |
import org.geotools.styling.TextSymbolizer; |
76 |
import org.geotools.util.NumberRange; |
import org.geotools.util.NumberRange; |
77 |
|
import org.opengis.feature.simple.SimpleFeature; |
78 |
|
import org.opengis.feature.simple.SimpleFeatureType; |
79 |
|
|
80 |
import schmitzm.geotools.feature.FeatureUtil; |
import schmitzm.geotools.feature.FeatureUtil; |
81 |
|
|
92 |
* <br> |
* <br> |
93 |
* <ul> |
* <ul> |
94 |
* <li>07.02.2008:<br> |
* <li>07.02.2008:<br> |
95 |
* Determining the default values of a {@link FeatureType} by |
* Determining the default values of a {@link SimpleFeatureType} by |
96 |
* {@link FeatureUtil#getDefaultAttributeValues(FeatureType)} instead of using |
* {@link FeatureUtil#getDefaultAttributeValues(SimpleFeatureType)} instead of using |
97 |
* {@link AttributeType#createDefaultValue()} directly, because the latter |
* {@link AttributeType#createDefaultValue()} directly, because the latter |
98 |
* returns {@code null} even though the attribut is not nillable.</li> |
* returns {@code null} even though the attribut is not nillable.</li> |
99 |
* </ul> |
* </ul> |
247 |
/** |
/** |
248 |
* Puts a BufferedImage into this.legendGraphic |
* Puts a BufferedImage into this.legendGraphic |
249 |
*/ |
*/ |
250 |
public void produceLegendGraphic(FeatureType featureType, Style gt2Style, |
public void produceLegendGraphic(SimpleFeatureType featureType, Style gt2Style, |
251 |
Rule[] applicableRules) { |
Rule[] applicableRules) { |
252 |
|
|
253 |
// final FeatureTypeStyle[] ftStyles = gt2Style.getFeatureTypeStyles(); |
// final FeatureTypeStyle[] ftStyles = gt2Style.getFeatureTypeStyles(); |
448 |
|
|
449 |
/** |
/** |
450 |
* Creates a little BufferedImage that presents the Style/Symbols used by |
* Creates a little BufferedImage that presents the Style/Symbols used by |
451 |
* the {@link MapLegend} to show a legend for the {@link FeatureType} |
* the {@link MapLegend} to show a legend for the {@link SimpleFeatureType} |
452 |
* |
* |
453 |
* @param rule |
* @param rule |
454 |
* {@link Rule} that provides the text and the style to present |
* {@link Rule} that provides the text and the style to present |
455 |
* @param featureType |
* @param featureType |
456 |
* Schema that describes the kind of the sample {@link Feature} |
* Schema that describes the kind of the sample {@link SimpleFeature} |
457 |
* that will be rendered with the {@link Style} |
* that will be rendered with the {@link Style} |
458 |
* @param bg |
* @param bg |
459 |
* Background {@link Color} or <code>null</code> |
* Background {@link Color} or <code>null</code> |
460 |
* |
* |
461 |
* @throws IllegalAttributeException |
* @throws IllegalAttributeException |
462 |
*/ |
*/ |
463 |
public BufferedImage createImageForRule(Rule rule, FeatureType featureType, |
public BufferedImage createImageForRule(Rule rule, SimpleFeatureType featureType, |
464 |
Dimension size, Color bg) { |
Dimension size, Color bg) { |
465 |
|
|
466 |
Symbolizer[] symbolizers = rule.getSymbolizers(); |
Symbolizer[] symbolizers = rule.getSymbolizers(); |
504 |
// RasterSymbolizers.."); |
// RasterSymbolizers.."); |
505 |
// } |
// } |
506 |
// else |
// else |
507 |
final Feature sampleFeature = FeatureUtil.createSampleFeature(featureType); |
final SimpleFeature sampleFeature = FeatureUtil.createSampleFeature(featureType); |
508 |
|
|
509 |
// The SLDStyleFactory has to be recreated, as it seams to cache |
// The SLDStyleFactory has to be recreated, as it seams to cache |
510 |
// some stuff. |
// some stuff. |
559 |
|
|
560 |
/** |
/** |
561 |
* Creates a little BufferedImage that presents the Style/Symbols used by |
* Creates a little BufferedImage that presents the Style/Symbols used by |
562 |
* the {@link MapLegend} to show a legend for the {@link FeatureType} |
* the {@link MapLegend} to show a legend for the {@link SimpleFeatureType} |
563 |
* |
* |
564 |
* @param rule |
* @param rule |
565 |
* {@link Rule} that provides the text and the style to present |
* {@link Rule} that provides the text and the style to present |
566 |
* @param featureType |
* @param featureType |
567 |
* Schema that describes the kind of the sample {@link Feature} |
* Schema that describes the kind of the sample {@link SimpleFeature} |
568 |
* that will be rendered with the {@link Style} |
* that will be rendered with the {@link Style} |
569 |
* |
* |
570 |
* @throws IllegalAttributeException |
* @throws IllegalAttributeException |
571 |
*/ |
*/ |
572 |
public BufferedImage createImageForRule(final Rule rule, |
public BufferedImage createImageForRule(final Rule rule, |
573 |
final FeatureType featureType, final Dimension size) { |
final SimpleFeatureType featureType, final Dimension size) { |
574 |
return createImageForRule(rule, featureType, size, null); |
return createImageForRule(rule, featureType, size, null); |
575 |
} |
} |
576 |
|
|