/// <summary> /// DamagePotential within intensity.geometry /// </summary> /// <param name="intensity"></param> /// <param name="dpList"></param> /// <returns></returns> public List <MappedObject> getDamagePotentialsWithin(Intensity intensity, IList <MappedObject> dpList) { var project = DBManager.ActiveSession.Load <Project>(intensity.Project.Id); var dpListFiltered = new List <MappedObject>(); dpListFiltered.AddRange(dpList.Where(m => m.point != null && m.point.Within(intensity.geometry))); dpListFiltered.AddRange(dpList.Where(m => m.line != null && m.line.Within(intensity.geometry))); dpListFiltered.AddRange(dpList.Where(m => m.polygon != null && m.polygon.Within(intensity.geometry))); List <MappedObject> withinList = new List <MappedObject>(); foreach (var damagePotential in dpListFiltered) { var copyDamagePotential = (MappedObject)damagePotential.Clone(); copyDamagePotential.IsClipped = false; copyDamagePotential.Intensity = (Intensity)intensity.Clone(); //remember the intensity the mappedObject is in withinList.Add(copyDamagePotential); } return(withinList); }
/// <summary> /// Computation of all Damage Extent of a Damage Potential in a given Intensity /// </summary> /// <param name="mapObj">Damage Potential</param> /// <param name="intensity"></param> /// <returns></returns> public static DamageExtent computeDamageExtent(MappedObject mapObj, Intensity intensity)//, List<MappedObject> clippedObjects = null) { var _damageExtent = new DamageExtent() { Intensity = (Intensity)intensity.Clone(), //make sure shallow copy is used MappedObject = (MappedObject)mapObj.Clone(), //make sure shallow copy is used Clipped = mapObj.IsClipped, }; if (mapObj.point != null) { _damageExtent.geometry = mapObj.point; } if (mapObj.line != null) { _damageExtent.geometry = mapObj.line; } if (mapObj.polygon != null) { _damageExtent.geometry = mapObj.polygon; } int _intensityDegree = intensity.IntensityDegree; //0=high, 1=med, 2=low //Merge Objectparameter with Freefillparamter var _mergedObjParam = MappedObjectController.getMergedObjectParameter(mapObj); //get Objectparameters for NatHazard (Vulnerability, Mortality, indirect costs) int _motherObjectID = _mergedObjParam.MotherObjectparameter != null ? _mergedObjParam.MotherObjectparameter.ID : _mergedObjParam.ID; ObjectparameterPerProcess _objectParamProcess; _objectParamProcess = _mergedObjParam.ProcessParameters .Where(pp => pp.NatHazard.ID == intensity.NatHazard.ID && pp.Objectparameter.ID == _motherObjectID) .SingleOrDefault(); if (_objectParamProcess == null) { _damageExtent.Log += $"ERROR: NO PROCESS PARAMETER, count: {_mergedObjParam.ProcessParameters.Count} \n"; return(_damageExtent); } //get pra for intensity var _intensityController = new IntensityController(); PrA _prA = _intensityController.getPrA(intensity); if (_prA == null) { _damageExtent.Log += $"ERROR: NO PrA VALUES FOUND FOR PROCESS {intensity.NatHazard.Name.ToUpper()} \n"; return(_damageExtent); } // BUILDINGS and SPECIAL BUILDINGS if (_mergedObjParam.ObjectClass.ID <= 2) { //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PERSON DAMAGE double _deaths = _prA.Value * _mergedObjParam.Personcount * _mergedObjParam.Presence / 24.0; string _logDeaths1 = $"Deaths = prA * PersonCount * Presence/24"; string _logDeaths2 = $"Deaths = {_prA.Value:F3} * {_mergedObjParam.Personcount} * {_mergedObjParam.Presence:F1} / 24"; double _deathProbability = _mergedObjParam.Personcount > 0 ? 1.0d / _mergedObjParam.Personcount : 0; string _logDProb1 = _mergedObjParam.Personcount > 0 ? $"IndividualDeathRisk = 1 / PersonCount" : "ERROR: 1 / PersonCount"; string _logDProb2 = _mergedObjParam.Personcount > 0 ? $"IndividualDeathRisk = 1 / {_mergedObjParam.Personcount}" : $"ERROR: 1 / {_mergedObjParam.Personcount}"; if (_mergedObjParam.Personcount < 1) { _damageExtent.Log = $"{ResModel.DE_PersonCount} = {_mergedObjParam.Personcount} \n"; } //switching on intensity degree switch (_intensityDegree) { case 0: _deaths *= _objectParamProcess.MortalityHigh; _logDeaths1 += $" * MortalityHigh"; _logDeaths2 += $" * {_objectParamProcess.MortalityHigh:F3}"; break; case 1: _deaths *= _objectParamProcess.MortalityMedium; _logDeaths1 += $" * MortalityMedium"; _logDeaths2 += $" * {_objectParamProcess.MortalityMedium:F3}"; break; case 2: _deaths *= _objectParamProcess.MortalityLow; _logDeaths1 += $" * MortalityLow"; _logDeaths2 += $" * {_objectParamProcess.MortalityLow:F3}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } //looking for floors count, if available for this object type if (_mergedObjParam.HasProperties.Where(m => m.Property == nameof(_mergedObjParam.Floors)).Any()) { _deaths *= _mergedObjParam.Floors; _logDeaths1 += $" * Floors"; _logDeaths2 += $" * {_mergedObjParam.Floors}"; if (_mergedObjParam.Floors > 0) { _deathProbability /= _mergedObjParam.Floors; _logDProb1 += $" / Floors"; _logDProb2 += $" / {_mergedObjParam.Floors}"; } else { _damageExtent.Log += $"{ResModel.DE_Floors} = {_mergedObjParam.Floors} \n"; } } _damageExtent.Deaths = _deaths; _damageExtent.LogDeaths = _logDeaths1 + ";\n" + _logDeaths2; _deathProbability *= _deaths; _logDProb1 += $" * Deaths"; _logDProb2 += $" * {_deaths:F6}"; _damageExtent.DeathProbability = _deathProbability; _damageExtent.LogDeathProbability = _logDProb1 + ";\n" + _logDProb2; _damageExtent.PersonDamage = _deaths * WillingnessToPay; _damageExtent.LogPersonDamage = $"PersonDamage = Deaths * WillingnessToPay;\n"; _damageExtent.LogPersonDamage += $"PersonDamage = {_deaths:F6} * {WillingnessToPay:C}"; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PROPERTY DAMAGE double _propertyDamage = _prA.Value * _mergedObjParam.Value; string _logPropertyDamage1 = $"PropertyDamage = prA * Value"; string _logPropertyDamage2 = $"PropertyDamage = {_prA.Value:F3} * {_mergedObjParam.Value:C}"; switch (_mergedObjParam.FeatureType) { case 0: //POINT BASED OBJECT(like communication tower) _damageExtent.Piece = 1; _logPropertyDamage1 += $" * Piece"; _logPropertyDamage2 += $" * 1"; if (_damageExtent.Clipped) { _damageExtent.Part = 1.0d; } break; case 1: //LINE BASED OBJECT (like Aduccion) _damageExtent.Length = mapObj.line.Length; if (_damageExtent.Clipped) { var rawMapObject = MappedObjectController.ActiveSession.Load <MappedObject>(mapObj.ID); _damageExtent.Part = mapObj.line.Length / rawMapObject.line.Length; } _propertyDamage *= mapObj.line.Length; _logPropertyDamage1 += $" * Length"; _logPropertyDamage2 += $" * {mapObj.line.Length:F3}"; break; case 2: //POLYGON BASED OBJECT _damageExtent.Area = mapObj.polygon.Area; if (_damageExtent.Clipped) { var rawMapObject = MappedObjectController.ActiveSession.Load <MappedObject>(mapObj.ID); _damageExtent.Part = mapObj.polygon.Area / rawMapObject.polygon.Area; } _propertyDamage *= mapObj.polygon.Area; _logPropertyDamage1 += $" * Area"; _logPropertyDamage2 += $" * {mapObj.polygon.Area:F3}"; break; default: _damageExtent.Log += $"ERROR: BUILDING, FEATURETYPE = {_mergedObjParam.ObjectClass.ID}, {_mergedObjParam.FeatureType} \n"; return(_damageExtent); } //looking for floors count, if available for this object type if (_mergedObjParam.HasProperties.Where(m => m.Property == nameof(_mergedObjParam.Floors)).Any()) { _propertyDamage *= _mergedObjParam.Floors; _logPropertyDamage1 += $" * Floors"; _logPropertyDamage2 += $" * {_mergedObjParam.Floors}"; } switch (_intensityDegree) { case 0: _propertyDamage *= _objectParamProcess.VulnerabilityHigh; _logPropertyDamage1 += $" * VulnerabilityHigh"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityHigh:F3}"; break; case 1: _propertyDamage *= _objectParamProcess.VulnerabilityMedium; _logPropertyDamage1 += $" * VulnerabilityMedium"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityMedium:F3}"; break; case 2: _propertyDamage *= _objectParamProcess.VulnerabilityLow; _logPropertyDamage1 += $" * VulnerabilityLow"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityLow:F3}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } _damageExtent.PropertyDamage = _propertyDamage; _damageExtent.LogPropertyDamage = _logPropertyDamage1 + ";\n" + _logPropertyDamage2; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } // INFRASTRUCTURE else if (_mergedObjParam.ObjectClass.ID == 3) { //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PERSON DAMAGE // STREETS / BRIDGES // LINE OBJECT if (_mergedObjParam.FeatureType == 1) { if (_mergedObjParam.Personcount == 0) { _damageExtent.Deaths = 0; _damageExtent.LogDeaths = "no person damage"; _damageExtent.DeathProbability = 0; _damageExtent.LogDeathProbability = "no person damage"; _damageExtent.PersonDamage = 0; _damageExtent.LogPersonDamage = "no person damage"; } else { _damageExtent.Length = mapObj.line.Length; double _deaths = _prA.Value * _mergedObjParam.Personcount * (double)_mergedObjParam.NumberOfVehicles * _damageExtent.Length / (double)_mergedObjParam.Velocity / 24000.0d; string _logDeaths1 = $"Deaths = prA * PersonCount * NumberOfVehicles * Length / Velocity / 24000"; string _logDeaths2 = $"Deaths = {_prA.Value:F3} * {_mergedObjParam.Personcount} * {_mergedObjParam.NumberOfVehicles} * {_damageExtent.Length:F3} / {_mergedObjParam.Velocity} / 24000"; switch (_intensityDegree) { case 0: _deaths *= _objectParamProcess.MortalityHigh; _logDeaths1 += $" * MortalityHigh"; _logDeaths2 += $" * {_objectParamProcess.MortalityHigh:F3}"; break; case 1: _deaths *= _objectParamProcess.MortalityMedium; _logDeaths1 += $" * MortalityMedium"; _logDeaths2 += $" * {_objectParamProcess.MortalityMedium:F3}"; break; case 2: _deaths *= _objectParamProcess.MortalityLow; _logDeaths1 += $" * MortalityLow"; _logDeaths2 += $" * {_objectParamProcess.MortalityLow:F3}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } _damageExtent.Deaths = _deaths; _damageExtent.LogDeaths = _logDeaths1 + ";\n" + _logDeaths2; int _passagesSamePerson = 4; //TODO: HARD CODED double _deathProbability = _deaths * _passagesSamePerson / _mergedObjParam.NumberOfVehicles / _mergedObjParam.Personcount; string _logDProb1 = $"IndivudualDeathRisk = Deaths * PassagesSamePerson / NumberOfVehicles / PersonCount"; string _logDProb2 = $"IndivudualDeathRisk = {_deaths:F6} * {_passagesSamePerson} / {_mergedObjParam.NumberOfVehicles} / {_mergedObjParam.Personcount}"; _damageExtent.DeathProbability = _deathProbability; _damageExtent.LogDeathProbability = _logDProb1 + ";\n" + _logDProb2; _damageExtent.PersonDamage = _deaths * WillingnessToPay; _damageExtent.LogPersonDamage = $"PersonDamage = Deaths * WillingnessToPay;\n"; _damageExtent.LogPersonDamage += $"PersonDamage = {_deaths:F6} * {WillingnessToPay:C}"; } } // TOWERS // POINT OBJECT else if (_mergedObjParam.FeatureType == 0) { _damageExtent.Deaths = 0; _damageExtent.LogDeaths = "no person damage"; _damageExtent.DeathProbability = 0; _damageExtent.LogDeathProbability = "no person damage"; _damageExtent.PersonDamage = 0; _damageExtent.LogPersonDamage = "no person damage"; } // POLYGON NOT IMPLEMENTED else { _damageExtent.Log += $"ERROR: Feature type not implemented"; return(_damageExtent); } //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PROPERTY DAMAGE double _propertyDamage = _prA.Value * _mergedObjParam.Value; string _logPropertyDamage1 = $"PropertyDamage = prA * Value"; string _logPropertyDamage2 = $"PropertyDamage = {_prA.Value:F3} * {_mergedObjParam.Value:C}"; switch (_mergedObjParam.FeatureType) { case 0: //POINT BASED OBJECT (like towers) _damageExtent.Piece = 1; _logPropertyDamage1 += $" * Piece"; _logPropertyDamage2 += $" * 1"; break; case 1: //LINE BASED OBJECT (like streets) _damageExtent.Length = mapObj.line.Length; _propertyDamage *= mapObj.line.Length; _logPropertyDamage1 += $" * Length"; _logPropertyDamage2 += $" * {mapObj.line.Length:F3}"; break; default: _damageExtent.Log += $"ERROR: Infrastructure, FEATURETYPE = {_mergedObjParam.FeatureType} \n"; return(_damageExtent); } switch (_intensityDegree) { case 0: _propertyDamage *= _objectParamProcess.VulnerabilityHigh; _logPropertyDamage1 += $" * VulnerabilityHigh"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityHigh:F3}"; break; case 1: _propertyDamage *= _objectParamProcess.VulnerabilityMedium; _logPropertyDamage1 += $" * VulnerabilityMedium"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityMedium:F3}"; break; case 2: _propertyDamage *= _objectParamProcess.VulnerabilityLow; _logPropertyDamage1 += $" * VulnerabilityLow"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityLow:F3}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } _damageExtent.PropertyDamage = _propertyDamage; _damageExtent.LogPropertyDamage = _logPropertyDamage1 + ";\n" + _logPropertyDamage2; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } // AGRICULTURE else if (_mergedObjParam.ObjectClass.ID == 4) { //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PERSON DAMAGE _damageExtent.Deaths = 0; _damageExtent.LogDeaths = "no person damage"; _damageExtent.DeathProbability = 0; _damageExtent.LogDeathProbability = "no person damage"; _damageExtent.PersonDamage = 0; _damageExtent.LogPersonDamage = "no person damage"; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // PROPERTY DAMAGE double _propertyDamage = _prA.Value * _mergedObjParam.Value; //value per hectare!!! string _logPropertyDamage1 = $"PropertyDamage = prA * Value"; string _logPropertyDamage2 = $"PropertyDamage = {_prA.Value:F3} * {_mergedObjParam.Value:C}"; switch (_mergedObjParam.FeatureType) { case 2: //POLYGON BASED OBJECT _damageExtent.Area = mapObj.polygon.Area; _propertyDamage *= _damageExtent.Area / 10000.0; //in hectare! _logPropertyDamage1 += $" * Area / 10000"; _logPropertyDamage2 += $" * {(_damageExtent.Area / 10000.0):F3}"; break; default: _damageExtent.Log += $"ERROR: Agriculture, FEATURETYPE = {_mergedObjParam.FeatureType} \n"; return(_damageExtent); } switch (_intensityDegree) { case 0: _propertyDamage *= _objectParamProcess.VulnerabilityHigh; _logPropertyDamage1 += $" * VulnerabilityHigh"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityHigh:F3}"; break; case 1: _propertyDamage *= _objectParamProcess.VulnerabilityMedium; _logPropertyDamage1 += $" * VulnerabilityMedium"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityMedium:F3}"; break; case 2: _propertyDamage *= _objectParamProcess.VulnerabilityLow; _logPropertyDamage1 += $" * VulnerabilityLow"; _logPropertyDamage2 += $" * {_objectParamProcess.VulnerabilityLow:F3}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } _damageExtent.PropertyDamage = _propertyDamage; _damageExtent.LogPropertyDamage = _logPropertyDamage1 + ";\n" + _logPropertyDamage2; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } else { _damageExtent.Log += $"ERROR: OBJECT CLASS = {_mergedObjParam.ObjectClass.ID} \n"; return(_damageExtent); } //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // RESILIENCE FACTOR //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if (mapObj.ResilienceValues != null && mapObj.ResilienceValues.Any()) { Tuple <double, string> _resilience = MappedObjectController.computeResilienceFactor(mapObj.ResilienceValues.ToList(), intensity); _damageExtent.ResilienceFactor = _resilience.Item1; _damageExtent.LogResilienceFactor = _resilience.Item2; } else { _damageExtent.ResilienceFactor = 0; _damageExtent.LogResilienceFactor = "no resilience available"; } //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // INDIRECT DAMAGE //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< double _indirectDamage = 0; string _logIndirectDamage1 = ""; string _logIndirectDamage2 = ""; if (_mergedObjParam.ObjectClass.ID <= 3) //Value = 1$ { _indirectDamage = _prA.Value; _logIndirectDamage1 = $"IndirectDamage = prA"; _logIndirectDamage2 = $"IndirectDamage = {_prA.Value:F3}"; } else //Value according to DB { _indirectDamage = _prA.Value * _objectParamProcess.Value; _logIndirectDamage1 = $"IndirectDamage = prA * Value"; _logIndirectDamage2 = $"IndirectDamage = {_prA.Value:F3} * {_objectParamProcess.Value:C}"; } //if (_mergedObjParam.ObjectClass.ID != 3) //not available for infrastructure { switch (_intensityDegree) //0=high, 1=med, 2=low { case 0: _indirectDamage *= _objectParamProcess.DurationHigh; _logIndirectDamage1 += $" * DurationHigh"; _logIndirectDamage2 += $" * {_objectParamProcess.DurationHigh:F0}"; break; case 1: _indirectDamage *= _objectParamProcess.DurationMedium; _logIndirectDamage1 += $" * DurationMedium"; _logIndirectDamage2 += $" * {_objectParamProcess.DurationMedium:F0}"; break; case 2: _indirectDamage *= _objectParamProcess.DurationLow; _logIndirectDamage1 += $" * DurationLow"; _logIndirectDamage2 += $" * {_objectParamProcess.DurationLow:F0}"; break; default: throw new ArgumentOutOfRangeException(nameof(_intensityDegree), _intensityDegree, "out of range"); } //Building and Special Objects if (_mergedObjParam.ObjectClass.ID <= 2) { // staff property indicates if indirect damage is available if (_mergedObjParam.HasProperties.Where(m => m.Property == nameof(_mergedObjParam.Staff)).Any()) { _indirectDamage *= (double)_mergedObjParam.Staff; _logIndirectDamage1 += $" * Loss/day"; _logIndirectDamage2 += $" * {_mergedObjParam.Staff:F0}"; if (_damageExtent.Clipped) { _indirectDamage *= _damageExtent.Part; _logIndirectDamage1 += $" * PartOfLoss"; _logIndirectDamage2 += $" * {_damageExtent.Part:F2}"; } if (_mergedObjParam.Staff <= 0) { _damageExtent.Log += $"{ResModel.DE_Staff} = {_mergedObjParam.Staff} \n"; } } else // Buildings without indirect damage { _indirectDamage = 0; _logIndirectDamage1 = $"no indirect damage"; _logIndirectDamage2 = ""; } } //Agriculture else if (_mergedObjParam.ObjectClass.ID == 4) { _indirectDamage *= _damageExtent.Area / 10000.0; //in hectare! _logIndirectDamage1 += $" * Area / 10000"; _logIndirectDamage2 += $" * {_damageExtent.Area / 10000.0:F3}"; } //Infrastructure else if (_mergedObjParam.ObjectClass.ID == 3) { // duration indicates if indirect damage is available if ((_objectParamProcess.DurationHigh + _objectParamProcess.DurationMedium + _objectParamProcess.DurationLow) > 0) { _indirectDamage *= (double)_mergedObjParam.Staff; _logIndirectDamage1 += $" * Loss/day"; _logIndirectDamage2 += $" * {_mergedObjParam.Staff:F0}"; //TODO } else // Infrastructure without indirect damage { _indirectDamage = 0; _logIndirectDamage1 = $"no indirect damage"; _logIndirectDamage2 = ""; } } } //else //Infrastructure //{ // _indirectDamage = 0; // _logIndirectDamage1 = $"no indirect damage"; // _logIndirectDamage2 = ""; //} _damageExtent.IndirectDamage = _indirectDamage; _damageExtent.LogIndirectDamage = _logIndirectDamage1 + ";\n" + _logIndirectDamage2; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // if no errors reported if (String.IsNullOrWhiteSpace(_damageExtent.Log)) { _damageExtent.Log = "OK \n"; } return(_damageExtent); }
/// <summary> /// like getDamagePotentialCrossing, but with spatial query on db /// </summary> /// <param name="intensity"></param> /// <param name="projectId"></param> /// <returns></returns> //public List<MappedObject> getDamagePotentialCrossing2(Intensity intensity, int projectId) //{ // //Stopwatch _timer = new Stopwatch(); // //_timer.Start(); // //long ts1 = _timer.ElapsedMilliseconds; ////////////////////////////// // //_timer.Restart(); // IList<MappedObject> dpListFiltered = ActiveSession.QueryOver<MappedObject>() // .Where(m => m.Project.Id == projectId) // //.Where(m => m.Project.geometry.Intersects(m.geometry)) // .WhereSpatialRestrictionOn(m => m.geometry).Not.Within(intensity.geometry) // .WhereSpatialRestrictionOn(m => m.geometry).Intersects(intensity.geometry) // //.Where(m => !m.geometry.Within(intensity.geometry)) // //.Where(m => m.geometry.Intersects(intensity.geometry)) // .List<MappedObject>(); // //long ts2 = _timer.ElapsedMilliseconds; ////////////////////////////// // //_timer.Restart(); // List<MappedObject> clippedList = new List<MappedObject>(); // foreach (var damagePotential in dpListFiltered) // { // //damagePotential can't be outside of intensity // IGeometry clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.geometry); // //assign new geometry to new MappedObject // MappedObject clippedDamagePotential = new MappedObject() // { // FreeFillParameter = damagePotential.FreeFillParameter, // ID = damagePotential.ID, // Objectparameter = damagePotential.Objectparameter, // Project = damagePotential.Project, // geometry = clippedDamagePotentialGeometry, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // IsClipped = true, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Intensity = (Intensity)intensity.Clone(), //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // ResilienceValues = damagePotential.ResilienceValues, // }; // clippedList.Add(clippedDamagePotential); // } // //long ts3 = _timer.ElapsedMilliseconds; ////////////////////////////// // //_timer.Restart(); // //Logging.warn($" 222 {ts1:F2} - {ts2:F2} - {ts3:F3}"); // //_timer.Stop(); // return clippedList; //} /// <summary> /// DamagePotential crossing intensity.geometry /// </summary> /// <param name="intensity"></param> /// <param name="dpList"></param> /// <returns></returns> public List <MappedObject> getDamagePotentialCrossing(Intensity intensity, IList <MappedObject> dpList) { //Stopwatch _timer = new Stopwatch(); //_timer.Start(); // select "ID" //from "MappedObject" as mapObj //where ST_Intersects((select geometry from "Intensity" where "ID" = 117), mapObj.Geometry) AND //NOT ST_Contains((select geometry from "Intensity" where "ID" = 117), mapObj.Geometry); var project = DBManager.ActiveSession.Load <Project>(intensity.Project.Id); //long ts1 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); List <MappedObject> dpListFiltered = new List <MappedObject>(); dpListFiltered.AddRange(dpList .Where(m => m.point != null && !m.point.Within(intensity.geometry) && m.point.Intersects(intensity.geometry) ) .ToList() ); dpListFiltered.AddRange(dpList .Where(m => m.line != null && !m.line.Within(intensity.geometry) && m.line.Intersects(intensity.geometry) ) .ToList() ); dpListFiltered.AddRange(dpList .Where(m => m.polygon != null && !m.polygon.Within(intensity.geometry) && m.polygon.Intersects(intensity.geometry) ) .ToList() ); //long ts2 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); List <MappedObject> clippedList = new List <MappedObject>(); foreach (var damagePotential in dpListFiltered) { //damagePotential can't be outside of intensity IGeometry clippedDamagePotentialGeometry = null; if (damagePotential.point != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.point); } else if (damagePotential.line != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.line); } else if (damagePotential.polygon != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.polygon); } //#if DEBUG // //area difference due to intersection // double areaDifference = damagePotential.geometry.Area - clippedDamagePotentialGeometry.Area; // Debug.WriteLine($"DAMAGEPOTENTIAL CLIPPING: DamagePotential {damagePotential.ID}: area diff = {areaDifference:F2}, new area = {clippedDamagePotentialGeometry.Area:F2}, type: {damagePotential.geometry.GeometryType} -> {clippedDamagePotentialGeometry.GeometryType}"); //#endif //assign new geometry to new MappedObject MappedObject clippedDamagePotential = new MappedObject() { FreeFillParameter = damagePotential.FreeFillParameter, ID = damagePotential.ID, Objectparameter = damagePotential.Objectparameter, Project = damagePotential.Project, //geometry = clippedDamagePotentialGeometry, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< IsClipped = true, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Intensity = (Intensity)intensity.Clone(), //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ResilienceValues = damagePotential.ResilienceValues, }; if (damagePotential.point != null) { clippedDamagePotential.point = clippedDamagePotentialGeometry; } else if (damagePotential.line != null) { clippedDamagePotential.line = clippedDamagePotentialGeometry; } else if (damagePotential.polygon != null) { clippedDamagePotential.polygon = clippedDamagePotentialGeometry; } clippedList.Add(clippedDamagePotential); } //long ts3 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); //Logging.warn($" 111 {ts1:F2} - {ts2:F2} - {ts3:F3}"); //_timer.Stop(); return(clippedList); }
/// <summary> /// like getDamagePotentialsWithin, but with spatial query on db /// </summary> /// <param name="intensity"></param> /// <param name="projectId"></param> /// <returns></returns> public List <MappedObject> getDamagePotentialsWithin2(Intensity intensity, int projectId) { //Stopwatch _timer = new Stopwatch(); //_timer.Start(); //long ts1 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); IList <MappedObject> dpListFiltered = ActiveSession.QueryOver <MappedObject>() .Where(m => m.Project.Id == projectId) .WhereSpatialRestrictionOn(m => m.point).Within(intensity.geometry) .WhereSpatialRestrictionOn(m => m.line).Within(intensity.geometry) .WhereSpatialRestrictionOn(m => m.polygon).Within(intensity.geometry) .List <MappedObject>(); //long ts2 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); List <MappedObject> clippedList = new List <MappedObject>(); foreach (var damagePotential in dpListFiltered) { //damagePotential can't be outside of intensity IGeometry clippedDamagePotentialGeometry = null; if (damagePotential.point != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.point); } else if (damagePotential.line != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.line); } else if (damagePotential.polygon != null) { clippedDamagePotentialGeometry = intensity.geometry.Intersection(damagePotential.point); } //assign new geometry to new MappedObject MappedObject clippedDamagePotential = new MappedObject() { FreeFillParameter = damagePotential.FreeFillParameter, ID = damagePotential.ID, Objectparameter = damagePotential.Objectparameter, Project = damagePotential.Project, //geometry = clippedDamagePotentialGeometry, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< IsClipped = true, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Intensity = (Intensity)intensity.Clone(), //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ResilienceValues = damagePotential.ResilienceValues, }; if (damagePotential.point != null) { clippedDamagePotential.point = clippedDamagePotentialGeometry; } else if (damagePotential.line != null) { clippedDamagePotential.line = clippedDamagePotentialGeometry; } else if (damagePotential.polygon != null) { clippedDamagePotential.polygon = clippedDamagePotentialGeometry; } clippedList.Add(clippedDamagePotential); } //long ts3 = _timer.ElapsedMilliseconds; ////////////////////////////// //_timer.Restart(); //Logging.warn($" 222 {ts1:F2} - {ts2:F2} - {ts3:F3}"); //_timer.Stop(); return(clippedList); }