001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/model/feature/AbstractFeatureCollection.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.model.feature;
037
038 import org.deegree.datatypes.QualifiedName;
039 import org.deegree.datatypes.Types;
040 import org.deegree.datatypes.UnknownTypeException;
041 import org.deegree.framework.log.ILogger;
042 import org.deegree.framework.log.LoggerFactory;
043 import org.deegree.model.feature.schema.PropertyType;
044 import org.deegree.model.spatialschema.Geometry;
045 import org.deegree.model.spatialschema.GeometryFactory;
046 import org.deegree.ogcbase.CommonNamespaces;
047
048 /**
049 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
050 * @author last edited by: $Author: apoth $
051 *
052 * @version $Revision: 19466 $, $Date: 2009-09-01 17:38:59 +0200 (Di, 01. Sep 2009) $
053 */
054 public abstract class AbstractFeatureCollection extends AbstractFeature implements FeatureCollection {
055
056 private static final ILogger LOG = LoggerFactory.getLogger( AbstractFeatureCollection.class );
057
058 /**
059 * @param id
060 */
061 public AbstractFeatureCollection( String id ) {
062 this( id, null );
063 }
064
065 /**
066 * @param id
067 * @param name
068 * of the feature collection if <code>null</code> it will be set to wfs:FeatureCollection
069 */
070 public AbstractFeatureCollection( String id, QualifiedName name ) {
071 super( id, null );
072
073 PropertyType[] ftp = new PropertyType[1];
074 if ( name == null ) {
075 name = new QualifiedName( CommonNamespaces.WFS_PREFIX, "FeatureCollection", CommonNamespaces.WFSNS );
076 }
077 try {
078 ftp[0] = FeatureFactory.createPropertyType( new QualifiedName( "features" ),
079 Types.FEATURE_ARRAY_PROPERTY_NAME, true );
080 } catch ( UnknownTypeException e ) {
081 LOG.logError( "Unreachable point reached.", e );
082 }
083 this.featureType = FeatureFactory.createFeatureType( name, false, ftp );
084
085 }
086
087 /**
088 * returns a Point with position 0/0 and no CRS
089 *
090 * @return a geometry
091 */
092 public Geometry getDefaultGeometryPropertyValue() {
093 return GeometryFactory.createPoint( 0, 0, null );
094 }
095
096 /**
097 * returns the value of a feature collection geometry properties
098 *
099 * @return array of all geometry property values
100 */
101 public Geometry[] getGeometryPropertyValues() {
102 return new Geometry[0];
103 }
104
105 /**
106 * returns all properties of a feature collection
107 *
108 * @return all properties of a feature
109 */
110 public FeatureProperty[] getProperties() {
111 return new FeatureProperty[0];
112 }
113
114 /**
115 * returns the properties of a feature collection at the passed index position
116 *
117 * @param index
118 * @return properties at the passed index position
119 */
120 public FeatureProperty[] getProperties( int index ) {
121 // TODO
122 // a FeatureCollection may also have properties?
123 return null;
124 }
125
126 /**
127 * returns the default property of a feature collection with the passed name
128 *
129 * @param name
130 * @return named default property
131 */
132 public FeatureProperty getDefaultProperty( QualifiedName name ) {
133 // TODO
134 // a FeatureCollection may also have properties?
135 return null;
136 }
137
138 /**
139 * returns the named properties of a feature collection
140 *
141 * @param name
142 * @return named properties
143 */
144 public FeatureProperty[] getProperties( QualifiedName name ) {
145 // TODO
146 // a FeatureCollection may also have properties?
147 return null;
148 }
149
150 /**
151 * sets a property of a feature collection.<br>
152 * !!! this method is not implemented yet !!!
153 *
154 * @param property
155 */
156 public void setProperty( FeatureProperty property ) {
157 // TODO
158 // a FeatureCollection may also have properties?
159 }
160
161 /**
162 * @see org.deegree.model.feature.FeatureCollection#addAll(org.deegree.model.feature.Feature[])
163 */
164 @Deprecated
165 public void addAll( Feature[] feature ) {
166 for ( int i = 0; i < feature.length; i++ ) {
167 add( feature[i] );
168 }
169 }
170
171 public void addAllUncontained( Feature[] feature ) {
172 for ( int i = 0; i < feature.length; i++ ) {
173 if ( feature[i] != getFeature( feature[i].getId() ) ) {
174 add( feature[i] );
175 }
176 }
177 }
178
179 /**
180 * @see org.deegree.model.feature.FeatureCollection#addAll(org.deegree.model.feature.FeatureCollection)
181 */
182 @Deprecated
183 public void addAll( FeatureCollection fc ) {
184 int size = fc.size();
185 for ( int i = 0; i < size; i++ ) {
186 add( fc.getFeature( i ) );
187 }
188 }
189
190 public void addAllUncontained( FeatureCollection fc ) {
191 int size = fc.size();
192 for ( int i = 0; i < size; i++ ) {
193 Feature f = fc.getFeature( i );
194 Feature f2 = getFeature( f.getId() );
195 if ( f2 == null || !f2.getId().equals( f.getId() ) ) {
196 add( f );
197 }
198 }
199 }
200
201 /**
202 * removes a feature identified by its ID from the feature collection. If no feature with the passed ID is available
203 * nothing happens and <tt>null</tt> will be returned
204 *
205 * @param id
206 * @return the removed feature
207 */
208 public Feature remove( String id ) {
209 Feature feat = getFeature( id );
210 return remove( feat );
211 }
212
213 }