Skip to content

Commit 9c7d664

Browse files
committed
Merge branch 'LANDFIRE-Endpoint-updates'
2 parents 9dfd853 + 5f69a0b commit 9c7d664

2 files changed

Lines changed: 34 additions & 38 deletions

File tree

src/ninja/landfireclient.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
7676
*-----------------------------------------------------------------------------*/
7777
int i = 0;
7878
char *p;
79-
//int nMaxTries = atoi( CPLGetConfigOption( "LCP_MAX_DOWNLOAD_TRIES", "40" ) );
8079
int nMaxTries = atoi( CPLGetConfigOption( "LCP_MAX_DOWNLOAD_TRIES", "300" ) );
8180
double dfWait = atof( CPLGetConfigOption( "LCP_DOWNLOAD_WAIT", "3" ) );
8281
const char *pszProduct = CPLStrdup( CSLFetchNameValue( options, "PRODUCT" ) );
@@ -97,21 +96,21 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
9796
CPLDebug( "LCP_CLIENT", "Testing if %s contains %s", osDataPath.c_str(),
9897
pszGeom );
9998
//using same code for all geographic areas, but could update by region as updates
100-
//become available. See codes at lfps.usgs.gov/helpdocs/productstable.html
99+
//become available. See codes at https://lfps.usgs.gov/products
101100
if( NinjaOGRContain( pszGeom, osDataPath.c_str(), "conus" ) )
102101
{
103-
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;200F40_20;200CC_20;" \
104-
"200CH_20;200CBH_20;200CBD_20" ); //2020 data
102+
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;240FBFM40;240CC;" \
103+
"240CH;240CBD;240CBH" ); //2024 data
105104
}
106105
else if( NinjaOGRContain( pszGeom, osDataPath.c_str(), "ak" ) )
107106
{
108-
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;200F40_20;200CC_20;" \
109-
"200CH_20;200CBH_20;200CBD_20" ); //2020 data
107+
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;240FBFM40;240CC;" \
108+
"240CH;240CBD;240CBH" ); //2024 data
110109
}
111110
else if( NinjaOGRContain( pszGeom, osDataPath.c_str(), "hi" ) )
112111
{
113-
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;200F40_20;200CC_20;" \
114-
"200CH_20;200CBH_20;200CBD_20" ); //2020 data
112+
pszProduct = CPLStrdup( "ELEV2020;SLPD2020;ASP2020;240FBFM40;240CC;" \
113+
"240CH;240CBD;240CBH" ); //2024 data
115114
}
116115
else
117116
{
@@ -153,6 +152,7 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
153152
m_poResult = CPLHTTPFetch( pszUrl, NULL );
154153
CHECK_HTTP_RESULT( "Failed to get download URL" );
155154
CPLDebug( "LCP_CLIENT", "Request URL: %s", pszUrl );
155+
156156
/*-----------------------------------------------------------------------------
157157
* Parse the JSON result of the request
158158
*-----------------------------------------------------------------------------*/
@@ -199,23 +199,22 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
199199
CSLT_STRIPENDSPACES | CSLT_STRIPLEADSPACES );
200200
int nTokens = CSLCount( papszTokens );
201201

202-
CPLDebug( "LCP_CLIENT", "papszTokens[2]: %s", papszTokens[2]);
203202
CPLDebug( "LCP_CLIENT", "papszTokens[3]: %s", papszTokens[3]);
204203

205-
for( int i = 1; i < nTokens; i++ )
206-
{
207-
if(EQUAL( papszTokens[i], "jobStatus" ))
208-
{
209-
if(EQUAL( papszTokens[i + 1], "esriJobSucceeded" ) )
210-
downloadReady = true;
211-
if(EQUAL( papszTokens[i + 1], "esriJobFailed" ) )
212-
downloadFailed = true;
213-
break;
214-
}
204+
if(EQUAL( papszTokens[5], "Succeeded" )) {
205+
downloadReady = true;
215206
}
207+
if(EQUAL( papszTokens[5], "Failed")) {
208+
downloadFailed = true;
209+
}
210+
216211
CPLDebug( "LCP_CLIENT", "Attempting to fetch LCP, try %d of %d, jobStatus: %s", i,
217212
nMaxTries, papszTokens[3] );
218213

214+
std::string strLCPTest = papszTokens[nTokens - 1];
215+
strLCPTest.pop_back(); // Removes the last character '}'
216+
downloadUrl = strLCPTest.c_str();
217+
219218
CSLDestroy( papszTokens );
220219
i++;
221220
CPLSleep( dfWait );
@@ -246,7 +245,7 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
246245
/*-----------------------------------------------------------------------------
247246
* Download the landfire model
248247
*-----------------------------------------------------------------------------*/
249-
pszUrl = CPLSPrintf( LF_DOWNLOAD_JOB_TEMPLATE, m_JobId.c_str(), m_JobId.c_str() );
248+
pszUrl = downloadUrl.c_str();
250249
m_poResult = CPLHTTPFetch( pszUrl, NULL );
251250
CHECK_HTTP_RESULT( "Failed to get job status" );
252251

@@ -277,15 +276,15 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
277276
papszFileList = VSIReadDirRecursive( pszVSIZip );
278277
int bFound = FALSE;
279278
std::string osFullPath;
280-
CPLDebug( "LCP_CLIENT", "Extracting %s", (CPLSPrintf("%s.tif", m_JobId.c_str())) );
281279
for( int i = 0; i < CSLCount( papszFileList ); i++ )
282280
{
283-
osFullPath = papszFileList[i];
284-
if( osFullPath.find( CPLSPrintf("%s.tif", m_JobId.c_str()) ) != std::string::npos )
285-
{
286-
bFound = TRUE;
287-
break;
288-
}
281+
osFullPath = papszFileList[i];
282+
if( osFullPath.size() >= 4 &&
283+
osFullPath.substr(osFullPath.size() - 4) == ".tif" )
284+
{
285+
bFound = TRUE;
286+
break;
287+
}
289288
}
290289
CSLDestroy( papszFileList );
291290
if( !bFound )
@@ -296,7 +295,7 @@ SURF_FETCH_E LandfireClient::FetchBoundingBox( double *bbox, double resolution,
296295
return SURF_FETCH_E_IO_ERR;
297296
}
298297
int nError = 0;
299-
const char *pszFileToFind = CPLSPrintf( "%s.tif", m_JobId.c_str() );
298+
const char *pszFileToFind = osFullPath.c_str();
300299
nError = ExtractFileFromZip( pszTmpZip, pszFileToFind, filename );
301300
if( nError )
302301
{

src/ninja/landfireclient.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@
5252
* REST API", string templates
5353
*-----------------------------------------------------------------------------*/
5454
#define LF_REQUEST_TEMPLATE "https://lfps.usgs.gov/" \
55-
"arcgis/rest/services/LandfireProductService/" \
56-
"GPServer/LandfireProductService/submitJob?" \
57-
"Output_Projection=%d&Layer_List=%s&" \
58-
"Area_of_Interest=%lf%%20%lf%%20%lf%%20%lf" \
59-
"&f=pjson"
55+
"api/job/submit?Email=wind.ninja.support@gmail.com" \
56+
"&Output_Projection=%d&Layer_List=%s" \
57+
"&Area_of_Interest=%lf%%20%lf%%20%lf%%20%lf" \
58+
"&Priority_Code=WNDNJA"
6059

61-
#define LF_DOWNLOAD_JOB_TEMPLATE "https://lfps.usgs.gov/arcgis/rest/directories/" \
62-
"arcgisjobs/landfireproductservice_gpserver/%s/scratch/%s.zip"
63-
64-
#define LF_GET_STATUS_TEMPLATE "https://lfps.usgs.gov/arcgis/rest/services/LandfireProductService/" \
65-
"GPServer/LandfireProductService/jobs/%s/?f=pjson"
60+
#define LF_GET_STATUS_TEMPLATE "https://lfps.usgs.gov/api/job/status?" \
61+
"JobId=%s"
6662

6763

6864
#define LF_DEFAULT_SRS_TOKENS "&prj=102039,&prj=0"
@@ -100,6 +96,7 @@ class LandfireClient : public SurfaceFetch
10096

10197
CPLHTTPResult *m_poResult;
10298
std::string m_JobId;
99+
std::string downloadUrl;
103100
};
104101

105102
#endif /* LANDFIRE_CLIENT_H_ */

0 commit comments

Comments
 (0)