GEOS  3.3.7
CoordinateSequence.h
00001 /**********************************************************************
00002  * $Id: CoordinateSequence.h 3255 2011-03-01 17:56:10Z mloskot $
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 namespace geos {
00039 namespace geom { // geos::geom
00040 
00060 class GEOS_DLL CoordinateSequence {
00061 
00062 protected:
00063 
00064         CoordinateSequence() {}
00065 
00066         CoordinateSequence(const CoordinateSequence&) {}
00067 
00068 public:
00069 
00070         typedef std::auto_ptr<CoordinateSequence> AutoPtr;
00071 
00072         virtual ~CoordinateSequence() {}
00073 
00077         virtual CoordinateSequence *clone() const=0;
00078 
00085         //virtual const Coordinate& getCoordinate(int i) const=0;
00086         virtual const Coordinate& getAt(std::size_t i) const=0;
00087 
00089         const Coordinate& back() const {
00090                 return getAt(size()-1);
00091         }
00092 
00094         const Coordinate& front() const {
00095                 return getAt(0);
00096         }
00097 
00098         const Coordinate& operator[] (std::size_t i) const {
00099                 return getAt(i);
00100         }
00101 
00105         virtual void getAt(std::size_t i, Coordinate& c) const=0;
00106 
00111         //virtual int size() const=0;
00112         virtual std::size_t getSize() const=0;
00113 
00114         size_t size() const { return getSize(); }
00115 
00136         virtual const std::vector<Coordinate>* toVector() const=0;
00137 
00139         //
00142         virtual void toVector(std::vector<Coordinate>& coords) const=0;
00143 
00151         void add(const std::vector<Coordinate>* vc, bool allowRepeated);
00152 
00153         /* This is here for backward compatibility.. */
00154         //void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00155 
00168         void add(const CoordinateSequence *cl, bool allowRepeated,
00169                         bool direction);
00170 
00178         virtual void add(const Coordinate& c, bool allowRepeated);
00179 
00191         virtual void add(std::size_t i, const Coordinate& coord, bool allowRepeated)=0;
00192 
00194         virtual bool isEmpty() const=0;
00195 
00197         virtual void add(const Coordinate& c)=0;
00198 
00199         // Get number of coordinates
00200         //virtual int getSize() const=0;
00201 
00203         //virtual       const Coordinate& getAt(std::size_t pos) const=0;
00204 
00206         virtual void setAt(const Coordinate& c, std::size_t pos)=0;
00207 
00209         virtual void deleteAt(std::size_t pos)=0;
00210 
00212         virtual std::string toString() const=0;
00213 
00215         virtual void setPoints(const std::vector<Coordinate> &v)=0;
00216         
00218         bool hasRepeatedPoints() const;
00219 
00221         const Coordinate* minCoordinate() const;
00222 
00223 
00232         static CoordinateSequence* removeRepeatedPoints(
00233                         const CoordinateSequence *cl);
00234 
00236         //
00239         virtual CoordinateSequence& removeRepeatedPoints()=0;
00240 
00245         static bool hasRepeatedPoints(const CoordinateSequence *cl);
00246 
00251         static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
00252                         CoordinateSequence *c);
00253 
00259         static const Coordinate* minCoordinate(CoordinateSequence *cl);
00260 
00262         //
00266         static int indexOf(const Coordinate *coordinate,
00267                         const CoordinateSequence *cl);
00268 
00274         static bool equals(const CoordinateSequence *cl1,
00275                         const CoordinateSequence *cl2);
00276 
00278         static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00279 
00297         static int increasingDirection(const CoordinateSequence& pts);
00298 
00300         static void reverse(CoordinateSequence *cl);
00301 
00303         enum { X,Y,Z,M };
00304 
00311         virtual std::size_t getDimension() const=0;
00312 
00323         virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const=0;
00324 
00331         virtual double getX(std::size_t index) const { return getOrdinate(index, X); }
00332 
00339         virtual double getY(std::size_t index) const { return getOrdinate(index, Y); }
00340 
00341 
00350         virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value)=0;
00351 
00359         virtual void expandEnvelope(Envelope &env) const;
00360 
00361         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
00362         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
00363 
00372         template <class T>
00373         void applyCoordinateFilter(T& f) 
00374         {
00375                 Coordinate c;
00376                 for(std::size_t i=0, n=size(); i<n; ++i)
00377                 {
00378                         getAt(i, c);
00379                         f.filter(c);
00380                         setAt(c, i);
00381                 }
00382         }
00383 
00384 };
00385 
00386 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs);
00387 
00388 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2);
00389 
00390 GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2);
00391 
00392 } // namespace geos::geom
00393 } // namespace geos
00394 
00395 //#ifdef GEOS_INLINE
00396 //# include "geos/geom/CoordinateSequence.inl"
00397 //#endif
00398 
00399 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H
00400 
00401 /**********************************************************************
00402  * $Log$
00403  * Revision 1.12  2006/06/12 16:51:23  strk
00404  * Added equality and inequality operators and tests
00405  *
00406  * Revision 1.11  2006/06/12 16:36:22  strk
00407  * indentation, notes about things to be fixed.
00408  *
00409  * Revision 1.10  2006/06/12 15:06:30  strk
00410  * Added default ctor and copy ctor (protected)
00411  *
00412  * Revision 1.9  2006/06/12 10:10:39  strk
00413  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
00414  *
00415  * Revision 1.8  2006/05/04 08:42:12  strk
00416  * Added note about the CoordinateSequence::toVector() method.
00417  *
00418  * Revision 1.7  2006/05/03 19:47:27  strk
00419  * added operator<< for CoordinateSequence
00420  *
00421  * Revision 1.6  2006/05/03 08:58:34  strk
00422  * added new non-static CoordinateSequence::removeRepeatedPoints() mutator.
00423  *
00424  * Revision 1.5  2006/04/11 11:55:22  strk
00425  * Added CoordinateSequence::AutoPtr typedef
00426  *
00427  * Revision 1.4  2006/04/04 09:53:45  strk
00428  * Fixed applyCoordinateFilter() templated function body
00429  *
00430  * Revision 1.3  2006/03/24 09:52:41  strk
00431  * USE_INLINE => GEOS_INLINE
00432  *
00433  * Revision 1.2  2006/03/20 17:27:03  strk
00434  * Bug #72 - Missing <vector> header
00435  *
00436  * Revision 1.1  2006/03/09 16:46:49  strk
00437  * geos::geom namespace definition, first pass at headers split
00438  *
00439  **********************************************************************/