Esempio n. 1
0
  /**
   * Filters a list of points for points that are of the selected
   * Range or in the given range. The filtered list will appear in
   * the navtools point list display.
   * @internal
   *   @history 2009-01-08 Jeannie Walldren - Modified to remove
   *                          new filter points from the existing
   *                          filtered list. Previously, a new
   *                          filtered list was created from the
   *                          entire control net each time.
   *   @history 2010-06-03 Jeannie Walldren - Removed "std::"
   *                          since "using namespace std"
   *
   */
  void QnetPointRangeFilter::filter() {
    // Make sure there is a control net loaded
    if (controlNet() == NULL) {
      QMessageBox::information((QWidget *)parent(),
          "Error", "No points to filter");
      return;
    }

    // Make sure all the values we need have been entered by the user
    if ((m_minlat->text() == "") || (m_maxlat->text() == "") ||
        (m_minlon->text() == "") || (m_maxlon->text() == "")) {
      QMessageBox::information((QWidget *)parent(),
          "Error", "All lat/lon range values must be entered");
      return;
    }
    else {
      // Get the user entered values for the range
      double minlat = m_minlat->text().toDouble();
      double maxlat = m_maxlat->text().toDouble();
      double minlon = m_minlon->text().toDouble();
      double maxlon = m_maxlon->text().toDouble();

      // Make sure the lat values are in order
      if (minlat > maxlat) {
        QString msg = "The minimum latitude value must be less than the maximum latitude value";
        QMessageBox::information((QWidget *)parent(), "Error", msg);
        return;
      }
      // Make sure the lon values are in order
      else if (minlon > maxlon) {
        QString msg = "The minimum longitude value must be less than the maximum longitude value";
        QMessageBox::information((QWidget *)parent(), "Error", msg);
        return;
      }

      // Loop through each value of the filtered points list
      // checking to see if each point falls within the rangee
      // Loop in reverse order since removal list of elements affects index number
      for (int i = filteredPoints().size() - 1; i >= 0; i--) {
        // Get the current control point
        ControlPoint &cp = *(*controlNet())[filteredPoints()[i]];

        Latitude lat = cp.GetBestSurfacePoint().GetLatitude();
        Longitude lon = cp.GetBestSurfacePoint().GetLongitude();
        if (lat.inRange(Latitude(minlat,Angle::Degrees),Latitude(maxlat,Angle::Degrees)) &&
            lon.inRange(Longitude(minlon,Angle::Degrees),Longitude(maxlon,Angle::Degrees))) {
          continue;
        }
        else {
          filteredPoints().removeAt(i);
        }

      }
    }

    // Tell the navtool that a list has been filtered and it needs to update
    emit filteredListModified();
    return;
  }
Esempio n. 2
0
/**
 * Creates a longitude by parsing strings for degrees, minutes and seconds
 *
 * This is a helper method for the parse (const QString &) method.
 */
Longitude Longitude::parse (const QString &degrees, const QString &minutes, const QString &seconds, bool positive)
{
	bool numOk=false;

	int deg=degrees.toUInt (&numOk); if (!numOk) return Longitude ();
	int min=minutes.toUInt (&numOk); if (!numOk) return Longitude ();
	int sec=seconds.toUInt (&numOk); if (!numOk) return Longitude ();

	return Longitude (deg, min, sec, positive);
}
Esempio n. 3
0
// ==============================================================================================================================================
//
double Orbit::IntersectionInterpolate(Orbit *tgt,double start,double end,bool dir)
{
	int i;
	bool ok=false;
	double dif;
	double gamma,sector,aa,da,db,first=0;
	VECTOR3 v;

	gamma=start;
	sector=end;

	if (dir) sector=-sector;

	sector/=2;

	v=tgt->Position(gamma);
	Longitude(v,&db,NULL,&aa);
	da=Radius(aa);
	first=da-db;

	gamma+=sector;

	for (i=0;i<30;i++) {  
	      
		gamma=limit(gamma);
		v=tgt->Position(gamma);
		Longitude(v,&db,NULL,&aa);
		da=Radius(aa);
		dif=da-db;
	
		if ((first*dif)<0) sector=-sector, ok=true;
		first=dif;
		
		sector/=2;
		gamma+=sector;
        
	}

	if (!ok) return -1.0;

	return(tgt->Translate(this,limit(gamma)));
}
Esempio n. 4
0
/**
 * Normalizes the longitude
 *
 * A normalized longitude is larger than -180° and less than or equal to +180°.
 *
 * @return a new Longitude representing the same longitude, but normalized
 */
Longitude Longitude::normalized () const
{
	double newValue=fmod (value, 360);

	if (newValue>180)
		newValue-=360;
	else if (newValue<=-180)
		newValue+=360;

	return Longitude (newValue);
}
void SunsetPluginSettingsPane::on_filenameInput_editingFinished ()
{
	QString filename=ui.filenameInput->text ().trimmed ();

	fileSpecified=false;
	fileResolved=false;
	fileExists=false;
	fileOk=false;

	referenceLongitude=Longitude ();

	if (!isBlank (filename))
	{
		fileSpecified=true;

		QString resolved=plugin->resolveFilename (filename, getEffectivePluginPaths ());

		if (!resolved.isEmpty ())
		{
			fileResolved=true;
			resolvedFilename=QFileInfo (resolved).absoluteFilePath ();

			if (QFile::exists (resolved))
			{
				fileExists=true;

				try
				{
					source=SunsetPluginBase::readSource (resolved);

					QString referenceLongitudeString=SunsetPluginBase::readReferenceLongitudeString (resolved);
					referenceLongitudeFound=!referenceLongitudeString.isEmpty ();
					referenceLongitude=Longitude::parse (referenceLongitudeString);

					fileOk=true;
				}
				catch (FileOpenError &ex)
				{
					fileError=ex.errorString;
				}
			}
		}
	}

	updateFilenameLabel ();
	updateSourceLabel ();
	updateReferenceLongitudeLabel ();
	updateReferenceLongitudeNoteLabel ();
}
Esempio n. 6
0
  /**
   * Find the lat/lon range of the image. This will use the image footprint,
   *   camera, or projection in order to find a good result.
   *
   * @param Cube* This is required for estimation. You can pass in NULL (it will
   *              disable estimation).
   * @param minLat This is an output: minimum latitude
   * @param maxLat This is an output: maximum latitude
   * @param minLon This is an output: minimum longitude
   * @param maxLon This is an output: maximum longitude
   * @param allowEstimation If this is true then extra efforts will be made to
   *     guess the ground range of the input. This can still fail.
   * @return True if a ground range was found, false if no ground range could
   *     be determined. Some lat/lon results may still be populated; their
   *     values are undefined.
   */
  bool UniversalGroundMap::GroundRange(Cube *cube, Latitude &minLat,
      Latitude &maxLat, Longitude &minLon, Longitude &maxLon,
      bool allowEstimation) {
    // Do we need a RingRange method?
    // For now just return false
    if (HasCamera())
      if (p_camera->target()->shape()->name() == "Plane") return false;
    if (HasProjection()) 
      if (p_projection->projectionType() == Projection::RingPlane) return false;

    minLat = Latitude();
    maxLat = Latitude();
    minLon = Longitude();
    maxLon = Longitude();

    // If we have a footprint, use it
    try {
      if (cube) {
        ImagePolygon poly;
        cube->read(poly);
        geos::geom::MultiPolygon *footprint = PolygonTools::MakeMultiPolygon(
            poly.Polys()->clone());

        geos::geom::Geometry *envelope = footprint->getEnvelope();
        geos::geom::CoordinateSequence *coords = envelope->getCoordinates();

        for (unsigned int i = 0; i < coords->getSize(); i++) {
          const geos::geom::Coordinate &coord = coords->getAt(i);

          Latitude coordLat(coord.y, Angle::Degrees);
          Longitude coordLon(coord.x, Angle::Degrees);

          if (!minLat.isValid() || minLat > coordLat)
            minLat = coordLat;
          if (!maxLat.isValid() || maxLat < coordLat)
            maxLat = coordLat;

          if (!minLon.isValid() || minLon > coordLon)
            minLon = coordLon;
          if (!maxLon.isValid() || maxLon < coordLon)
            maxLon = coordLon;
        }

        delete coords;
        coords = NULL;

        delete envelope;
        envelope = NULL;

        delete footprint;
        footprint = NULL;
      }
    }
    catch (IException &) {
    }

    if (!minLat.isValid() || !maxLat.isValid() ||
        !minLon.isValid() || !maxLon.isValid()) {
      if (HasCamera()) {
        // Footprint failed, ask the camera
        PvlGroup mappingGrp("Mapping");
        mappingGrp += PvlKeyword("LatitudeType", "Planetocentric");
        mappingGrp += PvlKeyword("LongitudeDomain", "360");
        mappingGrp += PvlKeyword("LongitudeDirection", "PositiveEast");

        Pvl mappingPvl;
        mappingPvl += mappingGrp;
        double minLatDouble;
        double maxLatDouble;
        double minLonDouble;
        double maxLonDouble;
        p_camera->GroundRange(
            minLatDouble, maxLatDouble,
            minLonDouble, maxLonDouble, mappingPvl);
        minLat = Latitude(minLatDouble, Angle::Degrees);
        maxLat = Latitude(maxLatDouble, Angle::Degrees);
        minLon = Longitude(minLonDouble, Angle::Degrees);
        maxLon = Longitude(maxLonDouble, Angle::Degrees);
      }
      else if (HasProjection()) {
        // Footprint failed, look in the mapping group
        PvlGroup mappingGrp = p_projection->Mapping();
        if (mappingGrp.hasKeyword("MinimumLatitude") &&
            mappingGrp.hasKeyword("MaximumLatitude") &&
            mappingGrp.hasKeyword("MinimumLongitude") &&
            mappingGrp.hasKeyword("MaximumLongitude")) {

          minLat = Latitude(mappingGrp["MinimumLatitude"],
                            mappingGrp, Angle::Degrees);
          maxLat = Latitude(mappingGrp["MaximumLatitude"],
                            mappingGrp, Angle::Degrees);
          minLon = Longitude(mappingGrp["MinimumLongitude"],
                             mappingGrp, Angle::Degrees);
          maxLon = Longitude(mappingGrp["MaximumLongitude"],
                             mappingGrp, Angle::Degrees);

        }
        else if (allowEstimation && cube) {
          // Footprint and mapping failed... no lat/lon range of any kind is
          //   available. Let's test points in the image to try to make our own
          //   extent.
          QList<QPointF> imagePoints;

          // Reset to TProjection
          TProjection *tproj = (TProjection *) p_projection;

                    /*
           * This is where we're testing:
           *
           *  |---------------|
           *  |***************|
           *  |**     *     **|
           *  |*  *   *   *  *|
           *  |*    * * *    *|
           *  |***************|
           *  |*    * * *    *|
           *  |*  *   *   *  *|
           *  |**     *     **|
           *  |***************|
           *  |---------------|
           *
           * We'll test at the edges, a plus (+) and an (X) to help DEMs work.
           */

          int sampleCount = cube->sampleCount();
          int lineCount = cube->lineCount();

          int stepsPerLength = 20; //number of steps per length
          double aspectRatio = (double)lineCount / (double)sampleCount;
          double xStepSize = sampleCount / stepsPerLength;
          double yStepSize = xStepSize * aspectRatio;

          if (lineCount > sampleCount) {
            aspectRatio = (double)sampleCount / (double)lineCount;
            yStepSize = lineCount / stepsPerLength;
            xStepSize = yStepSize * aspectRatio;
          }

          double yWalked = 0.5;

          //3 vertical lines
          for (int i = 0; i < 3; i++) {
            double xValue = 0.5 + ( i * (sampleCount / 2) );

            while (yWalked <= lineCount) {
              imagePoints.append( QPointF(xValue, yWalked) );
              yWalked += yStepSize;
            }

            yWalked = 0.5;
          }

          double xWalked = 0.5;

          //3 horizontal lines
          for (int i = 0; i < 3; i++) {
            double yValue = 0.5 + ( i * (lineCount / 2) );

            while (xWalked <= sampleCount) {
              imagePoints.append( QPointF(xWalked, yValue) );
              xWalked += xStepSize;
            }

            xWalked = 0.5;
          }

          double xDiagonalWalked = 0.5;
          double yDiagonalWalked = 0.5;
          xStepSize = sampleCount / stepsPerLength;
          yStepSize = lineCount / stepsPerLength;

          //Top-Down Diagonal
          while ( (xDiagonalWalked <= sampleCount) && (yDiagonalWalked <= lineCount) ) {
            imagePoints.append( QPointF(xDiagonalWalked, yDiagonalWalked) );
            xDiagonalWalked += xStepSize;
            yDiagonalWalked += yStepSize;
          }

          xDiagonalWalked = 0.5;

          //Bottom-Up Diagonal
          while ( (xDiagonalWalked <= sampleCount) && (yDiagonalWalked >= 0) ) {
            imagePoints.append( QPointF(xDiagonalWalked, yDiagonalWalked) );
            xDiagonalWalked += xStepSize;
            yDiagonalWalked -= yStepSize;
          }

          foreach (QPointF imagePoint, imagePoints) {
            if (tproj->SetWorld(imagePoint.x(), imagePoint.y())) {
              Latitude latResult(tproj->UniversalLatitude(),
                                 Angle::Degrees);
              Longitude lonResult(tproj->UniversalLongitude(),
                                  Angle::Degrees);
              if (minLat.isValid())
                minLat = qMin(minLat, latResult);
              else
                minLat = latResult;

              if (maxLat.isValid())
                maxLat = qMax(maxLat, latResult);
              else
                maxLat = latResult;

              if (minLon.isValid())
                minLon = qMin(minLon, lonResult);
              else
                minLon = lonResult;

              if (maxLon.isValid())
                maxLon = qMax(maxLon, lonResult);
              else
                maxLon = lonResult;
            }
          }
        }
      }
    }
Esempio n. 7
0
long Shred::GlobalY(const int y) const {
    return (Longitude() - CoordOfShred(y))*SHRED_WIDTH + y;
}
Esempio n. 8
0
int main()
{
    return 0;

    Wgs84d2 coord(Latitude(30), Longitude(50.));
}
Esempio n. 9
0
int main (void)
{
  xmlTextReaderPtr xml = xmlReaderForFd (STDIN_FILENO, "", NULL, 0);
  FILE *file = fopen ("gosmore.pak", "r");
  if (!xml || !file || fseek (file, 0, SEEK_END) != 0 ||
        !GosmInit (mmap (NULL, ftell (file), PROT_READ, MAP_SHARED,
                              fileno (file), 0), ftell (file))) {
    fprintf (stderr, "Unable to open gosmore.pak\n");
    return 1;
  }
                              
  
  int ptCnt = 0;
  printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  "<gpx\n"
  " version=\"1.0\"\n"
  " creator=\"osmunda\"\n"
  " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
  " xmlns=\"http://www.topografix.com/GPX/1/0\"\n"
  " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/\">\n");
  while (xmlTextReaderRead (xml)) {
    char *name = (char *) BAD_CAST xmlTextReaderName (xml);
    if (xmlTextReaderNodeType (xml) == XML_READER_TYPE_ELEMENT) {
      while (stricmp (name, "trkpt") == 0 &&
             xmlTextReaderMoveToNextAttribute (xml)) {
        char *aname = (char *) BAD_CAST xmlTextReaderName (xml);
        char *avalue = (char *) BAD_CAST xmlTextReaderValue (xml);
        if (stricmp (aname, "lat") == 0) tlat = Latitude (atof (avalue));
        if (stricmp (aname, "lon") == 0) tlon = Longitude (atof (avalue));
        xmlFree (aname);
        xmlFree (avalue);
      }
    }
    if (xmlTextReaderNodeType (xml) == XML_READER_TYPE_END_ELEMENT) {
      if (stricmp (name, "trkpt") == 0) {
        if (ptCnt++ > 0) {
          int vehicle[] = { bicycleR, motorcarR, footR }, i;
          for (i = 0; i < sizeof (vehicle) / sizeof (vehicle[0]); i++) {
            Route (TRUE, 0, 0, /*tlon - flon, tlat - flat,*/ bicycleR, 0);
            //routeNode *itr;
            //for (itr = shortest; itr->shortest; itr = itr->shortest) {}
            if (routeHeapSize > 0 && (!shortest || !shortest->shortest ||
                !shortest->shortest->shortest)) break;
          }
          if (i == sizeof (vehicle) / sizeof (vehicle[0])) {
//                fprintf (stderr, "%d\n", shortest->best);
            printf ("<trk>\n<trkseg>\n<trkpt lat=\"%.5lf\" "
              "lon=\"%.5lf\"/>\n<trkpt lat=\"%.5lf\" lon=\"%.5lf\"/>\n"
              "</trkseg>\n</trk>\n", LatInverse (flat), LonInverse (flon),
              LatInverse (tlat), LonInverse (tlon));
          }
        }
        flat = tlat;
        flon = tlon;
      }
      if (stricmp (name, "trk") == 0) ptCnt = 0; // Gap in track
    }
    xmlFree (name);
  }
  printf ("</gpx>\n");
  return 0;
}