|
|
|
svn_geotools
|
Author: mbedward
Date: 2009-11-04 07:17:11 -0500 (Wed, 04 Nov 2009) New Revision: 34322 Modified: branches/2.6.x/demo/example/src/main/java/org/geotools/demo/CRSLab.java branches/2.6.x/demo/example/src/main/java/org/geotools/demo/QueryLab.java branches/2.6.x/demo/example/src/main/java/org/geotools/demo/StyleFunctionLab.java branches/2.6.x/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java Log: Added docs and sphinx markers to StyleFunctionLab Updated CRSLab for new JMapFrame status bar with crs button Fixed licence in ShapefileViewer Modified: branches/2.6.x/demo/example/src/main/java/org/geotools/demo/CRSLab.java =================================================================== --- branches/2.6.x/demo/example/src/main/java/org/geotools/demo/CRSLab.java 2009-11-04 12:12:01 UTC (rev 34321) +++ branches/2.6.x/demo/example/src/main/java/org/geotools/demo/CRSLab.java 2009-11-04 12:17:11 UTC (rev 34322) @@ -18,7 +18,6 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JOptionPane; @@ -41,7 +40,6 @@ import org.geotools.map.DefaultMapContext; import org.geotools.map.MapContext; import org.geotools.referencing.CRS; -import org.geotools.swing.JCRSChooser; import org.geotools.swing.JMapFrame; import org.geotools.swing.ProgressWindow; import org.geotools.swing.action.SafeAction; @@ -106,9 +104,8 @@ mapFrame.enableStatusBar(true); JToolBar toolbar = mapFrame.getToolBar(); - toolbar.add( new JButton( new ChangeCRSAction() ) ); - toolbar.add( new JButton( new ExportShapefileAction() ) ); toolbar.add( new JButton( new ValidateGeometryAction() ) ); + toolbar.add( new JButton( new ExportShapefileAction() ) ); /* * Display the map frame. When it is closed the application @@ -153,27 +150,27 @@ DataStoreFactorySpi factory = new ShapefileDataStoreFactory(); Map<String, Serializable> create = new HashMap<String, Serializable>(); create.put("url", file.toURI().toURL()); - create.put("create spatial index", Boolean.TRUE); + create.put("create spatial index", Boolean.TRUE); DataStore newDataStore = factory.createNewDataStore(create); SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype( schema, worldCRS ); newDataStore.createSchema( featureType ); - + // carefully open an iterator and writer to process the results Transaction transaction = new DefaultTransaction("Reproject"); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriterAppend( featureType.getTypeName(), transaction); - FeatureIterator<SimpleFeature> iterator = featureCollection.features(); + FeatureIterator<SimpleFeature> iterator = featureCollection.features(); try { while( iterator.hasNext() ){ // copy the contents of each feature and transform the geometry SimpleFeature feature = iterator.next(); SimpleFeature copy = writer.next(); copy.setAttributes( feature.getAttributes() ); - + Geometry geometry = (Geometry) feature.getDefaultGeometry(); Geometry geometry2 = JTS.transform(geometry, transform); - - copy.setDefaultGeometry( geometry2 ); + + copy.setDefaultGeometry( geometry2 ); writer.write(); } transaction.commit(); @@ -250,7 +247,7 @@ transaction.close(); } } - + // docs end export2 // docs start validate @@ -265,8 +262,8 @@ final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = featureSource.getFeatures(); - /* - * Rather than use an iterator, we create a FeatureVisitor to + /* + * Rather than use an iterator, we create a FeatureVisitor to * check the Geometry of each feature */ FeatureVisitor visitor = new FeatureVisitor() { @@ -297,34 +294,6 @@ // docs end validate - // docs start crs action - /** - * This class performs the task of changing the CRS of the map display - * when the toolbar button is pressed. It also supplies the name and - * tool tip for the button. - */ - class ChangeCRSAction extends AbstractAction { - - ChangeCRSAction() { - super("Reproject..."); - putValue(Action.SHORT_DESCRIPTION, "Display features with in a new CRS"); - } - - public void actionPerformed(ActionEvent arg0) { - try { - CoordinateReferenceSystem crs = JCRSChooser.showDialog( - null, "Coordinate Reference System", "Choose a new projection:", null); - if (crs != null) { - map.setCoordinateReferenceSystem(crs); - } - } catch (Exception ex) { - System.out.println("Could not use crs " + ex); - } - } - } - - // docs end crs action - // docs start export action /** * This class performs the task of exporting the features to a new shapefile @@ -353,7 +322,7 @@ * supplies the name and tool tip for the toolbar button. */ class ValidateGeometryAction extends SafeAction { - + ValidateGeometryAction() { super("Validate geometry"); putValue(Action.SHORT_DESCRIPTION, "Check the geometry of each feature"); Modified: branches/2.6.x/demo/example/src/main/java/org/geotools/demo/QueryLab.java =================================================================== --- branches/2.6.x/demo/example/src/main/java/org/geotools/demo/QueryLab.java 2009-11-04 12:12:01 UTC (rev 34321) +++ branches/2.6.x/demo/example/src/main/java/org/geotools/demo/QueryLab.java 2009-11-04 12:17:11 UTC (rev 34322) @@ -137,8 +137,8 @@ * To modify this example to work with a PostGIS database instead just replace 'new * ShapefileDataStoreFactory()' in the line below with 'new PostgisDataStoreFactory()' */ - //JDataStoreWizard wizard = new JDataStoreWizard(new ShapefileDataStoreFactory()); - JDataStoreWizard wizard = new JDataStoreWizard(new PostgisDataStoreFactory()); + JDataStoreWizard wizard = new JDataStoreWizard(new ShapefileDataStoreFactory()); + //JDataStoreWizard wizard = new JDataStoreWizard(new PostgisDataStoreFactory()); int result = wizard.showModalDialog(); if (result != JWizard.FINISH) { System.exit(0); Modified: branches/2.6.x/demo/example/src/main/java/org/geotools/demo/StyleFunctionLab.java =================================================================== --- branches/2.6.x/demo/example/src/main/java/org/geotools/demo/StyleFunctionLab.java 2009-11-04 12:12:01 UTC (rev 34321) +++ branches/2.6.x/demo/example/src/main/java/org/geotools/demo/StyleFunctionLab.java 2009-11-04 12:17:11 UTC (rev 34322) @@ -1,3 +1,4 @@ +// docs start source /* * GeoTools - The Open Source Java GIS Tookit * http://geotools.org @@ -59,9 +60,9 @@ } /** - * Display - * @param file - * @throws Exception + * Connect to the shapefile and prompt the user to choose a feature + * attribute to base line and fill colours on. A colour will be + * generated for each unique value of the chosen attribute. */ private void displayShapefile(File file) throws Exception { FileDataStore store = FileDataStoreFinder.getDataStore(file); @@ -71,6 +72,10 @@ MapContext map = new DefaultMapContext(); map.setTitle("Filter Function Lab"); + /* + * Prompt the user for the feature attribute used to + * determine the line and fill colour for each feature + */ FeatureType type = featureSource.getSchema(); PropertyDescriptor geomDesc = type.getGeometryDescriptor(); List<String> attributeNames = new ArrayList<String>(); @@ -86,6 +91,9 @@ JOptionPane.PLAIN_MESSAGE, null, attributeNames.toArray(), null); + /** + * Create the Style and display the shapefile + */ if (selection != null) { Style style = createStyle(featureSource, (String)selection); map.addLayer(featureSource, style); @@ -95,6 +103,9 @@ } } + // docs end display + + // docs start create style /** * Create a rendering style to display features from the given feature source * by matching unique values of the specified feature attribute to colours @@ -102,50 +113,59 @@ * @param featureSource the feature source * @return a new Style instance */ - private Style createStyle(FeatureSource featureSource, String attributeName) + private Style createStyle(FeatureSource featureSource, String attributeName) throws Exception { - FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); - StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); + FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(null); + StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); - UniqueColourFunction colourFn = new UniqueColourFunction( - featureSource.getFeatures(), ff.property(attributeName)); - Fill fill = sf.createFill(colourFn); - Stroke stroke = sf.createStroke(colourFn, ff.literal(1.0f)); + ColorLookupFunction colourFn = new ColorLookupFunction( + featureSource.getFeatures(), filterFactory.property(attributeName)); + Stroke stroke = styleFactory.createStroke( + colourFn, // function to choose feature colour + filterFactory.literal(1.0f), // line width + filterFactory.literal(1.0f)); // opacity + + Fill fill = styleFactory.createFill( + colourFn, // function to choose feature colour + filterFactory.literal(1.0f)); // opacity + Class<?> geomClass = featureSource.getSchema().getGeometryDescriptor().getType().getBinding(); Symbolizer sym = null; if (Polygon.class.isAssignableFrom(geomClass) || MultiPolygon.class.isAssignableFrom(geomClass)) { - sym = sf.createPolygonSymbolizer(stroke, fill, null); + sym = styleFactory.createPolygonSymbolizer(stroke, fill, null); } else if (LineString.class.isAssignableFrom(geomClass) || MultiLineString.class.isAssignableFrom(geomClass)) { - sym = sf.createLineSymbolizer(stroke, null); + sym = styleFactory.createLineSymbolizer(stroke, null); } else { - Graphic gr = sf.createDefaultGraphic(); + Graphic gr = styleFactory.createDefaultGraphic(); gr.graphicalSymbols().clear(); - Mark mark = sf.getCircleMark(); + Mark mark = styleFactory.getCircleMark(); mark.setFill(fill); mark.setStroke(stroke); gr.graphicalSymbols().add(mark); - gr.setSize(ff.literal(10.0f)); - sym = sf.createPointSymbolizer(gr, null); + gr.setSize(filterFactory.literal(10.0f)); + sym = styleFactory.createPointSymbolizer(gr, null); } Style style = SLD.wrapSymbolizers(sym); return style; } + // docs end create style:w + // docs start function /** * A function to dynamically allocate colours to features. It works with a lookup table * where the key is a user-specified feature attribute. Colours are generated using * a simple colour ramp algorithm. */ - static class UniqueColourFunction extends FunctionExpressionImpl { + static class ColorLookupFunction extends FunctionExpressionImpl { private static final float INITIAL_HUE = 0.1f; private final FeatureCollection collection; @@ -169,7 +189,7 @@ * @param colourAttribute a literal expression that specifies the feature attribute * to use for colour lookup */ - public UniqueColourFunction(FeatureCollection collection, Expression colourAttribute) { + public ColorLookupFunction(FeatureCollection collection, Expression colourAttribute) { super("UniqueColour"); this.collection = collection; @@ -236,3 +256,4 @@ } } +// docs end source Modified: branches/2.6.x/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java =================================================================== --- branches/2.6.x/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java 2009-11-04 12:12:01 UTC (rev 34321) +++ branches/2.6.x/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java 2009-11-04 12:17:11 UTC (rev 34322) @@ -1,18 +1,11 @@ /* - * GeoTools - The Open Source Java GIS Toolkit + * GeoTools - The Open Source Java GIS Tookit * http://geotools.org * - * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) + * (C) 2006-2008, Open Source Geospatial Foundation (OSGeo) * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * This file is hereby placed into the Public Domain. This means anyone is + * free to do whatever they wish with this file. Use it well and enjoy! */ package org.geotools.demo.swing; @@ -94,7 +87,7 @@ enableToolBar(true); initComponents(); - + JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); @@ -186,7 +179,7 @@ throw new IllegalArgumentException("shapefileURL must not me null"); } ShapefileDataStore dstore = null; - + DataStore found = repository.dataStore( shapefileURL.toString()); if( found != null && found instanceof ShapefileDataStore){ dstore = (ShapefileDataStore) found; @@ -200,7 +193,7 @@ repository.register( shapefileURL.toString(), dstore ); } /* - * Before doing anything else we attempt to connect to the + * Before doing anything else we attempt to connect to the * shapefile to check that it exists and is reachable. An * IOException will be thrown if this fails. */ @@ -263,7 +256,7 @@ throw new IllegalArgumentException("shapefileURL must not be null"); } ShapefileDataStore dstore = null; - + DataStore found = repository.dataStore( shapefileURL.toString()); if( found != null && found instanceof ShapefileDataStore){ dstore = (ShapefileDataStore) found; @@ -275,7 +268,7 @@ throw new RuntimeException(urlEx); } repository.register( shapefileURL.toString(), dstore ); - } + } /* * Before doing anything else we attempt to connect to the * shapefile to check that it exists and is reachable. An @@ -305,9 +298,9 @@ */ public URL getShapefileSLD(URL shapefileURL) { URL sldURL = null; - + File shapefile; - try { + try { shapefile = new File( shapefileURL.toURI() ); } catch (URISyntaxException e) { shapefile = new File( shapefileURL.getPath() ); @@ -324,10 +317,10 @@ File sldFile1 = new File( directory, sldname1 ); File sldFile2 = new File( directory, sldname2 ); if( sldFile1.exists() && sldFile1.canRead() ){ - sldURL = sldFile1.toURL(); + sldURL = sldFile1.toURL(); } else if( sldFile1.exists() && sldFile1.canRead() ){ - sldURL = sldFile2.toURL(); + sldURL = sldFile2.toURL(); } else { /* ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ GeoTools-commits mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-commits |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |