Skip to content

Commit

Permalink
issue #45: Finish site count implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Sep 20, 2023
1 parent a5d46be commit 8e0ac50
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 30 deletions.
104 changes: 75 additions & 29 deletions bagis-pro/AnalysisTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5669,42 +5669,78 @@ public static async Task<IList<string>> GenerateForecastStatisticsList(BA_Object
lstElements.Add(strElevMedianFt);

//snotel_sites_all, snolite_sites_all, scos_sites_all, coop_sites_all
string strSnotelCount = "0";
string strSnoliteCount = "0";
string strScosCount = "0";
string strCoopCount = "0";
Uri sitesUri = new Uri(GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers));
long snotelCount = await GeodatabaseTools.CountFeaturesAsync(sitesUri, Constants.FILE_SNOTEL);
if (snotelCount > 0)
{
strSnotelCount = Convert.ToString(snotelCount);
}
long snoliteCount = await GeodatabaseTools.CountFeaturesAsync(sitesUri, Constants.FILE_SNOLITE);
if (snoliteCount > 0)
{
strSnoliteCount = Convert.ToString(snoliteCount);
}
long scosCount = await GeodatabaseTools.CountFeaturesAsync(sitesUri, Constants.FILE_SNOW_COURSE);
if (scosCount > 0)
string strSnotelAll = "0";
string strSnoliteAll = "0";
string strScosAll = "0";
string strCoopAll = "0";
string strSnotelInside = "0";
string strSnoliteInside = "0";
string strScosInside = "0";
string strCoopInside = "0";
string strSnotelOutside = "0";
string strSnoliteOutside = "0";
string strScosOutside = "0";
string strCoopOutside = "0";


Uri layersUri = new Uri(GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers));
string[] arrSiteFiles = new string[] { Constants.FILE_SNOTEL, Constants.FILE_SNOLITE, Constants.FILE_SNOW_COURSE,
Constants.FILE_COOP_PILLOW};
long[] arrSitesAll = new long[] { 0,0,0,0};
long[] arrSitesInside = new long[] { 0, 0, 0, 0 };
// Load statistics into arrays
for (int i = 0; i < arrSiteFiles.Length; i++)
{
strScosCount = Convert.ToString(scosCount);
long sitesCount = await GeodatabaseTools.CountFeaturesAsync(layersUri, arrSiteFiles[i]);
if (sitesCount > 0)
{
arrSitesAll[i] = sitesCount;
}
long sitesInside = await GeodatabaseTools.CountPointsWithinInFeatureAsync(layersUri, arrSiteFiles[i],
aoiUri, Constants.FILE_AOI_VECTOR);
if (sitesInside > 0)
{
arrSitesInside[i] = sitesInside;
}
}
long coopCount = await GeodatabaseTools.CountFeaturesAsync(sitesUri, Constants.FILE_COOP_PILLOW);
if (coopCount > 0)
for (int i = 0; i < arrSiteFiles.Length; i++)
{
strCoopCount = Convert.ToString(coopCount);
long sitesOutside = arrSitesAll[i] - arrSitesInside[i];
switch (arrSiteFiles[i])
{
case Constants.FILE_SNOTEL:
strSnotelAll = Convert.ToString(arrSitesAll[i]);
strSnotelInside = Convert.ToString(arrSitesInside[i]);
strSnotelOutside = Convert.ToString(sitesOutside);
break;
case Constants.FILE_SNOLITE:
strSnoliteAll = Convert.ToString(arrSitesAll[i]);
strSnoliteInside = Convert.ToString(arrSitesInside[i]);
strSnoliteOutside = Convert.ToString(sitesOutside);
break;
case Constants.FILE_SNOW_COURSE:
strScosAll = Convert.ToString(arrSitesAll[i]);
strScosInside = Convert.ToString(arrSitesInside[i]);
strScosOutside = Convert.ToString(sitesOutside);
break;
case Constants.FILE_COOP_PILLOW:
strCoopAll = Convert.ToString(arrSitesAll[i]);
strCoopInside = Convert.ToString(arrSitesInside[i]);
strCoopOutside = Convert.ToString(sitesOutside);
break;
}
}

//sites
string strSitesBuffer = "Not Found";
string fcPath = "";
if (snotelCount > 0)
if (arrSitesAll[0] > 0) // Snotel
{
fcPath = sitesUri.LocalPath + "\\" + Constants.FILE_SNOTEL;
fcPath = layersUri.LocalPath + "\\" + arrSiteFiles[0];
}
else if (scosCount > 0)
else if (arrSitesAll[2] > 0) // Snow Course
{
fcPath = sitesUri.LocalPath + "\\" + Constants.FILE_SNOW_COURSE;
fcPath = layersUri.LocalPath + "\\" + arrSiteFiles[2];
}
if (!string.IsNullOrEmpty(fcPath))
{
Expand All @@ -5731,10 +5767,20 @@ await QueuedTask.Run( () =>
}

lstElements.Add(strSitesBuffer);
lstElements.Add(strSnotelCount);
lstElements.Add(strSnoliteCount);
lstElements.Add(strScosCount);
lstElements.Add(strCoopCount);
lstElements.Add(strSnotelAll);
lstElements.Add(strSnoliteAll);
lstElements.Add(strScosAll);
lstElements.Add(strCoopAll);
lstElements.Add(strSnotelInside);
lstElements.Add(strSnoliteInside);
lstElements.Add(strScosInside);
lstElements.Add(strCoopInside);
lstElements.Add(strSnotelOutside);
lstElements.Add(strSnoliteOutside);
lstElements.Add(strScosOutside);
lstElements.Add(strCoopOutside);



}
return lstElements;
Expand Down
4 changes: 3 additions & 1 deletion bagis-pro/DockAdminToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ private async void RunGenStatisticsImplAsync(object param)
StringBuilder output = new StringBuilder();
String[] headings = { "stationTriplet","stationName","aoiArea_SqMeters", "aoiArea_SqMiles", "ann_runoff_ratio_pct",
"centroid_x_dd","centroid_y_dd","state_codes","elev_min_ft","elev_max_ft","elev_range_ft","elev_median_ft",
"sites_buffer","snotel_sites_all","snolite_sites_all","scos_sites_all","coop_sites_all"};
"sites_buffer","snotel_sites_all","snolite_sites_all","scos_sites_all","coop_sites_all","snotel_sites_inside",
"snolite_sites_inside","scos_sites_inside","coop_sites_inside","snotel_sites_outside","snolite_sites_outside",
"scos_sites_outside","coop_sites_outside"};
output.AppendLine(string.Join(separator, headings));

for (int idxRow = 0; idxRow < Names.Count; idxRow++)
Expand Down

0 comments on commit 8e0ac50

Please sign in to comment.