001 //$HeadURL: http://svn.wald.intevation.org/svn/deegree/base/trunk/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: 29966 $, $Date: 2011-03-09 15:19:04 +0100 (Wed, 09 Mar 2011) $ 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 163 public void addAllUncontained( Feature[] feature ) { 164 for ( int i = 0; i < feature.length; i++ ) { 165 Feature f = feature[i]; 166 Feature f2 = getFeature( f.getId() ); 167 if ( f2 == null || !f2.getId().equals( f.getId() ) ) { 168 add( feature[i] ); 169 } 170 } 171 } 172 173 174 175 public void addAllUncontained( FeatureCollection fc ) { 176 int size = fc.size(); 177 for ( int i = 0; i < size; i++ ) { 178 Feature f = fc.getFeature( i ); 179 Feature f2 = getFeature( f.getId() ); 180 if ( f2 == null || !f2.getId().equals( f.getId() ) ) { 181 add( f ); 182 } 183 } 184 } 185 186 /** 187 * removes a feature identified by its ID from the feature collection. If no feature with the passed ID is available 188 * nothing happens and <tt>null</tt> will be returned 189 * 190 * @param id 191 * @return the removed feature 192 */ 193 public Feature remove( String id ) { 194 Feature feat = getFeature( id ); 195 return remove( feat ); 196 } 197 198 }