GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2006 Refractions Research Inc. 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 **********************************************************************/ 00014 00015 #ifndef GEOS_GEOM_COORDINATESEQUENCE_H 00016 #define GEOS_GEOM_COORDINATESEQUENCE_H 00017 00018 #include <geos/export.h> 00019 #include <geos/platform.h> 00020 #include <geos/inline.h> 00021 00022 #include <geos/geom/Coordinate.h> // for applyCoordinateFilter 00023 00024 #include <vector> 00025 #include <iosfwd> // ostream 00026 #include <memory> // for auto_ptr typedef 00027 00028 // Forward declarations 00029 namespace geos { 00030 namespace geom { 00031 class Envelope; 00032 class CoordinateFilter; 00033 class Coordinate; 00034 } 00035 } 00036 00037 namespace geos { 00038 namespace geom { // geos::geom 00039 00059 class GEOS_DLL CoordinateSequence { 00060 00061 protected: 00062 00063 CoordinateSequence() {} 00064 00065 CoordinateSequence(const CoordinateSequence&) {} 00066 00067 public: 00068 00069 typedef std::auto_ptr<CoordinateSequence> AutoPtr; 00070 00071 virtual ~CoordinateSequence() {} 00072 00076 virtual CoordinateSequence *clone() const=0; 00077 00084 //virtual const Coordinate& getCoordinate(int i) const=0; 00085 virtual const Coordinate& getAt(std::size_t i) const=0; 00086 00088 const Coordinate& back() const { 00089 return getAt(size()-1); 00090 } 00091 00093 const Coordinate& front() const { 00094 return getAt(0); 00095 } 00096 00097 const Coordinate& operator[] (std::size_t i) const { 00098 return getAt(i); 00099 } 00100 00104 virtual void getAt(std::size_t i, Coordinate& c) const=0; 00105 00110 //virtual int size() const=0; 00111 virtual std::size_t getSize() const=0; 00112 00113 size_t size() const { return getSize(); } 00114 00135 virtual const std::vector<Coordinate>* toVector() const=0; 00136 00138 // 00141 virtual void toVector(std::vector<Coordinate>& coords) const=0; 00142 00150 void add(const std::vector<Coordinate>* vc, bool allowRepeated); 00151 00152 /* This is here for backward compatibility.. */ 00153 //void add(CoordinateSequence *cl,bool allowRepeated,bool direction); 00154 00167 void add(const CoordinateSequence *cl, bool allowRepeated, 00168 bool direction); 00169 00177 virtual void add(const Coordinate& c, bool allowRepeated); 00178 00190 virtual void add(std::size_t i, const Coordinate& coord, bool allowRepeated)=0; 00191 00193 virtual bool isEmpty() const=0; 00194 00196 virtual void add(const Coordinate& c)=0; 00197 00198 // Get number of coordinates 00199 //virtual int getSize() const=0; 00200 00202 //virtual const Coordinate& getAt(std::size_t pos) const=0; 00203 00205 virtual void setAt(const Coordinate& c, std::size_t pos)=0; 00206 00208 virtual void deleteAt(std::size_t pos)=0; 00209 00211 virtual std::string toString() const=0; 00212 00214 virtual void setPoints(const std::vector<Coordinate> &v)=0; 00215 00217 bool hasRepeatedPoints() const; 00218 00220 const Coordinate* minCoordinate() const; 00221 00222 00231 static CoordinateSequence* removeRepeatedPoints( 00232 const CoordinateSequence *cl); 00233 00235 // 00238 virtual CoordinateSequence& removeRepeatedPoints()=0; 00239 00244 static bool hasRepeatedPoints(const CoordinateSequence *cl); 00245 00250 static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n, 00251 CoordinateSequence *c); 00252 00258 static const Coordinate* minCoordinate(CoordinateSequence *cl); 00259 00261 // 00265 static int indexOf(const Coordinate *coordinate, 00266 const CoordinateSequence *cl); 00267 00273 static bool equals(const CoordinateSequence *cl1, 00274 const CoordinateSequence *cl2); 00275 00277 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate); 00278 00296 static int increasingDirection(const CoordinateSequence& pts); 00297 00299 static void reverse(CoordinateSequence *cl); 00300 00302 enum { X,Y,Z,M }; 00303 00310 virtual std::size_t getDimension() const=0; 00311 00322 virtual double getOrdinate(std::size_t index, std::size_t ordinateIndex) const=0; 00323 00330 virtual double getX(std::size_t index) const { return getOrdinate(index, X); } 00331 00338 virtual double getY(std::size_t index) const { return getOrdinate(index, Y); } 00339 00340 00349 virtual void setOrdinate(std::size_t index, std::size_t ordinateIndex, double value)=0; 00350 00358 virtual void expandEnvelope(Envelope &env) const; 00359 00360 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract 00361 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract 00362 00371 template <class T> 00372 void applyCoordinateFilter(T& f) 00373 { 00374 Coordinate c; 00375 for(std::size_t i=0, n=size(); i<n; ++i) 00376 { 00377 getAt(i, c); 00378 f.filter(c); 00379 setAt(c, i); 00380 } 00381 } 00382 00383 }; 00384 00385 GEOS_DLL std::ostream& operator<< (std::ostream& os, const CoordinateSequence& cs); 00386 00387 GEOS_DLL bool operator== (const CoordinateSequence& s1, const CoordinateSequence& s2); 00388 00389 GEOS_DLL bool operator!= (const CoordinateSequence& s1, const CoordinateSequence& s2); 00390 00391 } // namespace geos::geom 00392 } // namespace geos 00393 00394 //#ifdef GEOS_INLINE 00395 //# include "geos/geom/CoordinateSequence.inl" 00396 //#endif 00397 00398 #endif // ndef GEOS_GEOM_COORDINATESEQUENCE_H