/[schmitzm]/trunk/src/skrueger/geotools/StyledFS.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledFS.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 607 by alfonx, Wed Dec 9 15:13:42 2009 UTC revision 620 by alfonx, Mon Jan 25 17:46:06 2010 UTC
# Line 38  import java.util.Random; Line 38  import java.util.Random;
38    
39  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
40  import javax.swing.JPanel;  import javax.swing.JPanel;
41    import javax.xml.transform.TransformerException;
42    
43  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
44  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
45  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
46  import org.geotools.styling.Style;  import org.geotools.styling.Style;
47    import org.jfree.util.AttributedStringUtilities;
48  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
49  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
50  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
# Line 61  import com.vividsolutions.jts.geom.Envel Line 63  import com.vividsolutions.jts.geom.Envel
63   * {@link JPanel} as a {@link MapContextManagerInterface}   * {@link JPanel} as a {@link MapContextManagerInterface}
64   *   *
65   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
66     *
67     * TODO Rename to StyledShapefile
68   */   */
69  public class StyledFS implements StyledFeatureSourceInterface {  public class StyledFS implements StyledFeatureSourceInterface {
70          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
71    
72          private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;          private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
73            
74            /** Caching the CRS of the layer **/
75            CoordinateReferenceSystem crs = null;
76    
77          /**          /**
78           * A unique ID which identifies the Layer in the Atlas. It's more important           * A unique ID which identifies the Layer in the Atlas. It's more important
# Line 100  public class StyledFS implements StyledF Line 107  public class StyledFS implements StyledF
107                          File sldFile) {                          File sldFile) {
108    
109                  this.fs = fs;                  this.fs = fs;
110    
111                  id = StyledFS.class.getSimpleName()                  id = StyledFS.class.getSimpleName()
112                                  + new Random(new Date().getTime()).nextInt(10000000);                                  + new Random(new Date().getTime()).nextInt(10000000);
113    
114                  this.sldFile = sldFile;                  this.sldFile = sldFile;
115    
116                    // datei existiert, dann lesen
117                  if (sldFile != null && sldFile.exists()) {                  if (sldFile != null && sldFile.exists()) {
118                          try {                          try {
119                                  style = StylingUtil.loadSLD(sldFile)[0];                                  style = StylingUtil.loadSLD(sldFile)[0];
                         } catch (FileNotFoundException e) {  
                                 LOGGER  
                                                 .debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null");  
120                          } catch (Exception e) {                          } catch (Exception e) {
121                                  LOGGER.warn("Reading SLD failed: " + sldFile, e);                                  LOGGER.warn("Reading SLD failed: " + sldFile, e);
122                                    style = null;
123                          }                          }
124                  }                  }
125    
126                  title = new Translation();                  title = new Translation();
127                  desc = new Translation();                  desc = new Translation();
128    
# Line 147  public class StyledFS implements StyledF Line 155  public class StyledFS implements StyledF
155          }          }
156    
157          public CoordinateReferenceSystem getCrs() {          public CoordinateReferenceSystem getCrs() {
158                  CoordinateReferenceSystem crs = fs.getSchema().getCoordinateReferenceSystem();                  if (crs == null) {
159                  if (fs.getSchema().getCoordinateReferenceSystem() == null) {                          crs = fs.getSchema()
160                          LOGGER.warn("Could not determine the CRS of "+getTitle()+". Using default "+GeoImportUtil.getDefaultCRS());                                          .getCoordinateReferenceSystem();
161                          crs = GeoImportUtil.getDefaultCRS();                          if (fs.getSchema().getCoordinateReferenceSystem() == null) {
162                                    LOGGER.warn("Could not determine the CRS of " + getTitle()
163                                                    + ". Using default " + GeoImportUtil.getDefaultCRS());
164                                    crs = GeoImportUtil.getDefaultCRS();
165                            }
166                  }                  }
167                  return crs;                  return crs;
168          }          }
# Line 244  public class StyledFS implements StyledF Line 256  public class StyledFS implements StyledF
256          public AttributeMetadataMap getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
257                  if (map == null) {                  if (map == null) {
258    
259                          map = new AttributeMetadataMap(new String[] {Translation.getActiveLang()});                          map = new AttributeMetadataMap(new String[] { Translation
260                                            .getActiveLang() });
261    
262                          // Leaving out the first one, it will be the_geom                          // Leaving out the first one, it will be the_geom
263                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
264                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
265    
266                                  AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName(), map.getLanguages());                                  AttributeMetadata attMetaData = new AttributeMetadata(attDesc
267                                                    .getName(), map.getLanguages());
268                                  map.put(attDesc.getName(), attMetaData);                                  map.put(attDesc.getName(), attMetaData);
269                          }                          }
270                  }                  }
# Line 267  public class StyledFS implements StyledF Line 281  public class StyledFS implements StyledF
281          public File getSldFile() {          public File getSldFile() {
282                  return sldFile;                  return sldFile;
283          }          }
284            
285          public void setSldFile(File sldFile) {          public void setSldFile(File sldFile) {
286                  this.sldFile = sldFile;                  this.sldFile = sldFile;
287          }          }
# Line 302  public class StyledFS implements StyledF Line 316  public class StyledFS implements StyledF
316    
317          @Override          @Override
318          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
319  //              final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();                  // final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
320  //              if (filter == Filter.EXCLUDE)                  // getFeatureCollection();
321  //                      return new EmptyFeatureCollection(fc.getSchema());                  // if (filter == Filter.EXCLUDE)
322  //              if (filter == Filter.INCLUDE)                  // return new EmptyFeatureCollection(fc.getSchema());
323  //                      return fc;                  // if (filter == Filter.INCLUDE)
324  //              return fc.subCollection(filter);                  // return fc;
325                                    // return fc.subCollection(filter);
326    
327                  try {                  try {
328                          return getFeatureSource().getFeatures(filter);                          return getFeatureSource().getFeatures(filter);
329                  } catch (IOException e) {                  } catch (IOException e) {

Legend:
Removed from v.607  
changed lines
  Added in v.620

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26