Skip to content

Commit

Permalink
one last push to the pointInitialization stationFetch stuff for issue #…
Browse files Browse the repository at this point in the history
…506, at least for now

updated some of the deprecated gdal functions, but only within pointInitialization::fetchStationData(). The old deprecated gdal functions still seem to be working, and we still need to test this on windows, so I left them in the code for now

that being said, I only updated the deprecated gdal vector reading functions in the pointInitialization::fetchStationData() function, it seemed like there were other places within pointInit still using the deprecated functions, plus who knows where else in the code. In fact, the very getFeature() function that was causing so much trouble for issue #506 is still being used in some of the other parts of the pointInitialization code, going to need to watch out to see whether they cause problems in the future
  • Loading branch information
latwood committed Nov 18, 2023
1 parent d690d97 commit de51593
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/ninja/pointInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2837,11 +2837,13 @@ std::vector<std::string> pointInitialization::fixEmptySensor(std::vector<string>

bool pointInitialization::fetchStationData(string URL, string timeZone, bool latest)
{
OGRDataSourceH hDS;
//OGRDataSourceH hDS; // for old method, OGROpen()
GDALDatasetH hDS; // for new method, GDALOpenEx()
OGRLayerH hLayer;
OGRFeatureH hFeature;
CPLDebug("STATION_FETCH", "Downloading Data from MesoWest....");
hDS=OGROpen(URL.c_str(),0,NULL); //open the mesowest url
//hDS=OGROpen(URL.c_str(),0,NULL); //open the mesowest url // deprecated since gdal 2.0, use GDALOpenEx() with GDALDatasetH instead of OGRDataSourceH
hDS = GDALOpenEx( URL.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL ); //open the mesowest url

if (hDS==NULL) //This is mainly caused by a bad URL, the user enters something wrong
{
Expand All @@ -2852,10 +2854,12 @@ bool pointInitialization::fetchStationData(string URL, string timeZone, bool lat
}
//get the data

hLayer=OGR_DS_GetLayer(hDS,0);
//hLayer=OGR_DS_GetLayer(hDS,0); // deprecated since gdal 2.0, use GDALDatasetGetLayer() instead
hLayer=GDALDatasetGetLayer(hDS,0);
OGR_L_ResetReading(hLayer);

int fCount=OGR_L_GetFeatureCount(hLayer,1); // this is the number of weather stations
//GIntBig fCount=OGR_L_GetFeatureCount(hLayer,1); // as of gdal 2.0, returns GIntBig instead of int. still seems to work to use an int though
CPLDebug("STATION_FETCH","Found %i Stations...",fCount);
std::string csvName; //This is a prefix that generally comes from specifying an out directory or something

Expand Down Expand Up @@ -3169,7 +3173,8 @@ bool pointInitialization::fetchStationData(string URL, string timeZone, bool lat
}
OGR_F_Destroy(hFeature);
}
OGR_DS_Destroy(hDS);
//OGR_DS_Destroy(hDS); // deprecated since gdal 2.0, use GDALClose() instead, for GDALOpenEx() instead of OGROpen()
GDALClose(hDS);
if(stationChecks.size()>=fCount)
{
error_msg="ERROR: Data check failed on all stations, likley stations are missing sensors.";
Expand Down

0 comments on commit de51593

Please sign in to comment.