7#include "ProcessGroundPolygons.h"
11#include "geos/geom/CoordinateSequence.h"
12#include "geos/geom/LineString.h"
13#include "geos/io/WKTWriter.h"
15#include "Application.h"
16#include "BoxcarCachingAlgorithm.h"
17#include "IException.h"
18#include "PolygonTools.h"
19#include "Projection.h"
24 ProcessGroundPolygons::ProcessGroundPolygons() {
40 std::vector<double> &lon,
41 std::vector<double> &values) {
47 for (
unsigned int i = 0; i < lon.size() - 1; i++) {
48 if (fabs(lon[i] - lon[i+1]) > 180.0) {
56 geos::geom::CoordinateSequence pts;
57 for (
unsigned int i = 0; i < lat.size(); i++) {
58 pts.add(geos::geom::Coordinate(lon[i], lat[i]));
60 pts.add(geos::geom::Coordinate(lon[0], lat[0]));
62 geos::geom::Polygon *crossingPoly = Isis::globalFactory->createPolygon(
63 globalFactory->createLinearRing(pts)).release();
65 geos::geom::MultiPolygon *splitPoly = NULL;
77 if (splitPoly != NULL) {
79 for (
unsigned int g = 0; g < splitPoly->getNumGeometries(); ++g) {
80 const geos::geom::Polygon *poly =
81 dynamic_cast<const geos::geom::Polygon *
>(splitPoly->getGeometryN(g));
83 geos::geom::CoordinateSequence *llcoords =
84 poly->getExteriorRing()->getCoordinates().release();
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);
122 std::vector<double> &lon)
131 bool crosses =
false;
132 for (
unsigned int i = 0; i < lon.size() - 1; i++) {
133 if (fabs(lon[i] - lon[i+1]) > 180.0) {
142 geos::geom::CoordinateSequence pts;
143 for (
unsigned int i = 0; i < lat.size(); i++) {
144 pts.add(geos::geom::Coordinate(lon[i], lat[i]));
146 pts.add(geos::geom::Coordinate(lon[0], lat[0]));
148 geos::geom::Polygon *crossingPoly = Isis::globalFactory->createPolygon(
149 globalFactory->createLinearRing(pts)).release();
151 geos::geom::MultiPolygon *splitPoly = NULL;
163 if (splitPoly != NULL) {
165 for (
unsigned int g = 0; g < splitPoly->getNumGeometries(); ++g) {
166 const geos::geom::Polygon *poly =
167 dynamic_cast<const geos::geom::Polygon *
>(splitPoly->getGeometryN(g));
169 geos::geom::CoordinateSequence *llcoords =
170 poly->getExteriorRing()->getCoordinates().release();
174 std::vector<double> tlat;
175 std::vector<double> tlon;
176 for (
unsigned int cord = 0; cord < llcoords->getSize() - 1; ++cord) {
177 tlon.push_back(llcoords->getAt(cord).x);
178 tlat.push_back(llcoords->getAt(cord).y);
188 geos::geom::CoordinateSequence pts;
189 for (
unsigned int i = 0; i < lat.size(); i++) {
190 pts.add(geos::geom::Coordinate(lon[i], lat[i]));
192 pts.add(geos::geom::Coordinate(lon[0], lat[0]));
194 geos::geom::Polygon *singlePoly = Isis::globalFactory->createPolygon(
195 globalFactory->createLinearRing(pts)).release();
213 std::vector<double> &lon,
214 int &band,
double &value) {
229 std::vector<double> &lon) {
234 for (
unsigned int i = 0; i < lat.size(); i++) {
235 if (p_groundMap->SetUniversalGround(lat[i], lon[i])) {
236 p_samples.push_back(p_groundMap->Sample());
237 p_lines.push_back(p_groundMap->Line());
252 if(p_groundMap != NULL) {
268 if(p_groundMap != NULL) {
284 const QString &avgFileName,
285 const QString &countFileName) {
287 Cube cube(cubeStr,
"r");
304 const QString &countFileName,
314 int nBands = this->
InputCubes[0]->bandCount();
315 int nLines = this->
InputCubes[0]->lineCount();
316 int nSamples = this->
InputCubes[0]->sampleCount();
347 QString path = file.
path();
349 QString countString = path +
"/" + filename +
"-count-";
372 QString path = file.
path();
374 QString countString = path +
"/" + filename +
"-count-";
396 const QString &countFileName,
405 samples, lines, bands);
static UserInterface & GetUserInterface()
Returns the UserInterface object.
This algorithm is designed for applications that jump around between a couple of spots in the cube wi...
Manipulate and parse attributes of output cube filenames.
IO Handler for Isis Cubes.
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QString baseName() const
Returns the name of the file without the path and without extensions.
void Convert(std::vector< double > &lat, std::vector< double > &lon)
Converts lat/long to line/sample using the universal ground map object.
void AppendOutputCube(QString &cube, const QString &avgFileName, const QString &countFileName="")
This gives the option to append to the cube.
geos::geom::Geometry * Vectorize(std::vector< double > &lat, std::vector< double > &lon)
This method gets called from the application with the lat/lon vertices of a polygon.
void Finalize()
This method cleans up any open outputcube files and deletes the pointer to the universal ground map i...
void EndProcess()
This method cleans up any open outputcube files and deletes the pointer to the universal ground map i...
void SetStatCubes(const QString ¶meter, QString &cube)
This is a method that is called directly from the application.
void Rasterize(std::vector< double > &lat, std::vector< double > &lon, std::vector< double > &values)
This method gets called from the application with the lat/lon vertices of a polygon along with a vect...
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
virtual Isis::Cube * SetOutputCube(const QString ¶meter)
Allocates a user-specified output cube whose size matches the first input cube.
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
void ClearInputCubes()
Close owned input cubes from the list and clear the list.
Isis::Cube * AppendOutputCube(const QString &avgFileName, const QString &countFileName="")
This gives the option to append to the cube.
void Rasterize(std::vector< double > &samples, std::vector< double > &lines, std::vector< double > &values)
void SetStatCubes(const QString ¶meter, const int nsamps, const int nlines, int nbands=1)
void Finalize()
Cleans up by closing cubes and freeing memory for owned cubes.
static Isis::Projection * CreateForCube(Isis::Pvl &label, int &ns, int &nl, bool sizeMatch=true)
This method creates a map projection for a cube given a label.
Base class for Map Projections.
Contains multiple PvlContainers.
Container for cube-like labels.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
@ Traverse
Search child objects.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
QString GetCubeName(const QString ¶mName, QString extension="") const
Retrieves of a value for a parameter of type "cubename".
Isis::CubeAttributeOutput & GetOutputAttribute(const QString ¶mName)
Gets the attributes for an output cube.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.