GEOS 3.2.2
|
00001 /********************************************************************** 00002 * $Id: CoordinateSequence.h 2678 2009-10-17 12:28:41Z 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 00148 virtual const std::vector<Coordinate>* toVector() const=0; 00149 00151 // 00154 virtual void toVector(std::vector<Coordinate>& coords) const=0; 00155 00163 void add(const std::vector<Coordinate>* vc, bool allowRepeated); 00164 00165 /* This is here for backward compatibility.. */ 00166 //void add(CoordinateSequence *cl,bool allowRepeated,bool direction); 00167 00180 void add(const CoordinateSequence *cl, bool allowRepeated, 00181 bool direction); 00182 00190 virtual void add(const Coordinate& c, bool allowRepeated); 00191 00203 virtual void add(size_t i, const Coordinate& coord, bool allowRepeated)=0; 00204 00206 virtual bool isEmpty() const=0; 00207 00209 virtual void add(const Coordinate& c)=0; 00210 00211 // Get number of coordinates 00212 //virtual int getSize() const=0; 00213 00215 //virtual const Coordinate& getAt(size_t pos) const=0; 00216 00218 virtual void setAt(const Coordinate& c, size_t pos)=0; 00219 00221 virtual void deleteAt(size_t pos)=0; 00222 00224 virtual std::string toString() const=0; 00225 00227 virtual void setPoints(const std::vector<Coordinate> &v)=0; 00228 00230 bool hasRepeatedPoints() const; 00231 00233 const Coordinate* minCoordinate() const; 00234 00235 00244 static CoordinateSequence* removeRepeatedPoints( 00245 const CoordinateSequence *cl); 00246 00248 // 00251 virtual CoordinateSequence& removeRepeatedPoints()=0; 00252 00257 static bool hasRepeatedPoints(const CoordinateSequence *cl); 00258 00263 static CoordinateSequence* atLeastNCoordinatesOrNothing(size_t n, 00264 CoordinateSequence *c); 00265 00271 static const Coordinate* minCoordinate(CoordinateSequence *cl); 00272 00274 // 00278 static int indexOf(const Coordinate *coordinate, 00279 const CoordinateSequence *cl); 00280 00286 static bool equals(const CoordinateSequence *cl1, 00287 const CoordinateSequence *cl2); 00288 00290 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate); 00291 00309 static int increasingDirection(const CoordinateSequence& pts); 00310 00312 static void reverse(CoordinateSequence *cl); 00313 00315 enum { X,Y,Z,M }; 00316 00323 virtual size_t getDimension() const=0; 00324 00335 virtual double getOrdinate(size_t index, size_t ordinateIndex) const=0; 00336 00343 virtual double getX(size_t index) const { return getOrdinate(index, X); } 00344 00351 virtual double getY(size_t index) const { return getOrdinate(index, Y); } 00352 00353 00362 virtual void setOrdinate(size_t index, size_t ordinateIndex, double value)=0; 00363 00371 virtual void expandEnvelope(Envelope &env) const; 00372 00373 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract 00374 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract 00375 00384 template <class T> 00385 void applyCoordinateFilter(T& f) 00386 { 00387 Coordinate c; 00388 for(size_t i=0, n=size(); i<n; ++i) 00389 { 00390 getAt(i, c); 00391 f.filter(c); 00392 setAt(c, i); 00393 } 00394 } 00395 00396 }; 00397 00398 std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs); 00399 00400 bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2); 00401 00402 bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2); 00403 00404 } // namespace geos::geom 00405 } // namespace geos 00406 00407 //#ifdef GEOS_INLINE 00408 //# include "geos/geom/CoordinateSequence.inl" 00409 //#endif 00410 00411 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H 00412 00413 /********************************************************************** 00414 * $Log$ 00415 * Revision 1.12 2006/06/12 16:51:23 strk 00416 * Added equality and inequality operators and tests 00417 * 00418 * Revision 1.11 2006/06/12 16:36:22 strk 00419 * indentation, notes about things to be fixed. 00420 * 00421 * Revision 1.10 2006/06/12 15:06:30 strk 00422 * Added default ctor and copy ctor (protected) 00423 * 00424 * Revision 1.9 2006/06/12 10:10:39 strk 00425 * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t. 00426 * 00427 * Revision 1.8 2006/05/04 08:42:12 strk 00428 * Added note about the CoordinateSequence::toVector() method. 00429 * 00430 * Revision 1.7 2006/05/03 19:47:27 strk 00431 * added operator<< for CoordinateSequence 00432 * 00433 * Revision 1.6 2006/05/03 08:58:34 strk 00434 * added new non-static CoordinateSequence::removeRepeatedPoints() mutator. 00435 * 00436 * Revision 1.5 2006/04/11 11:55:22 strk 00437 * Added CoordinateSequence::AutoPtr typedef 00438 * 00439 * Revision 1.4 2006/04/04 09:53:45 strk 00440 * Fixed applyCoordinateFilter() templated function body 00441 * 00442 * Revision 1.3 2006/03/24 09:52:41 strk 00443 * USE_INLINE => GEOS_INLINE 00444 * 00445 * Revision 1.2 2006/03/20 17:27:03 strk 00446 * Bug #72 - Missing <vector> header 00447 * 00448 * Revision 1.1 2006/03/09 16:46:49 strk 00449 * geos::geom namespace definition, first pass at headers split 00450 * 00451 **********************************************************************/