public static List <EarthquakeObj> EarthquakeTrans(object earthquakeEvent, EarthquakeDataSource dataSource,
                                                           string startTime, string endTime)
        {
            EarthquakeObjConverter.eqList.Clear();
            EarthquakeObjConverter.startTime = startTime;
            EarthquakeObjConverter.endTime   = endTime;

            if (earthquakeEvent == null)
            {
                return(null);
            }

            switch (dataSource)
            {
            case EarthquakeDataSource.PALERT:
                List <Palert> palertEventList = JsonConvert.DeserializeObject <List <Palert> >((string)earthquakeEvent);
                foreach (Palert palertEvent in palertEventList)
                {
                    EarthquakeObj eq = palertTrans(palertEvent);
                    eqList.Add(eq);
                }
                return(eqList);

            case EarthquakeDataSource.CWB:
                cwbTrans((string)earthquakeEvent);
                return(eqList);

            case EarthquakeDataSource.CKAN:
                JObject ckanList = JObject.Parse((string)earthquakeEvent);
                ckanTrans(ckanList);
                return(eqList);

            case EarthquakeDataSource.TESIS:
                tesisTrans((string)earthquakeEvent);
                return(eqList);

            default:
                break;
            }

            // DEBUG
            return(null);
        }
        //
        // Transform palert object to earthquake object
        //
        private static EarthquakeObj palertTrans(Palert palertEvent)
        {
            // The time string format of palert : YYYYMMDDhhmmss
            // We only need YYYYMMDDhhmm
            // The time format in P-alert is UTC, we need to convert it into GMT+8
            string   timeString_   = palertEvent.Timestring;
            DateTime timeString_dt = new DateTime(int.Parse(timeString_.Substring(0, 4)), int.Parse(timeString_.Substring(4, 2)),
                                                  int.Parse(timeString_.Substring(6, 2)), int.Parse(timeString_.Substring(8, 2)),
                                                  int.Parse(timeString_.Substring(10, 2)), int.Parse(timeString_.Substring(12, 2)));

            // UTC time + 8 hours = GMT+8 (Time zone of Taiwan)
            timeString_dt = timeString_dt.AddHours(8);

            string timeString = timeString_dt.ToString("yyyyMMddHHmm");

            string lat = palertEvent.Lat;
            string lng = palertEvent.Lng;

            // The unit of depth of palert event is KM too.
            string depth     = palertEvent.Depth;
            string magnitude = palertEvent.Magnitude;
            EarthquakeDataSource dataSource = EarthquakeDataSource.PALERT;

            // The format of the link of the p-alert data : Domain + Key
            //      Domain  :   http://palert.earth.sinica.edu.tw/db/index1.clt2.php?time=
            //      Key     :   YYYYMMDDhhmmss
            //      And the Key is equal to palertEvent.Timestring

            string Domain = "http://palert.earth.sinica.edu.tw/db/index1.clt2.php?time=";
            string Key    = palertEvent.Timestring;

            string dataLink = Domain + Key;

            EarthquakeObj eq = new EarthquakeObj(timeString, lat, lng, depth, magnitude, dataSource, dataLink);

            return(eq);
        }
Example #3
0
 public EarthquakeObj(string timeString, string lat, string lng, string depth, string magnitude, EarthquakeDataSource dataSource, string dataLink)
 {
     this.timeString = timeString;
     this.lat        = lat;
     this.lng        = lng;
     this.depth      = depth;
     this.magnitude  = magnitude;
     this.dataSource = dataSource;
     this.dataLink   = dataLink;
 }
Example #4
0
        public static string GetEarhquakeRequestString(EarthquakeDataSource datasource, string startdate, string enddate, string min_magnitude, string max_magnitude)
        {
            string requestString = "";
            string prefix;
            string latLng;
            string time;
            string magnitude;

            switch (datasource)
            {
            case EarthquakeDataSource.CKAN:

                //
                // ****************************
                // *                          *
                // *   CKAN                   *
                // *                          *
                // ****************************
                //
                //  The format of the link :
                //
                //      Domain                  :  ConstCkan.CkanAPIPrefix
                //
                //      Organization            :  organization_show?id=earthquake&
                //
                //      Need to show dataset    :  include_datasets =true
                //
                //      The response data type is JSON.
                //

                prefix        = ConstCkan.CkanAPIPrefix + "organization_show?id=earthquake&include_datasets=true";
                latLng        = "";
                time          = startdate + "&" + enddate;
                magnitude     = "";
                requestString = prefix;
                break;

            case EarthquakeDataSource.CWB:

                //
                // ****************************
                // *                          *
                // *   CWB                    *
                // *                          *
                // ****************************
                //
                //  The format of the link : Domain + Time
                //
                //      Prefix      :   http://scweb.cwb.gov.tw/GraphicContent.aspx?ItemId=20&
                //      Time        :   Date=201603
                //                          (All the earthquakes in 2016/03)
                //
                //  The response data is HTML text.
                //  The data of the earthqukes are in each row except the first row of the table datalist4
                //
                prefix = "http://scweb.cwb.gov.tw/GraphicContent.aspx?ItemId=20&Date=";
                DateTime date_i = DateTime.Parse(startdate);
                requestString = prefix + date_i.ToString("yyyyMM");
                break;

            case EarthquakeDataSource.NOAA:
                break;

            case EarthquakeDataSource.PALERT:

                //
                // ****************************
                // *                          *
                // *   P-ALERT                *
                // *                          *
                // ****************************
                //
                //  The format of the link : Domain + LatLng + Time + Intensity
                //  * The "Intensity" of P-ALERT actually means "Magnitude".
                //
                //      Prefix      :   http://palert.earth.sinica.edu.tw/db/querydb.php?
                //      LatLng      :   lat%5B%5D=21&lat%5B%5D=26&lng%5B%5D=119&lng%5B%5D=123&
                //                          (from latitude 21~26, longitude 119~123)
                //      Time        :   time%5B%5D=2016-03-01&time%5B%5D=2016-03-31&
                //                          (from 2016/03/01 to 2016/03/31)
                //      Intensity   :   intensity%5B%5D=1&intensity%5B%5D=7
                //                          (from intensity 1 to intensity 7)
                //
                //      The response data type is JSON.
                //
                //      If there is no earthquake data, P-ALERT will response "false".
                //

                prefix    = "http://palert.earth.sinica.edu.tw/db/querydb.php?";
                latLng    = "lat%5B%5D=21&lat%5B%5D=26&lng%5B%5D=119&lng%5B%5D=123&";
                time      = "time%5B%5D=" + startdate + "&time%5B%5D=" + enddate + "&";
                magnitude = "intensity%5B%5D=" + min_magnitude + "&intensity%5B%5D=" + max_magnitude;

                requestString = prefix + latLng + time + magnitude;
                break;

            case EarthquakeDataSource.TESIS:
                //
                // ****************************
                // *                          *
                // *   TESIS                  *
                // *                          *
                // ****************************
                //
                //
                //      Prefix      :   http://tesis.earth.sinica.edu.tw/common/php/getid.php?
                //      Time        :   start=2016-07-01&end=2016-08-22
                //                          (from 2016/07/01 to 2016/08/22)
                //
                //      The response data type is string.
                //      Ex : ["992","993","994","995","996","997"]
                //      This is the ID of the earthquake event.
                //      We need another API to query each of it.
                //      This part is implemented in EarthquakeObjConverter.
                //
                //

                prefix = "http://tesis.earth.sinica.edu.tw/common/php/getid.php?";
                time   = "start=" + startdate + "&end=" + enddate;

                requestString = prefix + time;
                break;
            }

            return(requestString);
        }