/** * 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; }
/** * Get the latitude in the planetographic coordinate system. If this instance * was not constructed with the planetary radii, then an exception will be * thrown. * * @see CoordinateType * @param units The angular units to get the latitude in * @return The Planetographic latitude value */ double Latitude::planetographic(Angle::Units units) const { if (m_equatorialRadius == NULL || m_polarRadius == NULL) { IString msg = "Latitude [" + IString(degrees()) + " degrees] cannot " "be converted to Planetographic without the planetary radii, please " "use the other Latitude constructor"; throw IException(IException::Programmer, msg, _FILEINFO_); } if (*this > Angle(90.0, Angle::Degrees) || *this < Angle(-90.0, Angle::Degrees)) { IString msg = "Latitudes outside of the -90/90 range cannot be converted " "between Planetographic and Planetocentric"; throw IException(IException::Programmer, msg, _FILEINFO_); } if(!isValid()) { IString msg = "Invalid planetographic latitudes are not currently " "supported"; throw IException(IException::Programmer, msg, _FILEINFO_); } double ographicLatitude = atan(tan(radians()) * (*m_equatorialRadius / *m_polarRadius) * (*m_equatorialRadius / *m_polarRadius)); // This theoretically should just be an angle, but make it a Latitude so // we can access angle return Latitude(ographicLatitude, Angle::Radians).angle(units); }
/** * Adds another latitude to this one. Handles planetographic latitudes. * * @param angleToAdd the latitude being added to this one * @param equatorialRadius * @param polarRadius * @param latType * @return The result */ Latitude Latitude::add(Angle angleToAdd, Distance equatorialRadius, Distance polarRadius, CoordinateType latType) { Latitude result; switch (latType) { case Planetocentric: result = Latitude(planetocentric() + angleToAdd.radians(), equatorialRadius, polarRadius, latType, Radians, m_errors); break; case Planetographic: result = Latitude(planetographic() + angleToAdd.radians(), equatorialRadius, polarRadius, latType, Radians, m_errors); break; } return result; }
/** * 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; } } } } }
long Shred::GlobalX(const int x) const { return (Latitude() - CoordOfShred(x))*SHRED_WIDTH + x; }
int main() { return 0; Wgs84d2 coord(Latitude(30), Longitude(50.)); }
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; }