Во-вторых, как можно обратиться к определенному полигону или какому-нибудь объекту слоя?
Код: Выделить всё
public Map InitializeMap()
{
string connStr = "Server=127.0.0.1;Port=5432;User Id=postgres;Password=xxx;Database=postgis"; //Connectionstring
string tablename = "graph_sos"; //Name of table in database
string idColumn = "gid"; //Name of object ID column - MUST be integer!
//Initialize map object
if (chSos.Checked)
{
psgLayer = new SharpMap.Layers.VectorLayer("Сосны"); //Create layer
psgLayer.Style.Fill = Brushes.Green;
psgLayer.Style.Outline = Pens.Black;
psgLayer.Style.EnableOutline = true;
psgLayer.Style.Enabled = true;
psgLayer.DataSource = new SharpMap.Data.Providers.PostGIS(connStr, tablename, "the_geom", idColumn); //Set the datasource to the PostGreSQL table
map.Layers.Add(psgLayer);
}
if (chEl.Checked)
{
tablename = "graph_e";
psgLayer = new SharpMap.Layers.VectorLayer("Ели"); //Create layer
psgLayer.Style.Fill = Brushes.YellowGreen;
psgLayer.Style.Outline = Pens.Black;
psgLayer.Style.EnableOutline = true;
psgLayer.Style.Enabled = true;
psgLayer.DataSource = new SharpMap.Data.Providers.PostGIS(connStr, tablename, "the_geom", idColumn);
map.Layers.Add(psgLayer);
}
if (chB.Checked)
{
tablename = "graph_b";
psgLayer = new SharpMap.Layers.VectorLayer("Береза"); //Create layer
psgLayer.Style.Fill = Brushes.SpringGreen;
psgLayer.Style.Outline = Pens.Black;
psgLayer.Style.EnableOutline = true;
psgLayer.Style.Enabled = true;
psgLayer.DataSource = new SharpMap.Data.Providers.PostGIS(connStr, tablename, "the_geom", idColumn);
map.Layers.Add(psgLayer);
}
if (chL.Checked)
{
tablename = "graph_l";
psgLayer = new SharpMap.Layers.VectorLayer("Лиственница"); //Create layer
psgLayer.Style.Fill = Brushes.Yellow;
psgLayer.Style.Outline = Pens.Black;
psgLayer.Style.EnableOutline = true;
psgLayer.Style.Enabled = true;
psgLayer.DataSource = new SharpMap.Data.Providers.PostGIS(connStr, tablename, "the_geom", idColumn);
map.Layers.Add(psgLayer);
}
map.ZoomToExtents(); //Zoom to extents
return map;
}
}