7 #include "ProcessGroundPolygons.h"
11 #include "geos/geom/CoordinateSequence.h"
12 #include "geos/geom/CoordinateArraySequence.h"
13 #include "geos/geom/LineString.h"
14 #include "geos/geosAlgorithm.h"
16 #include "Application.h"
17 #include "BoxcarCachingAlgorithm.h"
18 #include "IException.h"
19 #include "PolygonTools.h"
20 #include "Projection.h"
25 ProcessGroundPolygons::ProcessGroundPolygons() {
40 void ProcessGroundPolygons::Rasterize(std::vector<double> &lat,
41 std::vector<double> &lon,
42 std::vector<double> &values) {
48 for (
unsigned int i = 0; i < lon.size() - 1; i++) {
49 if (fabs(lon[i] - lon[i+1]) > 180.0) {
57 geos::geom::CoordinateSequence *pts =
new geos::geom::CoordinateArraySequence();
58 for (
unsigned int i = 0; i < lat.size(); i++) {
59 pts->add(geos::geom::Coordinate(lon[i], lat[i]));
61 pts->add(geos::geom::Coordinate(lon[0], lat[0]));
63 geos::geom::Polygon *crossingPoly = Isis::globalFactory->createPolygon(
64 globalFactory->createLinearRing(pts), NULL);
66 geos::geom::MultiPolygon *splitPoly = NULL;
68 splitPoly = PolygonTools::SplitPolygonOn360(crossingPoly);
78 if (splitPoly != NULL) {
80 for (
unsigned int g = 0; g < splitPoly->getNumGeometries(); ++g) {
81 const geos::geom::Polygon *poly =
82 dynamic_cast<const geos::geom::Polygon *
>(splitPoly->getGeometryN(g));
84 geos::geom::CoordinateSequence *llcoords = poly->getExteriorRing()->getCoordinates();
88 std::vector<double> tlat;
89 std::vector<double> tlon;
90 for (
unsigned int cord = 0; cord < llcoords->getSize() - 1; ++cord) {
91 tlon.push_back(llcoords->getAt(cord).x);
92 tlat.push_back(llcoords->getAt(cord).y);
96 ProcessPolygons::Rasterize(p_samples, p_lines, values);
103 ProcessPolygons::Rasterize(p_samples, p_lines, values);
118 void ProcessGroundPolygons::Rasterize(std::vector<double> &lat,
119 std::vector<double> &lon,
120 int &band,
double &value) {
123 ProcessPolygons::Rasterize(p_samples, p_lines, band, value);
134 void ProcessGroundPolygons::Convert(std::vector<double> &lat,
135 std::vector<double> &lon) {
140 for (
unsigned int i = 0; i < lat.size(); i++) {
141 if (p_groundMap->SetUniversalGround(lat[i], lon[i])) {
142 p_samples.push_back(p_groundMap->Sample());
143 p_lines.push_back(p_groundMap->Line());
156 void ProcessGroundPolygons::EndProcess() {
158 if(p_groundMap != NULL) {
162 ProcessPolygons::EndProcess();
172 void ProcessGroundPolygons::Finalize() {
174 if(p_groundMap != NULL) {
178 ProcessPolygons::Finalize();
189 void ProcessGroundPolygons::AppendOutputCube(QString &cubeStr,
190 const QString &avgFileName,
191 const QString &countFileName) {
193 Cube cube(cubeStr,
"r");
195 ProcessPolygons::AppendOutputCube(avgFileName, countFileName);
209 void ProcessGroundPolygons::SetStatCubes(
const QString &avgFileName,
210 const QString &countFileName,
220 int nBands = this->InputCubes[0]->bandCount();
221 int nLines = this->InputCubes[0]->lineCount();
222 int nSamples = this->InputCubes[0]->sampleCount();
224 this->Process::SetOutputCube(avgFileName, outAtts, nSamples, nLines, nBands);
225 this->Process::SetOutputCube(countFileName, outAtts, nSamples, nLines, nBands);
244 void ProcessGroundPolygons::SetStatCubes(
const QString ¶meter,
248 Application::GetUserInterface().GetFileName(parameter);
250 Application::GetUserInterface().GetOutputAttribute(parameter);
253 QString path = file.
path();
255 QString countString = path +
"/" + filename +
"-count-";
257 SetStatCubes(avgString, countString, atts, cube);
269 void ProcessGroundPolygons::SetStatCubes(
const QString ¶meter,
273 Application::GetUserInterface().GetFileName(parameter);
275 Application::GetUserInterface().GetOutputAttribute(parameter);
278 QString path = file.
path();
280 QString countString = path +
"/" + filename +
"-count-";
282 SetStatCubes(avgString, countString, atts, map, bands);
301 void ProcessGroundPolygons::SetStatCubes(
const QString &avgFileName,
302 const QString &countFileName,
307 Projection *proj = ProjectionFactory::CreateForCube(map, samples, lines,
310 this->ProcessPolygons::SetStatCubes(avgFileName, countFileName, atts,
311 samples, lines, bands);
320 OutputCubes[0]->putGroup(group);
321 OutputCubes[1]->putGroup(group);
326 OutputCubes[0]->putGroup(alpha);
327 OutputCubes[1]->putGroup(alpha);