Exemplo n.º 1
0
        public ActionResult GetGeoDB(long layoutId)
        {
            var    connectionCredentials = new bv.common.Configuration.ConnectionCredentials();
            string connection            = connectionCredentials.ConnectionString;

            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(View("AvrServiceError", (object)access.ErrorMessage));
            }

            return(ObjectStorage.Using <AvrPivotViewModel, ActionResult>(viewModel =>
            {
                ViewBag.Title = string.Format(Translator.GetMessageString("webMapTitle"), viewModel.ViewHeader.LayoutName);

                // have we anything selected in combo admin unit?
                if (!string.IsNullOrEmpty(viewModel.ViewHeader.MapAdminUnitViewColumn))
                {
                    DataSet dataSet;
                    string error = ChartMapHelper.TryToPrepareMapData(viewModel, out dataSet);
                    if (error.Length > 0)
                    {
                        return View("AvrServiceError", (object)error);
                    }

                    string path = Path.Combine(Server.MapPath("~/App_Data/ExportQueryFiles"), DateTime.Now.Ticks.ToString());
                    System.IO.Directory.CreateDirectory(path); path = path + '\\';
                    string SrvPath = Server.MapPath("");
                    eidss.gis.common.MapUtils.ExportToFGDB(dataSet, connection, path);

                    string filename = "Export.fgdb.zip";
                    string filepath = path + filename;
                    byte[] filedata = System.IO.File.ReadAllBytes(filepath);

                    var cd = new System.Net.Mime.ContentDisposition
                    {
                        FileName = filename,
                        Inline = true,
                    };

                    Response.AppendHeader("Content-Disposition", cd.ToString());

                    return File(filedata, "application/force-download");
                }
                return View();
            }, Session.SessionID, layoutId, ViewLayoutController.StoragePrefix));
        }
Exemplo n.º 2
0
        public ActionResult Index(long layoutId)
        {
            var    connectionCredentials = new bv.common.Configuration.ConnectionCredentials();
            string connection            = connectionCredentials.ConnectionString;

            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(View("AvrServiceError", (object)access.ErrorMessage));
            }

            return(ObjectStorage.Using <AvrPivotViewModel, ActionResult>(viewModel =>
            {
                ViewBag.Title = string.Format(Translator.GetMessageString("webMapTitle"), viewModel.ViewHeader.LayoutName);

                // have we anything selected in combo admin unit?
                if (!string.IsNullOrEmpty(viewModel.ViewHeader.MapAdminUnitViewColumn))
                {
                    DataSet dataSet;
                    string error = ChartMapHelper.TryToPrepareMapData(viewModel, out dataSet);
                    if (error.Length > 0)
                    {
                        return View("AvrServiceError", (object)error);
                    }

                    //TEST
                    for (int j = 0; j < dataSet.Tables[1].Rows.Count; j++)
                    {
                        string c_name = dataSet.Tables[1].Rows[j]["ColumnName"].ToString();
                        string c_new_name = dataSet.Tables[1].Rows[j]["ColumnDescription"].ToString();
                        c_new_name = c_new_name.TrimStart(); // Spaces in column name, comes outside
                        dataSet.Tables[0].Columns[c_name].ColumnName = c_new_name;
                    }

                    SharpMap.Rendering.Thematics.ITheme gradLayerTheme;
                    SharpMap.Rendering.Thematics.ITheme chartLayerTheme;
                    string gradLayerName, chartLayerName;
                    gis.GisInterface.GetAvrStyles(layoutId, out gradLayerName, out gradLayerTheme, out chartLayerName, out chartLayerTheme);

                    if (chartLayerTheme is GIS_V4.Rendering.BarChartTheme)
                    {
                        var chart_theme = (GIS_V4.Rendering.BarChartTheme)chartLayerTheme;
                        string chart_style = "{\"BarCharts\" : [";
                        for (int j = 0; j < chart_theme.BarChartItems.Count; j++)
                        {
                            var c_column = chart_theme.BarChartItems[j].ColumnName;
                            var c_color = HexConverter(chart_theme.BarChartItems[j].Color);
                            chart_style += '{' + string.Format("\"title\":\"{0}\", \"color\":\"{1}\"", c_column, c_color) + '}' + ", ";
                        }
                        chart_style += "]}";
                        chart_style = chart_style.Replace(", ]", "]");
                        ViewBag.chart_style = new HtmlString(chart_style);
                    }

                    if (gradLayerTheme is GIS_V4.Rendering.GradientTheme)
                    {
                        GIS_V4.Rendering.GradientTheme grad_theme = (GIS_V4.Rendering.GradientTheme)gradLayerTheme;
                        string min_value = grad_theme.Min.ToString();
                        string max_value = grad_theme.Max.ToString();

                        System.Drawing.SolidBrush min_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.MinStyle).Fill;
                        string min_r = min_brush.Color.R.ToString();
                        string min_g = min_brush.Color.G.ToString();
                        string min_b = min_brush.Color.B.ToString();

                        System.Drawing.SolidBrush max_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.MaxStyle).Fill;
                        string max_r = max_brush.Color.R.ToString();
                        string max_g = max_brush.Color.G.ToString();
                        string max_b = max_brush.Color.B.ToString();

                        ViewBag.grad_style = new HtmlString("{" + string.Format("\"type\":\"gradient\", \"min_value\":{0}, \"max_value\":{1}, \"min_color\":[{2}, {3}, {4}], \"max_color\":[{5}, {6}, {7}]", min_value, max_value, min_r, min_g, min_b, max_r, max_g, max_b) + "}");
                    }

                    if (gradLayerTheme is GIS_V4.Rendering.GraduatedTheme)
                    {
                        dataSet.Tables[0].Columns.Add("color");
                        dataSet.Tables[0].Columns.Add("symbol");


                        string grad_style = "{\"type\":\"graduated\", \"legend\" : [";
                        GIS_V4.Rendering.GraduatedTheme grad_theme = (GIS_V4.Rendering.GraduatedTheme)gradLayerTheme;
                        for (int i = 0; i < grad_theme.Rules.Count; i++)
                        {
                            string value_title = ((GIS_V4.Rendering.GraduatedTheme)gradLayerTheme).Rules[i].Title;
                            System.Drawing.SolidBrush value_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.Rules[i].Style).Fill;
                            var val_color = HexConverter(value_brush.Color);
                            var val_symbol = ((SharpMap.Styles.VectorStyle)grad_theme.Rules[i].Style).SymbolId;

                            grad_style += '{' + string.Format("\"title\":\"{0}\", \"color\":\"{1}\", \"symbol\":\"{2}\"", value_title, val_color, val_symbol) + '}' + ", ";

                            var dataView = dataSet.DefaultViewManager.CreateDataView(dataSet.Tables[0]);
                            dataView.RowFilter = grad_theme.Rules[i].Condition;
                            for (int j = 0; j < dataView.Count; j++)
                            {
                                dataView[j].Row["color"] = val_color;
                                dataView[j].Row["symbol"] = val_symbol;
                            }
                        }
                        grad_style += "]}";
                        grad_style = grad_style.Replace(", ]", "]");
                        ViewBag.grad_style = new HtmlString(grad_style);
                    }


                    // Space in column fix
                    for (int j = 0; j < dataSet.Tables[1].Rows.Count; j++)
                    {
                        string c_new_name = dataSet.Tables[1].Rows[j]["ColumnDescription"].ToString();
                        c_new_name = c_new_name.TrimStart(); // Spaces in column name, comes outside
                        dataSet.Tables[0].Columns[c_new_name].ColumnName = c_new_name.TrimStart();
                        dataSet.Tables[1].Rows[j]["ColumnDescription"] = c_new_name.TrimStart();
                    }

                    using (var sqlConnection = new SqlConnection(connection))
                    {
                        try
                        {
                            sqlConnection.Open();
                            var CountryID = EidssSiteContext.Instance.CountryID;
                            SharpMap.Geometries.Geometry feature = Extents.GetGeomById(sqlConnection, "gisWKBCountry", CountryID);
                            if (feature != null)
                            {
                                feature = GeometryTransform.TransformGeometry(feature, GIS_V4.Common.CoordinateSystems.SphericalMercatorCS, GIS_V4.Common.CoordinateSystems.WGS84);
                            }
                            SharpMap.Geometries.Point center_point = feature.GetBoundingBox().GetCentroid();
                            ViewBag.county_lon = center_point.X;
                            ViewBag.county_lat = center_point.Y;
                        }
                        catch (Exception)
                        {
                            ViewBag.county_lon = 0;
                            ViewBag.county_lat = 0;
                        }
                    }
                    //TEST

                    if (error.Length == 0)
                    {
                        var ds = new DataSet();
                        ds.Tables.Add(dataSet.Tables[1].Copy());
                        string json = GeoJSON.DataSetToJSON(ds);
                        string avr_json = GeoJSON.DataSetToJSON(ds);
                        ViewBag.avr_json = new HtmlString(avr_json);

                        string map_json = GetMapJson(dataSet.Tables[0]);
                        ViewBag.map_json = new HtmlString(map_json);
                        ViewBag.ColumnName = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[1].ToString());
                        ViewBag.ColumnDescription = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[1].ToString());
                        ViewBag.blnIsGradient = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[2].ToString());
                        ViewBag.gradLayerName = new HtmlString(gradLayerName);
                        ViewBag.chartLayerName = new HtmlString(chartLayerName);
                        ViewBag.blnIsChart = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[3].ToString());
                        ViewBag.map_localurl = Config.GetSetting("MapLocalUrl");
                        if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
                        {
                            ViewBag.left2right = 1;
                        }
                        else
                        {
                            ViewBag.left2right = 0;
                        }

                        return View("Index", dataSet);
                    }
                    return View("AvrServiceError", (object)error);
                }
                return View();
            }, Session.SessionID, layoutId, ViewLayoutController.StoragePrefix));
        }