001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/framework/util/FeatureUtils.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2010 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.framework.util;
037
038 import org.deegree.framework.log.ILogger;
039 import org.deegree.framework.log.LoggerFactory;
040 import org.deegree.model.feature.Feature;
041 import org.deegree.model.feature.FeatureCollection;
042 import org.deegree.model.feature.FeatureFactory;
043 import org.deegree.model.spatialschema.Curve;
044 import org.deegree.model.spatialschema.Geometry;
045 import org.deegree.model.spatialschema.MultiCurve;
046 import org.deegree.model.spatialschema.MultiPoint;
047 import org.deegree.model.spatialschema.MultiSurface;
048 import org.deegree.model.spatialschema.Point;
049 import org.deegree.model.spatialschema.Surface;
050
051 /**
052 * The <code>FeatureUtils</code> class offeres several static methods for handling features.
053 *
054 * TODO add class documentation here.
055 *
056 * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a>
057 * @author last edited by: $Author: jmays $
058 *
059 * @version $Revision: 22732 $, $Date: 2010-02-24 15:38:35 +0100 (Mi, 24. Feb 2010) $
060 */
061 public class FeatureUtils {
062
063 private static final ILogger LOG = LoggerFactory.getLogger( FeatureUtils.class );
064
065 /**
066 * This method separates the features in the given FeatureCollection according to their geometry type into Points,
067 * MulitPoints, (Multi-)Curves, (Multi-)Surfaces. features with geometries that do not match these geometry types
068 * are collected in a five group (others).
069 *
070 * The separation according to geometryType is needed to prepare the feature collections for creating shape files.
071 *
072 * @param fc
073 * @return an array of five feature collections, containing the features of the original fc separated according to
074 * their geometry type. The first entry contains Points, the second contains MultiPoints, the third contains
075 * Curves and MultiCurves, the fourth contains Surfaces and MultiSurfaces. If the original fc contains
076 * features with MultiGeoemetries, these features are added to the fourth fc.
077 */
078 public static FeatureCollection[] separateFeaturesForShapes( FeatureCollection fc ) {
079
080 FeatureCollection fcPoint = FeatureFactory.createFeatureCollection( fc.getId() + "_Points", null );
081 FeatureCollection fcMultiPoint = FeatureFactory.createFeatureCollection( fc.getId() + "_MultiPoints", null );
082 FeatureCollection fcCurve = FeatureFactory.createFeatureCollection( fc.getId() + "_Curves", null );
083 FeatureCollection fcSurface = FeatureFactory.createFeatureCollection( fc.getId() + "_Surfaces", null );
084 FeatureCollection fcOther = FeatureFactory.createFeatureCollection( fc.getId() + "_Other", null );
085
086 for ( int i = 0; i < fc.size(); i++ ) {
087 Feature f = fc.getFeature( i );
088 Geometry geom = f.getDefaultGeometryPropertyValue();
089
090 if ( geom instanceof Point ) {
091 fcPoint.add( f );
092 LOG.logDebug( "Feature contains a POINT" );
093 } else if ( geom instanceof MultiPoint ) {
094 fcMultiPoint.add( f );
095 LOG.logDebug( "Feature contains a MULTIPOINT" );
096 } else if ( geom instanceof Curve || geom instanceof MultiCurve ) {
097 fcCurve.add( f );
098 LOG.logDebug( "Feature contains a LINESTRING" );
099 } else if ( geom instanceof Surface || geom instanceof MultiSurface ) {
100 fcSurface.add( f );
101 LOG.logDebug( "Feature contains a POLYGON" );
102 } else {
103 LOG.logDebug(
104 "Feature geometry is neither POINT, MULTIPOINT, CURVE, MULTICURVE, SURFACE, MULTISURFACE. ",
105 f.getName(), " contains a geometry of type: " + geom.getClass() );
106 fcOther.add( f );
107 }
108 }
109 return new FeatureCollection[] { fcPoint, fcMultiPoint, fcCurve, fcSurface, fcOther };
110 }
111
112 }