/[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 862 by alfonx, Sat May 22 01:24:46 2010 UTC revision 863 by alfonx, Sun May 23 13:42:13 2010 UTC
# Line 30  Line 30 
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.io.File;  import java.io.File;
33    import java.io.FileNotFoundException;
34  import java.io.IOException;  import java.io.IOException;
35  import java.net.URL;  import java.net.URL;
36  import java.util.Date;  import java.util.Date;
# Line 52  import org.opengis.referencing.crs.Coord Line 53  import org.opengis.referencing.crs.Coord
53  import schmitzm.geotools.io.GeoImportUtil;  import schmitzm.geotools.io.GeoImportUtil;
54  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
55  import skrueger.AttributeMetadataImpl;  import skrueger.AttributeMetadataImpl;
56    import skrueger.AttributeMetadataInterface;
57  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
58    
59  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 62  import com.vividsolutions.jts.geom.Envel Line 64  import com.vividsolutions.jts.geom.Envel
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   *         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 **/          /** Caching the CRS of the layer **/
75          CoordinateReferenceSystem crs = null;          CoordinateReferenceSystem crs = null;
76    
# Line 86  public class StyledFS implements StyledF Line 88  public class StyledFS implements StyledF
88    
89          private File sldFile;          private File sldFile;
90    
91          private AttributeMetadataMap map;          /** A map of simple attribute names to their meta-data **/
92            private AttributeMetadataMap<AttributeMetadataImpl> map;
93    
94          private Filter filter = Filter.INCLUDE;          private Filter filter = Filter.INCLUDE;
95    
# Line 154  public class StyledFS implements StyledF Line 157  public class StyledFS implements StyledF
157    
158          public CoordinateReferenceSystem getCrs() {          public CoordinateReferenceSystem getCrs() {
159                  if (crs == null) {                  if (crs == null) {
160                          crs = fs.getSchema()                          crs = fs.getSchema().getCoordinateReferenceSystem();
                                         .getCoordinateReferenceSystem();  
161                          if (fs.getSchema().getCoordinateReferenceSystem() == null) {                          if (fs.getSchema().getCoordinateReferenceSystem() == null) {
162                                  LOGGER.warn("Could not determine the CRS of " + getTitle()                                  LOGGER.warn("Could not determine the CRS of " + getTitle()
163                                                  + ". Using default " + GeoImportUtil.getDefaultCRS());                                                  + ". Using default " + GeoImportUtil.getDefaultCRS());
# Line 251  public class StyledFS implements StyledF Line 253  public class StyledFS implements StyledF
253          /**          /**
254           *           *
255           */           */
256          public AttributeMetadataMap getAttributeMetaDataMap() {          public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() {
257                  if (map == null) {                  if (map == null) {
258    
259                          map = new AttributeMetadataImplMap();                          map = new AttributeMetadataImplMap();
260    
261  //                      // Leaving out the first one, it will be the_geom                          // // Leaving out the first one, it will be the_geom
262  //                      for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          // for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
263  //                              AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);                          // AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
264  //                          //
265  //                              AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( new NameImpl(attDesc                          // AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
266  //                                              .getName().getNamespaceURI(), attDesc                          // new NameImpl(attDesc
267  //                                              .getName().getLocalPart()), map.getLanguages());                          // .getName().getNamespaceURI(), attDesc
268  //                              map.put(attDesc.getName(), attMetaData);                          // .getName().getLocalPart()), map.getLanguages());
269  //                      }                          // map.put(attDesc.getName(), attMetaData);
270                                                    // }
271    
272                          // Leaving out the first one, it will be the_geom                          // Leaving out the first one, it will be the_geom
273                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
274                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
275    
276                                  // TODO AttributeMetadataAS would be nicer, which would not work with Translations ;-)                                  // TODO AttributeMetadataAS would be nicer, which would not work
277                                  AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( new NameImpl(attDesc                                  // with Translations ;-)
278                                                  .getName().getNamespaceURI(), attDesc                                  AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
279                                                  .getName().getLocalPart()), map.getLanguages());                                                  new NameImpl(attDesc.getName().getNamespaceURI(),
280                                  if (String.class.isAssignableFrom( attDesc.getType().getBinding() )){                                                                  attDesc.getName().getLocalPart()), map
281                                                                    .getLanguages());
282                                    if (String.class.isAssignableFrom(attDesc.getType()
283                                                    .getBinding())) {
284                                          // For Strings we add the "" as NODATA values                                          // For Strings we add the "" as NODATA values
285                                          attMetaData.addNodataValue("");                                          attMetaData.addNodataValue("");
286                                  }                                  }
# Line 294  public class StyledFS implements StyledF Line 300  public class StyledFS implements StyledF
300          public File getSldFile() {          public File getSldFile() {
301                  return sldFile;                  return sldFile;
302          }          }
303            
304          public void setSldFile(File sldFile) {          public void setSldFile(File sldFile) {
305                  this.sldFile = sldFile;                  this.sldFile = sldFile;
306          }          }
# Line 359  public class StyledFS implements StyledF Line 365  public class StyledFS implements StyledF
365                  return getGeoObject().getSchema();                  return getGeoObject().getSchema();
366          }          }
367    
368            /**
369             * Tries to load a style from the file denoted in {@link #getSldFile()}. If
370             * the file doesn't exits, return <code>null</code>;
371             * @return <code>true</code> is style was loaded
372             */
373            public boolean loadStyle() {
374                    if (getSldFile() == null)
375                            return false;
376                    
377                    try {
378                            Style[] loadSLD = StylingUtil.loadSLD(getSldFile());
379                            setStyle(loadSLD[0]);
380                            return true;
381                    } catch (Exception e) {
382                            return false;
383                    }
384    
385            }
386    
387  }  }

Legend:
Removed from v.862  
changed lines
  Added in v.863

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26