Esempio n. 1
0
        public string ToJSONArray()
        {
            JSONArraySRTM3         a        = new JSONArraySRTM3(this);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            settings.FloatFormatHandling  = FloatFormatHandling.String;
            settings.Formatting           = Formatting.Indented;
            string json = JsonConvert.SerializeObject(a, settings);

            return(json);
        }
Esempio n. 2
0
 public DataTable FromJSONArray(string filename)
 {
     if (!File.Exists(filename))
     {
         return(new DataTableSRTM3());
     }
     try
     {
         using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
         {
             string         json = sr.ReadToEnd();
             JSONArraySRTM3 a    = JsonConvert.DeserializeObject <JSONArraySRTM3>(json);
             // check version
             if (String.Compare(Version, a.version) != 0)
             {
                 // do upgrade/downgrade stuff here
             }
             else
             {
                 foreach (List <string> l in a.tiles)
                 {
                     string          fileindex = l[0];
                     string          FileName  = l[1];
                     double          minlat    = System.Convert.ToDouble(l[2], CultureInfo.InvariantCulture);
                     double          maxlat    = System.Convert.ToDouble(l[3], CultureInfo.InvariantCulture);
                     double          minlon    = System.Convert.ToDouble(l[4], CultureInfo.InvariantCulture);
                     double          maxlon    = System.Convert.ToDouble(l[5], CultureInfo.InvariantCulture);
                     int             minelv    = System.Convert.ToInt32(l[6]);
                     int             maxelv    = System.Convert.ToInt32(l[7]);
                     int             rows      = System.Convert.ToInt32(l[8]);
                     int             columns   = System.Convert.ToInt32(l[9]);
                     int             version   = System.Convert.ToInt32(l[10]);
                     string          url       = l[11];
                     SRTM3TILESTATUS status    = SRTM3TILESTATUS.UNDEFINED;
                     try
                     {
                         status = (SRTM3TILESTATUS)Enum.Parse(typeof(SRTM3TILESTATUS), l[12]);
                     }
                     catch
                     {
                     }
                     bool     local       = System.Convert.ToBoolean(l[13]);
                     DateTime lastupdated = DateTime.UtcNow;
                     try
                     {
                         lastupdated = System.Convert.ToDateTime(l[4]);
                     }
                     catch
                     {
                     }
                     Update(new SRTM3TileDesignator(fileindex, filename, minlat, maxlat, minlon, maxlon, minelv, maxelv, rows, columns, version, url, status, local, lastupdated));
                 }
             }
         }
         return(ToTable());
     }
     catch (Exception ex)
     {
     }
     return(new DataTableSRTM3());
 }