for given lat long, access same lat lon in lat lon height file and print height

Hello,

I believe I am reading in a 3 column file with lat lon height ok and making vectors with the three columns, however I'm having trouble figuring out how to find the lat lon in the file and print the associated third column (height) given a latitude and longitude. Below is what I have thus far.

Best,

jm4smtddd


This part is in a separate include.h file:

1
2
3
4
5
6
7
8
9
10
11
      private:
                std::vector<double> latitudes_alt;
                std::vector<double> longitudes_alt;
                std::vector<double> altitudes;
                std::string topography_file;
                double altitude;
                double altitude_ref;


             double get_altitude (const double latitude,
                 const double longitude) const;


In another part of my .cc file I read in the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

 std::ifstream input2(topography_file.c_str());
                        if (input2.is_open())
                          {
                            std::string line;

                            while (true)
                              {
                                double latitude_alt, longitude_alt, altitude;
                                input2 >> latitude_alt >> longitude_alt >> altitude;
                                if (input2.eof())
                                  break;

                                latitudes_alt.push_back(latitude_alt);
                                longitudes_alt.push_back(longitude_alt);
                                altitudes.push_back(altitude);
                              }
                          }
                        else
                          throw std::ios_base::failure("Cannot open file " + topography_file
                              + "!!!");
 


All code above compiles ok and I've used similar versions of the above code to access and use another file in my program. Accessing the topography_file, finding the lat, lon, and height given any latitude and longitude and printing the height (altitude) is part where I'm stuck:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
   template <int dim>
    double Africa<dim>::get_altitude (const double latitude,
                 const double longitude) const
         {
    	 for (int i = 0; i <= latitudes_alt.size(); i++)
    	 {
    	  while (latitude == std::vector<double> latitudes_alt(i)
    	    && longitude == std::vector<double> longitudes_alt(i) )
    	  {
    	    altitude = std::vector<double> altitudes(i);
    	    break;
    	  }
    	 }
    	   return altitude;
         }


When compiling I get the following errors:

expected '(' for function-style cast
or type construction
while (latitude == std::vector<double> latitudes_alt(i)

AND


error: expected '(' for function-style cast
or type construction
altitude = std::vector<double> altitudes(i);
Figured out the answer, however I should find a certain that latitudes_alt and longitudes_alt within a certain range, like +- X.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    template <int dim>
    double Africa<dim>::get_altitude (const double latitude,
                 const double longitude) const
                 {
    	        	double altitude;
    				for (int i = 0; i <= latitudes_alt.size(); i++)
    	        	{
    	        		if ((latitude == latitudes_alt[i])
    	        				&& (longitude == longitudes_alt[i]))
    	        		{
    	        				altitude = altitudes[i];
    	        				break;
    	        		}
    	        	}
    	        	return altitude;
                 }
Topic archived. No new replies allowed.