/[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

branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java revision 422 by alfonx, Fri Oct 2 00:47:48 2009 UTC trunk/src/skrueger/geotools/StyledFS.java revision 769 by alfonx, Sun Mar 21 11:02:34 2010 UTC
# Line 30  Line 30 
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.io.File;  import java.io.File;
 import java.io.FileNotFoundException;  
33  import java.io.IOException;  import java.io.IOException;
34  import java.net.URL;  import java.net.URL;
35  import java.util.Date;  import java.util.Date;
# Line 46  import org.geotools.styling.Style; Line 45  import org.geotools.styling.Style;
45  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
46  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
47  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
48    import org.opengis.filter.Filter;
49  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
50    
51    import schmitzm.geotools.io.GeoImportUtil;
52  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
53  import skrueger.AttributeMetaData;  import skrueger.AttributeMetadataImpl;
54  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
55    
56  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 59  import com.vividsolutions.jts.geom.Envel Line 60  import com.vividsolutions.jts.geom.Envel
60   * {@link JPanel} as a {@link MapContextManagerInterface}   * {@link JPanel} as a {@link MapContextManagerInterface}
61   *   *
62   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
63     *
64     * TODO Rename to StyledShapefile
65   */   */
66  public class StyledFS implements StyledFeatureSourceInterface {  public class StyledFS implements StyledFeatureSourceInterface {
67          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
68    
69          private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;          private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
70            
71            /** Caching the CRS of the layer **/
72            CoordinateReferenceSystem crs = null;
73    
74          /**          /**
75           * 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 81  public class StyledFS implements StyledF Line 87  public class StyledFS implements StyledF
87    
88          private AttributeMetadataMap map;          private AttributeMetadataMap map;
89    
90            private Filter filter = Filter.INCLUDE;
91    
92          /**          /**
93           * This class enables a non Atlas context to use the Atlas LayerPanel           * This class enables a non Atlas context to use the Atlas LayerPanel
94           * {@link JPanel} as a {@link MapContextManagerInterface}           * {@link JPanel} as a {@link MapContextManagerInterface}
# Line 92  public class StyledFS implements StyledF Line 100  public class StyledFS implements StyledF
100           *            may be <code>null</code>. Otherwise the SLD {@link File} to           *            may be <code>null</code>. Otherwise the SLD {@link File} to
101           *            import and associate with this {@link StyledFS}           *            import and associate with this {@link StyledFS}
102           */           */
103          public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, File sldFile) {          public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
104                            File sldFile) {
105    
106                  this.fs = fs;                  this.fs = fs;
107    
108                  id = StyledFS.class.getSimpleName()                  id = StyledFS.class.getSimpleName()
109                                  + new Random(new Date().getTime()).nextInt(10000000);                                  + new Random(new Date().getTime()).nextInt(10000000);
110    
111                  this.sldFile = sldFile;                  this.sldFile = sldFile;
112    
113                    // datei existiert, dann lesen
114                  if (sldFile != null && sldFile.exists()) {                  if (sldFile != null && sldFile.exists()) {
115                          try {                          try {
116                                  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");  
117                          } catch (Exception e) {                          } catch (Exception e) {
118                                  LOGGER.warn("Reading SLD failed: " + sldFile, e);                                  LOGGER.warn("Reading SLD failed: " + sldFile, e);
119                                    style = null;
120                          }                          }
121                  }                  }
                 title = new Translation();  
                 title.fromOneLine(sldFile.getName());  
122    
123                    title = new Translation();
124                  desc = new Translation();                  desc = new Translation();
125                  desc.fromOneLine(sldFile.getAbsolutePath());  
126                    if (sldFile != null) {
127                            title.fromOneLine(sldFile.getName());
128                            desc.fromOneLine(sldFile.getAbsolutePath());
129                    }
130    
131            }
132    
133            public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
134                    this(fs, null);
135          }          }
136    
137          public void dispose() {          public void dispose() {
# Line 135  public class StyledFS implements StyledF Line 152  public class StyledFS implements StyledF
152          }          }
153    
154          public CoordinateReferenceSystem getCrs() {          public CoordinateReferenceSystem getCrs() {
155                  return fs.getSchema().getCoordinateReferenceSystem();                  if (crs == null) {
156                            crs = fs.getSchema()
157                                            .getCoordinateReferenceSystem();
158                            if (fs.getSchema().getCoordinateReferenceSystem() == null) {
159                                    LOGGER.warn("Could not determine the CRS of " + getTitle()
160                                                    + ". Using default " + GeoImportUtil.getDefaultCRS());
161                                    crs = GeoImportUtil.getDefaultCRS();
162                            }
163                    }
164                    return crs;
165          }          }
166    
167          public Translation getDesc() {          public Translation getDesc() {
# Line 227  public class StyledFS implements StyledF Line 253  public class StyledFS implements StyledF
253          public AttributeMetadataMap getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
254                  if (map == null) {                  if (map == null) {
255    
256                          map = new AttributeMetadataMap();                          map = new AttributeMetadataImplMap();
257    
258                          // Leaving out the first one, it will be the_geom                          // Leaving out the first one, it will be the_geom
259                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
260                                  AttributeDescriptor att = fs.getSchema().getDescriptor(i);                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
261    
262                                  AttributeMetaData attMetaData = new AttributeMetaData(i, att                                  AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(attDesc
263                                                  .getLocalName());                                                  .getName(), map.getLanguages());
264                                  map.put(i, attMetaData);                                  map.put(attDesc.getName(), attMetaData);
265                          }                          }
266                  }                  }
267                  return map;                  return map;
# Line 243  public class StyledFS implements StyledF Line 269  public class StyledFS implements StyledF
269    
270          /**          /**
271           * @return The {@link File} where the SLD was loaded from or           * @return The {@link File} where the SLD was loaded from or
272           *         <code>null</code> if there didn't exist a {@link File}.           *         <code>null</code> if there didn't exist a {@link File}.
273           *           *
274           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
275           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
# Line 251  public class StyledFS implements StyledF Line 277  public class StyledFS implements StyledF
277          public File getSldFile() {          public File getSldFile() {
278                  return sldFile;                  return sldFile;
279          }          }
280            
281          public void setSldFile(File sldFile) {          public void setSldFile(File sldFile) {
282                  this.sldFile = sldFile;                  this.sldFile = sldFile;
283          }          }
# Line 262  public class StyledFS implements StyledF Line 288  public class StyledFS implements StyledF
288           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
289           */           */
290          @Override          @Override
291          public FeatureCollection getFeatureCollection() {          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
292                  FeatureCollection features;                  FeatureCollection<SimpleFeatureType, SimpleFeature> features;
293                  try {                  try {
294                          features = getGeoObject().getFeatures();                          features = getGeoObject().getFeatures();
295                  } catch (IOException e) {                  } catch (IOException e) {
# Line 280  public class StyledFS implements StyledF Line 306  public class StyledFS implements StyledF
306           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
307           */           */
308          @Override          @Override
309          public FeatureSource getFeatureSource() {          public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
310                  return getGeoObject();                  return getGeoObject();
311          }          }
312    
313            @Override
314            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
315                    // final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
316                    // getFeatureCollection();
317                    // if (filter == Filter.EXCLUDE)
318                    // return new EmptyFeatureCollection(fc.getSchema());
319                    // if (filter == Filter.INCLUDE)
320                    // return fc;
321                    // return fc.subCollection(filter);
322    
323                    try {
324                            return getFeatureSource().getFeatures(filter);
325                    } catch (IOException e) {
326                            throw new RuntimeException(e);
327                    }
328            }
329    
330            @Override
331            public Filter getFilter() {
332                    return filter;
333            }
334    
335            @Override
336            public void setFilter(Filter filter) {
337                    this.filter = filter;
338            }
339    
340            @Override
341            public SimpleFeatureType getSchema() {
342                    return getGeoObject().getSchema();
343            }
344    
345  }  }

Legend:
Removed from v.422  
changed lines
  Added in v.769

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26