Exemple #1
0
        public static void initLayers(SharpMap.Map _sharpMap, List <string> types, List <SharpMap.Layers.VectorLayer> layersList, bool typeEnabled, string query)
        {
            foreach (var layer in layersList)
            {
                _sharpMap.Layers.Remove(layer);
            }
            layersList.RemoveAll(x => true);
            foreach (var name in types)
            {
                SharpMap.Layers.VectorLayer pointsLayer = new SharpMap.Layers.VectorLayer(name);

                var provajder = new SharpMap.Data.Providers.PostGIS(connString, "points", geomname, idname);
                provajder.DefinitionQuery = "type = '" + name + "' " + query ?? "";

                pointsLayer.Style.Symbol      = Image.FromFile(Directory.GetCurrentDirectory().Replace('\\', '/') + "/pic/" + name + ".png");
                pointsLayer.Style.SymbolScale = 0.8f;
                pointsLayer.DataSource        = provajder;
                //pointsLayer.LabelColumn = "name";
                ////pointsLayer.LabelFilter = FilterLabels;
                //pointsLayer.LabelStringDelegate = ChangeLabelName;
                //pointsLayer.Style.CollisionDetection = true;
                //pointsLayer.Style.CollisionBuffer = new SizeF(25, 25);
                //pointsLayer.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
                //pointsLayer.Style.Font = new Font(FontFamily.Families.Where(x => x.Name == "Arial").FirstOrDefault(), 10 - ZoomRegulator.zoomRegulator.zoom_level * 0.7f, FontStyle.Italic);
                //pointsLayer.Style.ForeColor = Color.FromArgb(unchecked((int)0xff071e42));
                pointsLayer.Style.MaxVisible = ZoomRegulator.startZoom * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR;
                pointsLayer.Enabled          = typeEnabled;

                layersList.Add(pointsLayer);
                _sharpMap.Layers.Add(pointsLayer);
            }
        }
Exemple #2
0
        public void setPlacesLayer()
        {
            _sharpMap.Layers.Remove(placesLayer);

            var queryic = " type in (";

            for (int i = 0; i < ZoomRegulator.zoomRegulator.zoom_level + 1; ++i)
            {
                queryic += "'" + placesTypes[i] + "', ";
            }
            queryic = queryic.Remove(queryic.Count() - 2, 2) + ")";

            var provajder = new SharpMap.Data.Providers.PostGIS(connString, "places", geomname, idname);

            provajder.DefinitionQuery = queryic;

            placesLayer.DataSource  = provajder;
            placesLayer.LabelColumn = "name";

            SharpMap.Styles.LabelStyle min = new SharpMap.Styles.LabelStyle();
            SharpMap.Styles.LabelStyle max = new SharpMap.Styles.LabelStyle();
            min.CollisionDetection = true;
            max.CollisionDetection = true;
            min.CollisionBuffer    = new SizeF(25, 25);
            max.CollisionBuffer    = new SizeF(25, 25);
            min.Font          = new Font(FontFamily.Families.Where(x => x.Name == "Arial").FirstOrDefault(), 14 - ZoomRegulator.zoomRegulator.zoom_level * 0.7f, FontStyle.Italic);
            max.Font          = new Font(FontFamily.Families.Where(x => x.Name == "Arial").FirstOrDefault(), 14 - ZoomRegulator.zoomRegulator.zoom_level * 0.7f, FontStyle.Italic);
            min.ForeColor     = Color.DarkGray;
            max.ForeColor     = Color.Black;
            placesLayer.Theme = new SharpMap.Rendering.Thematics.GradientTheme("population", 0, 202250, min, max);

            _sharpMap.Layers.Add(placesLayer);
        }
Exemple #3
0
        public static string getLabelInfo(string from, string to, SharpMap.Map _sharpMap)
        {
            string returnString = "";
            var    translated   = LaToCy.CyToLaConverter.Translit(from);

            if (!allTypes.Contains(translated) && translated != "")
            {
                string query = "select ST_Distance((select geom from points where gid = '" + to + "' limit 1), (select geom from points " +
                               "where name in ('" + from + "','" + LaToCy.LaToCyConverter.Translit(from) + "') limit 1))";

                using (var connection = new NpgsqlConnection(connString))
                {
                    connection.Open();

                    var command = new NpgsqlCommand(query, connection);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            returnString = ((int)(Double.Parse(reader[0].ToString()) * 111195)).ToString() + "m";
                        }
                    }
                    connection.Close();
                }
            }
            _sharpMap.Layers.Remove(targetLayer);
            if (to != "")
            {
                targetLayer = new SharpMap.Layers.VectorLayer("target");

                var provajder = new SharpMap.Data.Providers.PostGIS(connString, "points", geomname, idname);

                provajder.DefinitionQuery = "gid = " + to;

                targetLayer.Style.Symbol       = Image.FromFile(Directory.GetCurrentDirectory().Replace('\\', '/') + "/pic/target.png");
                targetLayer.Style.SymbolScale  = 0.3f;
                targetLayer.Style.SymbolOffset = new PointF(0, -35);
                targetLayer.DataSource         = provajder;
                //searchLayer.Style.MaxVisible = ZoomRegulator.startZoom * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR;
                targetLayer.Enabled = true;
                _sharpMap.Layers.Add(targetLayer);
            }
            return(returnString);
        }
Exemple #4
0
        public static SharpMap.Layers.VectorLayer search(string name)
        {
            searchLayer = new SharpMap.Layers.VectorLayer("search");

            string query = "and type in ('";

            string delimiter = "', '";

            query += serviceTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query += utilityTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query += innTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query += transportationTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query += culturalTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query += touristActivityTypes.Aggregate((i, j) => i + delimiter + j) + delimiter;

            query = query.Remove(query.Length - delimiter.Length - 1, delimiter.Length) + ")";
            var provajder = new SharpMap.Data.Providers.PostGIS(connString, "points", geomname, idname);

            var fullQuery = "name in ('" + name + "', '" + LaToCy.CyToLaConverter.Translit(name) + "') " + query ?? "";

            if (allTypes.Contains(LaToCy.CyToLaConverter.Translit(name)))
            {
                fullQuery = " type = '" + LaToCy.CyToLaConverter.Translit(name) + "' and name != '' and name is not null";
            }
            provajder.DefinitionQuery = fullQuery;

            searchLayer.Style.Symbol      = Image.FromFile(Directory.GetCurrentDirectory().Replace('\\', '/') + "/pic/pin.png");
            searchLayer.Style.SymbolScale = 0.3f;
            searchLayer.DataSource        = provajder;
            //searchLayer.Style.MaxVisible = ZoomRegulator.startZoom * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR * ZoomRegulator.ZOOM_FACTOR;
            searchLayer.Enabled = true;



            return(searchLayer);
        }
Exemple #5
0
        public Image searchRoute(string street1, string street2)
        {
            _sharpMap.Layers.Remove(routingLayer);
            string Source1 = street1 != null?findRoadSource(street1) : null;

            string Source2 = street2 != null?findRoadSource(street2) : null;

            if (Source1 != null && Source2 != null)
            {
                var queryic = " id in (SELECT id2 FROM pgr_dijkstra('SELECT id, source, target, cost, reverse_cost " +
                              "FROM nis_routing', " + Source1 + ", " + Source2 + ", false, true))";

                var provajder = new SharpMap.Data.Providers.PostGIS(connString, "nis_routing", "geom_way", "id");
                provajder.DefinitionQuery = queryic;
                routingLayer.DataSource   = provajder;
                routingLayer.Enabled      = true;

                routingLayer.Style.Line.Width = 1;
                routingLayer.Style.Line.Color = Color.Red;
                _sharpMap.Layers.Add(routingLayer);
            }

            return(getMap());
        }
Exemple #6
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in this.gridLayers.Rows)
            {
                if ((bool)row.Cells[1].Value == true)
                {
                    string layerName = (string)row.Cells[2].Value;
                    string tableName = (string)row.Cells[2].Value;
                    string geomColumn = "the_geom";
                    string columnName = "gid";
                    PostGIS pg = new PostGIS(this.MakeConnectionString(), tableName, geomColumn, columnName);

                    PostGisEventArgs args = new PostGisEventArgs(layerName, pg);
                    this.addedPostGisLayer(this, args);
                }
            }
            this.Close();
        }