/[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 769 by alfonx, Sun Mar 21 11:02:34 2010 UTC revision 863 by alfonx, Sun May 23 13:42:13 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
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 41  import javax.swing.JPanel; Line 42  import javax.swing.JPanel;
42  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
43  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
44  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
45    import org.geotools.feature.NameImpl;
46  import org.geotools.styling.Style;  import org.geotools.styling.Style;
47  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
48  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
# Line 51  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 61  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 85  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 153  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 250  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
262                            // for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
263                            // AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
264                            //
265                            // AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
266                            // new NameImpl(attDesc
267                            // .getName().getNamespaceURI(), attDesc
268                            // .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                                  AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(attDesc                                  // TODO AttributeMetadataAS would be nicer, which would not work
277                                                  .getName(), map.getLanguages());                                  // with Translations ;-)
278                                    AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
279                                                    new NameImpl(attDesc.getName().getNamespaceURI(),
280                                                                    attDesc.getName().getLocalPart()), map
281                                                                    .getLanguages());
282                                    if (String.class.isAssignableFrom(attDesc.getType()
283                                                    .getBinding())) {
284                                            // For Strings we add the "" as NODATA values
285                                            attMetaData.addNodataValue("");
286                                    }
287                                  map.put(attDesc.getName(), attMetaData);                                  map.put(attDesc.getName(), attMetaData);
288                          }                          }
289                  }                  }
# Line 277  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 342  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.769  
changed lines
  Added in v.863

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26