source: osm/applications/editors/josm/plugins/opendata/includes/org/geotools/feature/FeatureCollection.java@ 28000

Last change on this file since 28000 was 28000, checked in by donvip, 12 years ago

Import new "opendata" JOSM plugin

File size: 14.3 KB
Line 
1/*
2 * GeoTools - The Open Source Java GIS Toolkit
3 * http://geotools.org
4 *
5 * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation;
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 */
17package org.geotools.feature;
18
19import java.io.IOException;
20import java.util.Collection;
21import java.util.Iterator;
22
23import org.geotools.geometry.jts.ReferencedEnvelope;
24import org.opengis.feature.Feature;
25import org.opengis.feature.FeatureVisitor;
26import org.opengis.feature.type.FeatureType;
27import org.opengis.filter.Filter;
28import org.opengis.util.ProgressListener;
29
30
31/**
32 * Represents a collection of features.
33 * <p>
34 * Implementations (and client code) should adhere to the rules set forth
35 * by java.util.Collection. That is, some methods are
36 * optional to implement, and may throw an UnsupportedOperationException.
37 * </p>
38 * <p>
39 * SimpleFeatureCollection house rules:
40 * <ul>
41 * <li>FeatureCollection.close( iterator ) must be called (see example below)
42 * <li>Features are not specifically ordered within the SimpleFeatureCollection (see FeatureList)
43 * <li>Two instances cannot exist with the same Feature ID (Feature contract)
44 * <li>(unsure) the same Instance can be in the collection more then once
45 * </ul>
46 * In programmer speak a SimpleFeatureCollection is a "Bag" with an index based ID.
47 * </p>
48 * <p>
49 * <h3>Life Cycle of Iterator</h3>
50 * <p>
51 * We have also adopted an additional constraint on the use of iterator.
52 * You must call FeatureCollection.close( iterator ) to allow FeatureCollection
53 * to clean up any operating system resources used to acces information.
54 * </p>
55 * <p>
56 * Example (safe) use:<pre><code>
57 * Iterator iterator = collection.iterator();
58 * try {
59 * for( Iterator i=collection.iterator(); i.hasNext();){
60 * Feature feature = (Feature) i.hasNext();
61 * System.out.println( feature.getID() );
62 * }
63 * }
64 * finally {
65 * collection.close( iterator );
66 * }
67 * </code></pre>
68 * </p>
69 * <p>
70 * Handy Tip: Although many resource backed collections will choose
71 * to release resources at when the iterator has reached the end of its contents
72 * this is not something you should rely on.
73 * </p>
74 * <h2>Notes for SimpleFeatureCollection Implementors</h2>
75 * <p>
76 * Many users will be treating this as a straight forward Collection,
77 * there code will break often enough due to latency - try and close
78 * up resources for them when you can detect that an Iterator is not
79 * useful anymore.
80 * </p>
81 * <p>
82 * Collections are used in two fashions, basically as you see them,
83 * and also as "range" for common opperations. You can see this with
84 * List.subCollection( Filter ). Existing RnD effort is
85 * going towards supporting this kind of use at the FeatureCollection
86 * level.
87 * </p>
88 *
89 * @see java.util.Collection, org.geotools.Feature
90 * @author Ian Turton, CCG
91 * @author Rob Hranac, VFNY
92 * @author Ian Schneider, USDA-ARS
93 * @author Jody Garnett, Refractions Research, Inc.
94 *
95 * @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/modules/library/api/src/main/java/org/geotools/feature/FeatureCollection.java $
96 * @version $Id: FeatureCollection.java 37280 2011-05-24 07:53:02Z mbedward $
97 *
98 */
99public interface FeatureCollection<T extends FeatureType, F extends Feature> {
100 /**
101 * Obtain a FeatureIterator<SimpleFeature> of the Features within this collection.
102 * <p>
103 * The implementation of Collection must adhere to the rules of
104 * fail-fast concurrent modification. In addition (to allow for
105 * resource backed collections, the <code>close( Iterator )</code>
106 * method must be called.
107 * <p>
108 *
109 * This is almost equivalent to:
110 * <ul>
111 * <li>a Type-Safe call to:
112 * <code>getAttribute(getFeatureType().getAttributeType(0).getName()).iterator();</code>.
113 * <li>A Java 5:<code>Iterator&lt;Feature&gt;</code>
114 * </ul>
115 * </p>
116 * Example (safe) use:<pre><code>
117 * FeatureIterator<SimpleFeature> iterator=collection.features();
118 * try {
119 * while( iterator.hasNext() ){
120 * Feature feature = iterator.next();
121 * System.out.println( feature.getID() );
122 * }
123 * }
124 * finally {
125 * collection.close( iterator );
126 * }
127 * </code></pre>
128 * </p>
129 *
130 * <p>
131 * GML Note: The contents of this iterator are considered to be defined by
132 * <b>featureMember</b> tags (and/or the single allowed <b>FeatureMembers</b> tag).
133 * Please see getFeatureType for more details.
134 * </p>
135 *
136 * @return A FeatureIterator.
137 */
138 FeatureIterator<F> features();
139
140 /**
141 * Clean up after any resources associated with this FeatureIterator in a manner similar to JDO collections.
142 * </p>
143 * Example (safe) use:<pre><code>
144 * Iterator iterator = collection.iterator();
145 * try {
146 * for( Iterator i=collection.iterator(); i.hasNext();){
147 * Feature feature = i.hasNext();
148 * System.out.println( feature.getID() );
149 * }
150 * }
151 * finally {
152 * collection.close( iterator );
153 * }
154 * </code></pre>
155 * </p>
156 * @param close
157 * @deprecated Please FeatureIterator.close()
158 */
159 public void close(FeatureIterator<F> close);
160
161 /**
162 * Clean up after any resources associated with this itterator in a manner similar to JDO collections.
163 * </p>
164 * Example (safe) use:<pre><code>
165 * Iterator iterator = collection.iterator();
166 * try {
167 * for( Iterator i=collection.iterator(); i.hasNext();){
168 * Feature feature = (Feature) i.hasNext();
169 * System.out.println( feature.getID() );
170 * }
171 * }
172 * finally {
173 * collection.close( iterator );
174 * }
175 * </code></pre>
176 * </p>
177 * @deprecated Please use features() to obtain a FeatureIterator
178 */
179 public void close(Iterator<F> close);
180
181 /**
182 * Gets a reference to the type of this feature collection.
183 * <p>
184 * There are several limitations on the use of FeatureType with respect to a FeatureCollection.
185 * </p>
186 * <p>
187 * GML 3.x: all FeatureCollections decend from gml:AbstractFeatureCollectionType:
188 * <ul>
189 * <li>featureMember 0..* allows _Feature or xlink:ref
190 * <li>featureMembers 0..1 contents treated as _Feature
191 * </ul>
192 * The contents defined in this manner is returned the collection
193 * iterator() method.
194 * </p>
195 * <p>
196 * GML 3.x: gml:AbstractFeatureCollectionType decends from gml:BoundedFeatureType:
197 * <ul>
198 * <li>metaDataProperty 0..*
199 * <li>description 0..1
200 * <li>name 0..*
201 * <li>boundedBy 1..1 (required)
202 * <li>location 0..1
203 * </ul>
204 * The value of the boundedBy attribute should be derived from the contents
205 * of the collection.
206 * </p>
207 * <h3>Implementation Notes</h3>
208 * <p>
209 * There is a difference between getFeatureType() and getSchema(), getSchema is named
210 * for historical reasons and reprensets the LCD FeatureType that best represents the
211 * contents of this collection.
212 * <ul>
213 * <li>The degenerate case returns the "_Feature" FeatureType, where the
214 * onlything known is that the contents are Features.
215 * <li>For a collection backed by a shapefiles (or database tables) the
216 * FeatureType returned by getSchema() will complete describe each and every child in the collection.
217 * <li>For mixed content FeatureCollections you will need to check the FeatureType
218 * of each Feature as it is retrived from the collection
219 * </ul>
220 * </p>
221 *
222 * @return A reference to this collections type
223 */
224
225 //FeatureType getFeatureType();
226
227 /**
228 * The schema for the child features of this collection.
229 * <p>
230 * There is a difference between getFeatureType() and getSchema()represents the LCD
231 * FeatureType that best represents the contents of this collection.
232 * <ul>
233 * <li>The degenerate case returns the "_Feature" FeatureType, where the
234 * onlything known is that the contents are Features.
235 * <li>For a collection backed by a shapefiles (or database tables) the FeatureType returned by getSchema() will
236 * complete describe each and every child in the collection.
237 * <li>For mixed content FeatureCollections you will need to check the FeatureType of each Feature as it
238 * is retrived from the collection
239 * </ul>
240 * </p>
241 * <p>
242 * The method getSchema() is named for compatability with the geotools 2.0 API. In the
243 * Geotools 2.2 time frame we should be able to replace this method with a careful check
244 * of getFeatureType() and its attributes.
245 * </p>
246 * @return FeatureType describing the "common" schema to all child features of this collection
247 */
248 T getSchema();
249
250 /** ID used when serializing to GML */
251 String getID();
252
253 /**
254 * Visit the contents of a feature collection.
255 * <p>
256 * The order of traversal is dependent on the FeatureCollection implementation; some
257 * collections are able to make efficient use of an internal index in order to quickly
258 * visit features located in the same region.
259 * </p>
260 *
261 * @param visitor Closure applied to each feature in turn.
262 * @param progress Used to report progress, may be used to interrupt the operation
263 *
264 * @since 2.5
265 */
266 void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException;
267
268 /**
269 * SimpleFeatureCollection "view" indicated by provided filter.
270 * <p>
271 * The contents of the returned SimpleFeatureCollection are determined by
272 * applying the provider Filter to the entire contents of this
273 * FeatureCollection. The result is "live" and modifications will
274 * be shared.
275 * <p>
276 * This method is used cut down on the number of filter based methods
277 * required for a useful SimpleFeatureCollection construct. The FeatureCollections
278 * returned really should be considered as a temporary "view" used to
279 * control the range of a removeAll, or modify operation.
280 * <p>
281 * Example Use:
282 * <pre><code>
283 * collection.subCollection( filter ).clear();
284 * </code></pre>
285 * The above recommended use is agreement with the Collections API precident of
286 * List.subList( start, end ).
287 * <p>
288 * The results of subCollection:
289 * <ul>
290 * <li>are to be considered unordered
291 * <li>may be an ordered FeatureList if requested when sortBy is indicated
292 * </ul>
293 * </p>
294 * @see FeatureList
295 * @param filter
296 * @return SimpleFeatureCollection identified as subset.
297 */
298 public FeatureCollection<T, F> subCollection(Filter filter);
299
300 /**
301 * Get the total bounds of this collection which is calculated by doing a
302 * union of the bounds of each feature inside of it
303 *
304 * @return An Envelope containing the total bounds of this collection.
305 */
306 ReferencedEnvelope getBounds();
307
308 //
309 // ResourceCollection methods
310 //
311 /**
312 * An iterator over this collection, which must be closed after use.
313 * <p>
314 * Collection is not guaranteed to be ordered in any manner.
315 * </p>
316 * <p>
317 * The implementation of Collection must adhere to the rules of
318 * fail-fast concurrent modification. In addition (to allow for
319 * resource backed collections, the <code>close( Iterator )</code>
320 * method must be called.
321 * <p>
322 * </p>
323 * Example (safe) use:<pre><code>
324 * Iterator iterator = collection.iterator();
325 * try {
326 * while( iterator.hasNext();){
327 * Feature feature = (Feature) iterator.hasNext();
328 * System.out.println( feature.getID() );
329 * }
330 * }
331 * finally {
332 * collection.close( iterator );
333 * }
334 * </code></pre>
335 * </p>
336 * @return Iterator
337 * @deprecated Please use features() to obtain a FeatureIterator
338 */
339 public Iterator<F> iterator();
340
341 /**
342 * Close any outstanding resources released by this resources.
343 * <p>
344 * This method should be used with great caution, it is however available
345 * to allow the use of the ResourceCollection with algorthims that are
346 * unaware of the need to close iterators after use.
347 * </p>
348 * <p>
349 * Example of using a normal Collections utility method:<pre><code>
350 * Collections.sort( collection );
351 * collection.purge();
352 * </code></pre>
353 * @deprecated Please use features() to obtain a FeatureIterator
354 */
355 public void purge();
356
357 /**
358 * Add object to this collection.
359 * <p>
360 * This method is often not impelmented for collections produced as the result of a query.
361 *
362 * @return true of the element was added
363 * @see java.util.Collection#add(Object)
364 */
365 boolean add(F obj);
366
367 /**
368 * Add all the objects to the collection.
369 * <p>
370 * This method is often not implemented for collections produced as the results of a query.
371 * @see java.util.Collection#addAll(Collection)
372 */
373 boolean addAll(Collection<? extends F> collection);
374
375 /** @see #addAll(Collection) */
376 boolean addAll(FeatureCollection<? extends T,? extends F> resource);
377
378 /** @see java.util.Collection#clear() */
379 void clear();
380
381 /**
382 * @see java.util.Collection#contains(Object)
383 */
384 boolean contains(Object o);
385
386 /**
387 * @see java.util.Collection#containsAll(Collection)
388 */
389 boolean containsAll(Collection<?> o);
390
391 /** @see java.util.Collection#isEmpty() */
392 boolean isEmpty();
393
394 /** @see java.util.Collection#remove(Object) */
395 boolean remove(Object o);
396
397 /** @see java.util.Collection#removeAll(Collection) */
398 public boolean removeAll(Collection<?> c);
399
400 /** @see java.util.Collection#retainAll(Collection) */
401 public boolean retainAll(Collection<?> c);
402
403 /**
404 * @see java.util.Collection#size()
405 */
406 int size();
407
408 /** @see java.util.Collection#toArray() */
409 Object[] toArray();
410
411 /** @see java.util.Collection#toArray(Object[]) */
412 <O> O[] toArray(O[] a);
413}
Note: See TracBrowser for help on using the repository browser.