Esempio n. 1
0
 public EdiDataElement(MapDataElement definition, string val)
 {
     if (definition != null)
     {
         Type = definition.GetType().Name;
     }
     Val = val;
 }
        private void CalculateSeismicValues()
        {
            decimal LatitideD  = (decimal)Latitude;
            decimal LongitudeD = (decimal)Longitude;

            SeismicGroundMotionMapDataReader reader = new SeismicGroundMotionMapDataReader();
            MapDataElement dp    = reader.ReadData(LatitideD, LongitudeD);
            decimal        SSVal = dp.GetValue(GroundMotionParameterType.SS, true, 1.05m, 6.0m);
            decimal        S1Val = dp.GetValue(GroundMotionParameterType.S1, true, 1.05m, 6.0m);
            decimal        TLVal = dp.GetValue(GroundMotionParameterType.TL, true, 1.05m, 6.0m);

            SS = (double)Math.Round(SSVal / 100.0m, 3, MidpointRounding.AwayFromZero);
            S1 = (double)Math.Round(S1Val / 100.0m, 3, MidpointRounding.AwayFromZero);
            TL = (double)Math.Round(TLVal, 3, MidpointRounding.AwayFromZero);

            IsDirty = false;
        }
Esempio n. 3
0
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapDataElement elDef = null;
                if (i < segDef.Content.Count)
                {
                    elDef = segDef.Content[i];
                }

                if (elDef == null)
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Unexpected element '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                EdiDataElement el = new EdiDataElement(elDef, val);
                if (elDef != null && !el.IsValid(elDef))
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Invalid value '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                i++;
                seg.Content.Add(el);
            }
            return(seg);
        }
Esempio n. 4
0
        protected MapDataElement ReadData(decimal Latitude, decimal Longitude, ReadPointValueDelegate ReadPointValue, decimal DataCoordinateStep)
        {
            this.readPointValue = ReadPointValue;
            //find the lower-left cornerpoint of a quad 
            decimal LatLow = Latitude.FloorWithSignificance(DataCoordinateStep);
            decimal LongLow = Longitude.FloorWithSignificance(DataCoordinateStep);

            //SeismicGroundMotionDataPoint pointFound = this.FindPointInDataFileRecursive(LatLow, LongLow, DataStartIndex+1, DataEndIndex);
            IMultipleValueDataPoint2D foundPoint = this.FindPointInDataFileRecursive(LatLow, LongLow, DataStartIndex + 1, DataEndIndex);
            MapDataElement de = new MapDataElement(Latitude, Longitude);
            //add neigboring points for interpolation

            #region Neigbouring points for interpolation
            #region Special cases
            //Corner points
            if (foundPoint.DataArrayIndex == DataStartIndex + 1 || foundPoint.DataArrayIndex == NumberOfColumns + 1 || foundPoint.DataArrayIndex == DataEndIndex || foundPoint.DataArrayIndex == DataEndIndex - NumberOfColumns + 1)
            {
                de.LowerLeftPoint = foundPoint;
                de.LowerRightPoint = foundPoint.Clone();
                de.LowerRightPoint.Longitude = de.LowerRightPoint.Longitude + CoordinateIncrement;
                de.UpperLeftPoint = foundPoint.Clone();
                de.UpperLeftPoint.Latitude = de.UpperLeftPoint.Latitude + CoordinateIncrement;
                de.UpperRightPoint = foundPoint.Clone();
                de.UpperRightPoint.Latitude = de.UpperRightPoint.Latitude + CoordinateIncrement;
                de.UpperRightPoint.Longitude = de.UpperRightPoint.Longitude + CoordinateIncrement;
                return de;
            }
            //bottom row- do nothing 
            //top row 
            if (foundPoint.DataArrayIndex < (NumberOfColumns + 1))
            {
                de.LowerLeftPoint = foundPoint;
                IMultipleValueDataPoint2D pNextLongitude = readPointValue(foundPoint.DataArrayIndex + 1);
                de.LowerRightPoint = pNextLongitude;
                IMultipleValueDataPoint2D NextLatitudePoint = foundPoint.Clone();
                NextLatitudePoint.Latitude = foundPoint.Latitude + CoordinateIncrement;
                de.UpperLeftPoint = NextLatitudePoint;
                IMultipleValueDataPoint2D NextLatitudeAndLongitudePoint = pNextLongitude.Clone();
                NextLatitudeAndLongitudePoint.Latitude = foundPoint.Latitude + CoordinateIncrement;
                NextLatitudeAndLongitudePoint.Longitude = foundPoint.Longitude + CoordinateIncrement;
                de.UpperRightPoint = NextLatitudeAndLongitudePoint;
                return de;
            }
            //first column -do nothing

            //last column
            if ((foundPoint.DataArrayIndex - DataStartIndex) % (NumberOfColumns) == 0 && foundPoint.DataArrayIndex > 2)
            {
                de.LowerLeftPoint = foundPoint;
                IMultipleValueDataPoint2D pNextLongitude = foundPoint.Clone();
                pNextLongitude.Longitude = foundPoint.Longitude + CoordinateIncrement;
                de.LowerRightPoint = pNextLongitude;
                IMultipleValueDataPoint2D pNextLatitude = readPointValue(foundPoint.DataArrayIndex - NumberOfColumns);
                de.UpperLeftPoint = pNextLatitude;
                IMultipleValueDataPoint2D NextLatitudeAndLongitudePoint = pNextLatitude.Clone();
                NextLatitudeAndLongitudePoint.Latitude = pNextLatitude.Latitude;
                NextLatitudeAndLongitudePoint.Longitude = pNextLongitude.Longitude;
                de.UpperRightPoint = NextLatitudeAndLongitudePoint;
                return de;
            }

            #endregion
            #region Typical case
                    de.LowerLeftPoint = foundPoint;
                    de.LowerRightPoint = readPointValue(foundPoint.DataArrayIndex + 1); //NextLongitudePoint;
                    de.UpperLeftPoint = readPointValue(foundPoint.DataArrayIndex - NumberOfColumns);  //NextLatitudePoint;
                    de.UpperRightPoint = readPointValue(foundPoint.DataArrayIndex - NumberOfColumns + 1); //NextLatitudeAndLongitudePoint 
            
            #endregion
            #endregion

            //Interpolation is done by MapDataElement


                        //if (pointFound!=null)
                        //{

                        //    decimal SS = GetInterpolatedValue(pointFound, Latitude, Longitude, GroundMotionParameterType.SS);
                        //    decimal S1 = GetInterpolatedValue(pointFound, Latitude, Longitude, GroundMotionParameterType.S1);

                        //    return new SeismicGroundMotionDataPoint(Latitude, Longitude, SS, S1);
                        //}

                        //return new SeismicGroundMotionDataPoint();
            return de;
        }
Esempio n. 5
0
        public static bool IsValid(this EdiDataElement el, MapDataElement definition)
        {
            //required
            if (definition.ReqDes == RequirementDesignator.Mandatory && string.IsNullOrEmpty(el.Val)) //whitespaces allowed
            {
                return(false);
            }

            //Min max len
            if (!string.IsNullOrEmpty(el.Val) && (el.Val.Length < definition.MinLength || el.Val.Length > definition.MaxLength))
            {
                return(false);
            }

            DateTime dummyDt;

            switch (definition.DataType)
            {
            case DataType.AN:
                return(true);

            case DataType.ID:
                return(definition.AllowedValues.IndexOf(el.Val) >= 0 ||
                       (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

            case DataType.N0:
            case DataType.N1:
            case DataType.N2:
            case DataType.N4:
            case DataType.N6:
                int dummyInt;
                return(int.TryParse(el.Val, out dummyInt) ||
                       (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

            case DataType.R:
            case DataType.R2:
            case DataType.R4:
            case DataType.R5:
            case DataType.R6:
            case DataType.R7:
            case DataType.R8:
                decimal dummyDec;
                return(decimal.TryParse(el.Val, out dummyDec) ||
                       (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

            case DataType.DT:
                switch (definition.MaxLength)
                {
                case 6:
                    return(DateTime.TryParseExact(el.Val, "yyMMdd", CultureInfo.InvariantCulture,
                                                  DateTimeStyles.None, out dummyDt) ||
                           (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

                case 8:
                    return(DateTime.TryParseExact(el.Val, "yyyyMMdd", CultureInfo.InvariantCulture,
                                                  DateTimeStyles.None, out dummyDt) ||
                           (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

                default:
                    throw new NotSupportedException($"Date validation with length {definition.MaxLength} is not implemented. {el.Type}");
                }

            case DataType.TM:
                return(DateTime.TryParseExact(el.Val, "hhmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dummyDt) ||
                       (definition.ReqDes == RequirementDesignator.Optional && string.IsNullOrEmpty(el.Val)));

            default:
                throw new NotSupportedException($"{definition.DataType} validation is not implemented. {el.Type}");
            }
        }