Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

CoordinateSequence.h

00001 /**********************************************************************
00002  * $Id: CoordinateSequence.h 2556 2009-06-06 22:22:28Z strk $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2006 Refractions Research Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************/
00015 
00016 #ifndef GEOS_GEOM_COORDINATESEQUENCE_H
00017 #define GEOS_GEOM_COORDINATESEQUENCE_H
00018 
00019 #include <geos/export.h>
00020 #include <geos/platform.h>
00021 #include <geos/inline.h>
00022 
00023 #include <geos/geom/Coordinate.h> // for applyCoordinateFilter
00024 
00025 #include <vector>
00026 #include <iosfwd> // ostream
00027 #include <memory> // for auto_ptr typedef
00028 
00029 // Forward declarations
00030 namespace geos {
00031         namespace geom { 
00032                 class Envelope;
00033                 class CoordinateFilter;
00034                 class Coordinate;
00035         }
00036 }
00037 
00038 
00039 namespace geos {
00040 namespace geom { // geos::geom
00041 
00061 class GEOS_DLL CoordinateSequence {
00062 
00063 protected:
00064 
00065         CoordinateSequence() {}
00066 
00067         CoordinateSequence(const CoordinateSequence&) {}
00068 
00069 public:
00070 
00071         typedef std::auto_ptr<CoordinateSequence> AutoPtr;
00072 
00073         friend std::ostream& operator<< (std::ostream& os,
00074                 const CoordinateSequence& cs);
00075 
00076         friend bool operator== (
00077                 const CoordinateSequence& seq1,
00078                 const CoordinateSequence& seq2);
00079 
00080         friend bool operator!= (
00081                 const CoordinateSequence& seq1,
00082                 const CoordinateSequence& seq2);
00083 
00084         virtual ~CoordinateSequence() {}
00085 
00089         virtual CoordinateSequence *clone() const=0;
00090 
00097         //virtual const Coordinate& getCoordinate(int i) const=0;
00098         virtual const Coordinate& getAt(size_t i) const=0;
00099 
00101         const Coordinate& back() const {
00102                 return getAt(size()-1);
00103         }
00104 
00106         const Coordinate& front() const {
00107                 return getAt(0);
00108         }
00109 
00110         const Coordinate& operator[] (size_t i) const {
00111                 return getAt(i);
00112         }
00113 
00117         virtual void getAt(size_t i, Coordinate& c) const=0;
00118 
00123         //virtual int size() const=0;
00124         virtual size_t getSize() const=0;
00125 
00126         size_t size() const { return getSize(); }
00127 
00146         virtual const std::vector<Coordinate>* toVector() const=0;
00147 
00155         void add(const std::vector<Coordinate>* vc, bool allowRepeated);
00156 
00157         /* This is here for backward compatibility.. */
00158         //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00159 
00172         void add(const CoordinateSequence *cl, bool allowRepeated,
00173                         bool direction);
00174 
00182         virtual void add(const Coordinate& c, bool allowRepeated);
00183 
00195         virtual void add(size_t i, const Coordinate& coord, bool allowRepeated)=0;
00196 
00198         virtual bool isEmpty() const=0;
00199 
00201         virtual void add(const Coordinate& c)=0;
00202 
00203         // Get number of coordinates
00204         //virtual int getSize() const=0;
00205 
00207         //virtual       const Coordinate& getAt(size_t pos) const=0;
00208 
00210         virtual void setAt(const Coordinate& c, size_t pos)=0;
00211 
00213         virtual void deleteAt(size_t pos)=0;
00214 
00216         virtual std::string toString() const=0;
00217 
00219         virtual void setPoints(const std::vector<Coordinate> &v)=0;
00220         
00222         bool hasRepeatedPoints() const;
00223 
00225         const Coordinate* minCoordinate() const;
00226 
00227 
00236         static CoordinateSequence* removeRepeatedPoints(
00237                         const CoordinateSequence *cl);
00238 
00240         //
00243         virtual CoordinateSequence& removeRepeatedPoints()=0;
00244 
00249         static bool hasRepeatedPoints(const CoordinateSequence *cl);
00250 
00255         static CoordinateSequence* atLeastNCoordinatesOrNothing(size_t n,
00256                         CoordinateSequence *c);
00257 
00263         static const Coordinate* minCoordinate(CoordinateSequence *cl);
00264 
00266         //
00270         static int indexOf(const Coordinate *coordinate,
00271                         const CoordinateSequence *cl);
00272 
00278         static bool equals(const CoordinateSequence *cl1,
00279                         const CoordinateSequence *cl2);
00280 
00282         static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00283 
00301         static int increasingDirection(const CoordinateSequence& pts);
00302 
00304         static void reverse(CoordinateSequence *cl);
00305 
00307         enum { X,Y,Z,M };
00308 
00315         virtual size_t getDimension() const=0;
00316 
00327         virtual double getOrdinate(size_t index, size_t ordinateIndex) const=0;
00328 
00335         virtual double getX(size_t index) const { return getOrdinate(index, X); }
00336 
00343         virtual double getY(size_t index) const { return getOrdinate(index, Y); }
00344 
00345 
00354         virtual void setOrdinate(size_t index, size_t ordinateIndex, double value)=0;
00355 
00363         virtual void expandEnvelope(Envelope &env) const;
00364 
00365         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
00366         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
00367 
00376         template <class T>
00377         void applyCoordinateFilter(T& f) 
00378         {
00379                 Coordinate c;
00380                 for(size_t i=0, n=size(); i<n; ++i)
00381                 {
00382                         getAt(i, c);
00383                         f.filter(c);
00384                         setAt(c, i);
00385                 }
00386         }
00387 
00388 };
00389 
00390 std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
00391 
00392 bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
00393 
00394 bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
00395 
00396 } // namespace geos::geom
00397 } // namespace geos
00398 
00399 //#ifdef GEOS_INLINE
00400 //# include "geos/geom/CoordinateSequence.inl"
00401 //#endif
00402 
00403 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
00404 
00405 /**********************************************************************
00406  * $Log$
00407  * Revision 1.12  2006/06/12 16:51:23  strk
00408  * Added equality and inequality operators and tests
00409  *
00410  * Revision 1.11  2006/06/12 16:36:22  strk
00411  * indentation, notes about things to be fixed.
00412  *
00413  * Revision 1.10  2006/06/12 15:06:30  strk
00414  * Added default ctor and copy ctor (protected)
00415  *
00416  * Revision 1.9  2006/06/12 10:10:39  strk
00417  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
00418  *
00419  * Revision 1.8  2006/05/04 08:42:12  strk
00420  * Added note about the CoordinateSequence::toVector() method.
00421  *
00422  * Revision 1.7  2006/05/03 19:47:27  strk
00423  * added operator<< for CoordinateSequence
00424  *
00425  * Revision 1.6  2006/05/03 08:58:34  strk
00426  * added new non-static CoordinateSequence::removeRepeatedPoints() mutator.
00427  *
00428  * Revision 1.5  2006/04/11 11:55:22  strk
00429  * Added CoordinateSequence::AutoPtr typedef
00430  *
00431  * Revision 1.4  2006/04/04 09:53:45  strk
00432  * Fixed applyCoordinateFilter() templated function body
00433  *
00434  * Revision 1.3  2006/03/24 09:52:41  strk
00435  * USE_INLINE => GEOS_INLINE
00436  *
00437  * Revision 1.2  2006/03/20 17:27:03  strk
00438  * Bug #72 - Missing <vector> header
00439  *
00440  * Revision 1.1  2006/03/09 16:46:49  strk
00441  * geos::geom namespace definition, first pass at headers split
00442  *
00443  **********************************************************************/

Generated on Thu Jun 11 06:17:01 2009 for GEOS by  doxygen 1.4.4