Exemple #1
0
        /// <summary>
        /// get sub image by longitude latitude range
        /// </summary>
        /// <param name="lonlatbox"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public Image GetSubImage(Envelope lonlatbox, int width, int height)
        {
            if (this.bigImg == null || this.imgRange == null || !this.imgRange.Contains(lonlatbox))
            {
                MessageBox.Show("GetSubImage wrong,");
                return(null);
            }

            PixelBound box = new PixelBound();

            if (DBTranslateFactory.LonLatBound2PixelBound(this.googleLevel, lonlatbox, ref box))
            {
                //double boxwidth = Math.Abs(this.PixelBox.maxPX - this.PixelBox.minPX);
                //double imgwidth = this.bigImg.Width;
                //Rectangle _SourceRect = new Rectangle((int)((double)(box.minPX - this.PixelBox.minPX) / boxwidth * imgwidth), (int)((double)(box.minPY - this.PixelBox.minPY) / boxwidth * imgwidth), (int)((double)(box.maxPX - box.minPX) / boxwidth * imgwidth), (int)((double)(box.maxPY - box.minPY) / boxwidth * imgwidth));
                Rectangle _SourceRect   = new Rectangle(box.minPX - this.PixelBox.minPX, box.minPY - this.PixelBox.minPY, box.maxPX - box.minPX, box.maxPY - box.minPY);
                Rectangle _TargetRect   = new Rectangle(0, 0, width, height);
                Bitmap    _CanvasBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                System.Drawing.Graphics _CanvasGraphics = System.Drawing.Graphics.FromImage(_CanvasBitmap);
                _CanvasGraphics.Clear(Color.Yellow);
                _CanvasGraphics.CompositingQuality = CompositingQuality.HighQuality;
                _CanvasGraphics.SmoothingMode      = SmoothingMode.AntiAlias;
                _CanvasGraphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                _CanvasGraphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                _CanvasGraphics.DrawImage(this.bigImg, _TargetRect, _SourceRect, GraphicsUnit.Pixel);

                _CanvasGraphics.Dispose();
                _CanvasGraphics = null;

                return(_CanvasBitmap);
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// get the google big image and extracted kq tile image by level-X-Y
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void start_lxy_Click(object sender, RoutedEventArgs e)
        {
            int level = 0, x = 0, y = 0;

            if (!(int.TryParse(Signal_L.Text, out level)) || !(int.TryParse(Signal_X.Text, out x)) || !(int.TryParse(Signal_Y.Text, out y)))
            {
                StatusLable.Content = "Try to enter anther valuable L-X-Y.";
                return;
            }
            string func = this.CBOX.SelectionBoxItem as string;

            if (func == "MongoDB部分转KQDB")
            {
                if (level < 0 || level > 15)
                {
                    StatusLable.Content = "Try to enter anther valuable L.";
                    return;
                }

                int maxX = 5 * (int)Math.Pow(2.0, level);
                int maxY = 10 * (int)Math.Pow(2.0, level);

                if (x >= maxX || y >= maxY || x < 0 || y < 0)
                {
                    StatusLable.Content = "Try to enter anther valuable X-Y.";
                    return;
                }
                Envelope range = new Envelope();

                DBTranslateFactory.GetLonLatBoundByRowCol(level, x, y, ref range);
                BigImage bigimage = await DBTranslateFactory.GetBigImageFromGoogleTile("", level + 5, range.MinX, range.MinY, range.MaxX, range.MaxY);

                byte[] bigimg = null;
                if (bigimage != null && bigimage.BigImg != null)
                {
                    var _TargetMemory = new MemoryStream();
                    bigimage.BigImg.Save(_TargetMemory, ImageFormat.Jpeg);
                    bigimage.BigImg.Dispose();
                    bigimage.BigImg = null;
                    bigimg          = _TargetMemory.GetBuffer();
                }
                else
                {
                    StatusLable.Content = "Can not find tile data in google database.";
                    return;
                }

                if (!(bigimg == null))
                {
                    BitmapImage imgSource = new BitmapImage();
                    imgSource.BeginInit();
                    imgSource.StreamSource = new MemoryStream(bigimg);
                    imgSource.EndInit();
                    bigiamgebox.Source = imgSource;
                }

                GoogleLbel.Visibility = Visibility.Visible;

                byte[] image = await DBTranslateFactory.GetKQTileImageBuffer("", level, x, y);

                if (!(image == null))
                {
                    BitmapImage imgSource = new BitmapImage();
                    imgSource.BeginInit();
                    imgSource.StreamSource = new MemoryStream(image);
                    imgSource.EndInit();
                    imagebox.Source = imgSource;
                }
                else
                {
                    StatusLable.Content = "Convert big image to KongQing tile image failed.";
                }
            }

            if (func == "MongoDB提取图片文件")
            {
                string key = string.Format("{0}-{1}-{2}", level, x, y);
                if (DBTranslateFactory.DBReaderHelper != null)
                {
                    try
                    {
                        byte[] buffer = await DBTranslateFactory.DBReaderHelper.GetTiled(key);

                        if (buffer != null)
                        {
                            BitmapImage imgSource = new BitmapImage();
                            imgSource.BeginInit();
                            imgSource.StreamSource = new MemoryStream(buffer);
                            imgSource.EndInit();
                            imagebox.Source = imgSource;
                        }
                        else
                        {
                            StatusLable.Content = "Can not find tile data in google database";
                        }
                    }
                    catch (Exception ex)
                    {
                        StatusLable.Content = ex.Message;
                    }
                }
            }


            imagebox.Visibility    = Visibility.Visible;
            bigiamgebox.Visibility = Visibility.Visible;

            ProgressInfo.Visibility  = Visibility.Hidden;
            ProgressLabel.Visibility = Visibility.Hidden;

            KQLable.Visibility = Visibility.Visible;
        }
Exemple #3
0
        /// <summary>
        /// according to the longitude latitude box and level range insert tile data to kq database file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void start_Click(object sender, RoutedEventArgs e)
        {
            if (start.Content.ToString() == "Start" || start.Content.ToString() == "Config")
            {
                if (start.Content.ToString() == "Config")
                {
                    string configPath = "";
                    System.Windows.Forms.OpenFileDialog odlg = new OpenFileDialog();
                    odlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
                    odlg.Filter           = "config files (*.ini)|*.ini";
                    if (odlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        configPath = odlg.FileName;
                    }
                    else
                    {
                        return;
                    }

                    tConfig = new TransformConfigion();

                    try
                    {
                        SharpConfig.Configuration configi = SharpConfig.Configuration.LoadFromFile(configPath);
                        if (configi != null && configi.Contains("Record") && configi["Record"].SettingCount == 13)
                        {
                            tConfig = configi["Record"].CreateObject <TransformConfigion>();
                            if (tConfig != null)
                            {
                                SUM_MinX.Text = tConfig.minLon.ToString();
                                SUM_MinY.Text = tConfig.minLat.ToString();
                                SUM_MaxX.Text = tConfig.maxLon.ToString();
                                SUM_MaxY.Text = tConfig.maxLat.ToString();

                                StartLevel.Text = tConfig.sLevel.ToString();
                                EndLevel.Text   = tConfig.eLevel.ToString();
                                foreach (ComboBoxItem s in this.CBOX.Items)
                                {
                                    if (tConfig.OperateFunction == s.Content as string)
                                    {
                                        this.CBOX.SelectedItem = s;
                                    }
                                }

                                List <string> item = new List <string>();
                                item.Add(string.Format("Min Longitude :{0}", tConfig.minLon));
                                item.Add(string.Format("Max Longitude :{0}", tConfig.maxLon));
                                item.Add(string.Format("Min Latitude :{0}", tConfig.minLat));
                                item.Add(string.Format("Max Latitude :{0}", tConfig.maxLat));
                                item.Add(string.Format("Start Level :{0}", tConfig.sLevel));
                                item.Add(string.Format("End   Level :{0}", tConfig.eLevel));
                                item.Add(string.Format("Function :{0}", tConfig.OperateFunction));
                                item.Add(string.Format("Start Time :{0}", tConfig.StartTime));
                                item.Add(string.Format("Last  Time :{0}", tConfig.LastTime));
                                item.Add(string.Format("Tiles Amount :{0}", tConfig.TotalTilesNum));
                                item.Add(string.Format("Tiles Finished :{0}", tConfig.NowTileNum));
                                item.Add(string.Format("Tiles Succeed :{0}", tConfig.SuccessNum));
                                item.Add(string.Format("Save Path :{0}", tConfig.SavePath));
                                listBoxConfig.ItemsSource = item;

                                DBTranslateFactory.configSucceed  = tConfig.SuccessNum;
                                DBTranslateFactory.configFinished = tConfig.NowTileNum;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }

                double minX = 0, minY = 0, maxX = 0, maxY = 0;
                int    sLevel = 0, eLevel = 0, threatNum = 0;

                string func = this.CBOX.SelectionBoxItem as string;

                if (!(double.TryParse(SUM_MinX.Text, out minX)) || !(double.TryParse(SUM_MinY.Text, out minY)) || !(double.TryParse(SUM_MaxX.Text, out maxX)) || !(double.TryParse(SUM_MaxY.Text, out maxY)))
                {
                    StatusLable.Content = "Try to enter anther valuable longitude and latitude range.";
                    return;
                }
                if (!(int.TryParse(StartLevel.Text, out sLevel)) || !(int.TryParse(EndLevel.Text, out eLevel)) || !(int.TryParse(ThreatNum.Text, out threatNum)))
                {
                    StatusLable.Content = "Try to enter anther valuable StartLevel and EndLevel , Threat Number.";
                    return;
                }

                if (minX > maxX || minY > maxY || minX < -180 || minY < -90 || maxX > 180 || maxY > 90)
                {
                    StatusLable.Content = "Try to enter anther valuable longitude and latitude range.";
                    return;
                }

                if (sLevel < 0 || sLevel > 21 || eLevel < 0 || eLevel > 21 || sLevel > eLevel || threatNum < 1 || threatNum > 25)
                {
                    StatusLable.Content = "Try to enter anther valuable StartLevel and EndLevel.";
                    return;
                }

                imagebox.Visibility    = Visibility.Hidden;
                bigiamgebox.Visibility = Visibility.Hidden;
                KQLable.Visibility     = Visibility.Hidden;
                GoogleLbel.Visibility  = Visibility.Hidden;

                ProgressInfo.Visibility = Visibility.Visible;

                //start.IsEnabled = false;

                tConfig = new TransformConfigion();

                tConfig.sLevel          = sLevel;
                tConfig.eLevel          = eLevel;
                tConfig.minLat          = minY;
                tConfig.minLon          = minX;
                tConfig.maxLat          = maxY;
                tConfig.maxLon          = maxX;
                tConfig.TotalTilesNum   = 0;
                tConfig.NowTileNum      = 0;
                tConfig.SuccessNum      = 0;
                tConfig.OperateFunction = func;
                tConfig.StartTime       = DateTime.Now.ToString();
                tConfig.LastTime        = DateTime.Now.ToString();
                tConfig.SavePath        = DBTranslateFactory.kqpath;

                tileAmount   = 0;
                tileFinished = 0;
                tileSucceed  = 0;
                lastFinished = 0;

                StatusLable.Content = "Transformation is beginning.";

                bool result = false;
                if (func == "MongoDB To KQDB")
                {
                    if (DBTranslateFactory.InsertOperationByMultiThreading(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }

                if (func == "MongoDB To File")
                {
                    if (DBTranslateFactory.CreatGoogleFileByMultiThreading(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }

                if (func == "Get Partial MongoDB")
                {
                    if (DBTranslateFactory.CreatPartialMongoDB(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }
                //DBTranslateFactory.InsertKQImageByLonLatRange(6, 115, 25, 110, 20);
                if (!result)
                {
                    return;
                }
                timeCount          = new System.Windows.Forms.Timer();
                timeCount.Tick    += timeCount_Tick;
                timeCount.Enabled  = true;
                timeCount.Interval = 1000;
                timeCount.Start();

                start.Content = "Pause";
                if (config != null && config.Contains("Record") && config["Record"].SettingCount == 13)
                {
                    config["Record"]["NowTileNum"].SetValue <ulong>(tConfig.NowTileNum);
                    config["Record"]["SuccessNum"].SetValue <ulong>(tConfig.SuccessNum);
                    config["Record"]["minLon"].SetValue <double>(tConfig.minLon);
                    config["Record"]["minLat"].SetValue <double>(tConfig.minLat);
                    config["Record"]["maxLon"].SetValue <double>(tConfig.maxLon);
                    config["Record"]["maxLat"].SetValue <double>(tConfig.maxLat);
                    config["Record"]["sLevel"].SetValue <int>(tConfig.sLevel);
                    config["Record"]["eLevel"].SetValue <int>(tConfig.eLevel);
                    config["Record"]["OperateFunction"].SetValue <string>(tConfig.OperateFunction);
                    config["Record"]["StartTime"].SetValue <string>(tConfig.StartTime);
                    config["Record"]["LastTime"].SetValue <string>(tConfig.LastTime);
                    config["Record"]["TotalTilesNum"].SetValue <ulong>(tConfig.TotalTilesNum);
                    config["Record"]["SavePath"].SetValue <string>(tConfig.SavePath);
                    config.Save("Config.ini");
                }

                return;
            }
            else if (start.Content.ToString() == "Pause")
            {
                DBTranslateFactory.Pause = true;
                timeCount.Stop();
                start.Content = "Continue";
                return;
            }

            else if (start.Content.ToString() == "Continue")
            {
                DBTranslateFactory.Pause = false;
                timeCount.Start();
                start.Content = "Pause";
                return;
            }
        }