Debian Codegraph @

src/imageclasses/JimList.h

raw symbols SCIP
1 /**********************************************************************
2 JimList.h: class to read raster files using GDAL API library
3 Author(s): [email protected]
4 Copyright (C) 2016-2020 European Union (Joint Research Centre)
5
6 This file is part of jiplib.
7
8 jiplib is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 jiplib is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with jiplib. If not, see <https://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 #ifndef _JIMLIST_H_
22 #define _JIMLIST_H_
23
24 #include <string>
25 #include <vector>
26 #include <list>
27 #include <memory>
28 // #include "boost/date_time/posix_time/posix_time.hpp"
29 /* #include "ImgReaderOgr.h" */
30 #include "Jim.h"
31 #include "VectorOgr.h"
32 #include "apps/AppFactory.h"
33
34 #include "config_jiplib.h"
35
36 #if MIALLIB == 1
37 extern "C" {
38 #include "miallib_swig.h"
39 #include "miallib_convolve.h"
40 #include "miallib_dem.h"
41 #include "miallib_dist.h"
42 #include "miallib_erodil.h"
43 #include "miallib_format.h"
44 #include "miallib_geodesy.h"
45 #include "miallib_geometry.h"
46 #include "miallib_hmt.h"
47 #include "miallib_imem.h"
48 #include "miallib_io.h"
49 #include "miallib_label.h"
50 #include "miallib_miscel.h"
51 #include "miallib_opclo.h"
52 #include "miallib_pointop.h"
53 #include "miallib_proj.h"
54 #include "miallib_segment.h"
55 #include "miallib_stats.h"
56 #include "op.h"
57 }
58 #endif
59
60 //todo: namespace jiplib
61 namespace app{
62 class AppFactory;
63 }
64
65 class Jim;
66 class VectorOgr;
67 /**
68 This class is used to store a list of raster images
69 **/
70 /* class JimList : public std::vector<std::shared_ptr<Jim> > */
71 class JimList : public std::list<std::shared_ptr<Jim> >
72 {
73 public:
74 enum CRULE_TYPE {overwrite=0, maxndvi=1, maxband=2, minband=3, validband=4, mean=5, mode=6, median=7,sum=8,minallbands=9,maxallbands=10,stdev=11};
75 ///default constructor
76 JimList(){};// : std::vector<Jim*>() {};
77 ///copy constructor
78 JimList(const JimList &jimlist){
79 /* std::vector<std::shared_ptr<Jim> >::const_iterator pimit=jimlist.begin(); */
80 std::list<std::shared_ptr<Jim> >::const_iterator pimit=jimlist.begin();
81 for(pimit=jimlist.begin();pimit!=jimlist.end();++pimit)
82 pushImage(*pimit);
83 std::vector<double> nodata;
84 jimlist.getNoDataValues(nodata);
85 setNoData(nodata);
86 }
87 /* JimList(const std::vector<std::shared_ptr<Jim> > &coll){ */
88 /* std::vector<std::shared_ptr<Jim> >::const_iterator pimit=coll.begin(); */
89 /* for(pimit=coll.begin();pimit!=coll.end();++pimit) */
90 /* pushImage(*pimit); */
91 /* } */
92 JimList(unsigned int theSize);
93 ///constructor using vector of images
94 JimList(const std::list<std::shared_ptr<Jim> > &jimlist);
95 ///constructor from an AppFactory
96 JimList(app::AppFactory& theApp){open(theApp);};
97 ///constructor from a JSON string
98 JimList& open(const std::string& strjson);
99 ///constructor from an app
100 JimList& open(app::AppFactory& theApp);
101 ///create a JSON string from a list
102 std::string jl2json();
103 ///destructor
104 ~JimList(){};
105
106 // JimList(const JimList&) = default;
107 // JimList& operator=(const JimList&) = default;
108
109 ///get bounding box of image list
110 void getBoundingBox(double& ulx, double& uly, double& lrx, double& lry) const;
111 ///get upper left x coordinate of image list
112 double getUlx() const {double ulx, uly, lrx, lry;getBoundingBox(ulx,uly,lrx,lry);return(ulx);};
113 ///get upper left y coordinate of image list
114 double getUly() const {double ulx, uly, lrx, lry;getBoundingBox(ulx,uly,lrx,lry);return(uly);};
115 ///get lower right x coordinate of image list
116 double getLrx() const {double ulx, uly, lrx, lry;getBoundingBox(ulx,uly,lrx,lry);return(lrx);};
117 ///get lower right y coordinate of image list
118 double getLry() const {double ulx, uly, lrx, lry;getBoundingBox(ulx,uly,lrx,lry);return(lry);};
119 // ///get begin and last time of image list
120 // boost::posix_time::time_period getTimePeriod();
121
122 // ///filter list according to period
123 // void filterTime(const boost::posix_time::time_period& thePeriod){
124 // unsigned int index=0;
125 // std::vector<std::shared_ptr<Jim>>::iterator it=begin();
126 // std::vector<boost::posix_time::time_period>::iterator tit=m_time.begin();
127 // while(it!=end()&&tit!=m_time.end()){
128 // if(thePeriod.contains(m_time[m_index])){
129 // ++it;
130 // ++tit;
131 // }
132 // else{
133 // it=erase(it);
134 // tit=m_time.erase(tit);
135 // }
136 // }
137 // m_index=0;
138 // };
139 ///filter list according to bounding box
140 JimList& selectGeo(double ulx, double uly, double lrx, double lry);
141 ///filter list according to position
142 JimList& selectGeo(double x, double y);
143 ///push image to list
144 JimList& pushImage(const std::shared_ptr<Jim> imgRaster){
145 this->emplace_back(imgRaster);
146 return(*this);
147 };
148 ///pop image from list
149 JimList& popImage(){
150 this->pop_back();
151 return(*this);
152 };
153 ///get image from list (not recommended, because unlike random access vector iterator the complexity for a list iterator is linear in index)
154 std::shared_ptr<Jim> getImage(int index) const{
155 if(index>=this->size()){
156 std::cerr << "Error: index>=list size" << std::endl;
157 return(0);
158 }
159 std::list<std::shared_ptr<Jim>>::const_iterator it=begin();
160 std::advance(it,index);
161 return(*it);
162 }
163 size_t getSize() const{return size();};
164 // ///push image to list with corresponding period
165 // void pushImage(std::shared_ptr<Jim> imgRaster, boost::posix_time::time_period imgPeriod){
166 // this->emplace_back(imgRaster);
167 // // m_time.push_back(imgPeriod);
168 // };
169 // ///push image period
170 // void pushTime(boost::posix_time::time_period imgPeriod){
171 // m_time.push_back(imgPeriod);
172 // };
173 // ///set image periods for list
174 // void setTime(const std::vector<boost::posix_time::time_period>& timeVector){
175 // m_time=timeVector;
176 // };
177 // ///get image periods for list
178 // void getTime(std::vector<boost::posix_time::time_period>& timeVector){
179 // timeVector=m_time;
180 // };
181 ///Check if a geolocation is covered by this dataset. Only the bounding box is checked, irrespective of no data values.
182 bool covers(double x, double y, OGRCoordinateTransformation *poCT=0) const;
183 ///Check if a region of interest is (partially) covered by this dataset. Only the bounding box is checked, irrespective of no data values.
184 bool covers(double ulx, double uly, double lrx, double lry, bool all=false, OGRCoordinateTransformation *poCT=0) const;
185 ///Check if an image raster dataset is (partially) covered by this dataset. Only the bounding box is checked, irrespective of no data values.
186 bool covers(const Jim &imgRaster, bool all=false) const;
187 // std::shared_ptr<Jim> getNextImage(){
188 // if(m_index<size())
189 // return(this->at(m_index++));
190 // else
191 // return(0);
192 // }
193 // std::shared_ptr<Jim> getNextImage(boost::posix_time::time_period& imgPeriod){
194 // if(m_index<size()){
195 // if(m_index<m_time.size())
196 // imgPeriod=m_time[m_index];
197 // return(this->at(m_index++));
198 // }
199 // else
200 // return(0);
201 // }
202 /* JimList& resetIterator(){m_index=0;return(*this);}; */
203 JimList& clear(){std::list<std::shared_ptr<Jim> >::clear();return(*this);};
204 JimList& close();
205 ///Get the no data values of this dataset as a standard template library (stl) vector
206 void getNoDataValues(std::vector<double>& noDataValues) const;
207 ///Check if value is nodata in this dataset
208 bool isNoData(double value) const{if(m_noDataValues.empty()) return false;else return find(m_noDataValues.begin(),m_noDataValues.end(),value)!=m_noDataValues.end();};
209 ///Push a no data value for this dataset
210 void pushNoDataValue(double noDataValue);
211 ///Set the no data values of this dataset using a standard template library (stl) vector as input
212 void setNoData(const std::vector<double>& nodata){m_noDataValues=nodata;};
213 ///Clear the no data values
214 void clearNoData(){m_noDataValues.clear();}
215
216 ///composite image
217 void composite(Jim& imgWriter, app::AppFactory& app);
218 ///composite image only for in memory
219 std::shared_ptr<Jim> composite(app::AppFactory& app);
220 ///crop image
221 /* JimList& crop(Jim& imgWriter, app::AppFactory& app); */
222 ///crop image only for in memory
223 /* std::shared_ptr<Jim> crop(app::AppFactory& app); */
224 ///stack image
225 void stackBand(Jim& imgWriter, app::AppFactory& app);
226 ///stack image
227 void stackBand(Jim& imgWriter){app::AppFactory app;return stackBand(imgWriter,app);};
228 ///stack image only for in memory (alias for crop)
229 std::shared_ptr<Jim> stackBand(app::AppFactory& app);
230 ///stack image only for in memory (alias for crop)
231 std::shared_ptr<Jim> stackBand(){app::AppFactory app;return stackBand(app);};
232 ///stack image
233 void stackPlane(Jim& imgWriter, app::AppFactory& app);
234 ///stack image
235 void stackPlane(Jim& imgWriter){app::AppFactory app;return stackPlane(imgWriter,app);};
236 ///stack image only for in memory (alias for crop)
237 std::shared_ptr<Jim> stackPlane(app::AppFactory& app);
238 ///stack image only for in memory (alias for crop)
239 std::shared_ptr<Jim> stackPlane(){app::AppFactory app;return stackPlane(app);};
240 ///stat profile image
241 void statProfile(Jim& imgWriter, app::AppFactory& app);
242 ///stat profile image only for in memory
243 std::shared_ptr<Jim> statProfile(app::AppFactory& app);
244 ///get statistics
245 std::multimap<std::string,std::string> getStats(app::AppFactory& app);
246 //JimList& getStats(app::AppFactory& app);
247 ///validate image based on reference vector dataset (-ref)
248 JimList& validate(app::AppFactory& app);
249 ///extract vector layer from list
250 CPLErr extractOgr(VectorOgr& sampleReader, VectorOgr& ogrWriter, app::AppFactory& app);
251 ///extract vector layer from list only for in memory
252 std::shared_ptr<VectorOgr> extractOgr(VectorOgr& sampleReader, app::AppFactory& app);
253 size_t extractOgrMem(VectorOgr& sampleReader, std::vector<unsigned char> &vbytes, app::AppFactory& app);
254 //start insert from fun2method_imagetype_jimlist
255 //end insert from fun2method_imagetype_jimlist
256 private:
257 std::vector<double> m_noDataValues;
258 // std::vector<boost::posix_time::time_period> m_time;
259 };
260 static JimList createJimList(){JimList alist; return alist;};
261 static JimList createJimList(const std::list<std::shared_ptr<Jim> > &jimlist){JimList alist(jimlist);return alist;};
262 #endif // _JIIMLIST_H_