VDS Technologies

 

How to add layer from database using layer.AddSpatialDataLayer(table,geom);

1/12/2015 1:50:51 AM
Total Posts 5

How to add layer from database using layer.AddSpatialDataLayer(table,geom);

I have to add map layer directly from database dynamically. Can I use layer.AddSpatialDataLayer(table, geom)?

The sample code is not found int the AspMapSamples.

My code:

string sql = "SELECT farmer_nam,lattitude,longitude,crop_name,panchayt,asbinary(geom) as geom FROM " + plot_map.Trim() + ";";

NpgsqlDataAdapter adpt = new NpgsqlDataAdapter(sql, connStr);

DataTable tbl = new DataTable();
adpt.Fill(tbl);
AspMap.Layer dblayer = map.AddSpatialDataLayer(tbl, "geom");
dblayer.Visible = true;

 

But, the map is not displaying.

1/12/2015 2:36:24 AM
MVP
Total Posts 323

Re: How to add layer from database using layer.AddSpatialDataLayer(table,geom);

The AddSpatialDataLayer method is obsolete, but is still available for old applications.
The PostgreSqlLayer class can be used with PostgreSQL databases, it supports spatial indexes.

If you use the AddSpatialDataLayer method, you have to set the Map.FullExtent property to the extent of your database layer or any other extent.

map.FullExtent = new AspMap.Rectangle(left, top, right, bottom);

1/12/2015 2:50:30 AM
Total Posts 5

Re: How to add layer from database using layer.AddSpatialDataLayer(table,geom);

Can u give a sample code using PostgreSQL Layer class?

1/12/2015 2:58:57 AM
Total Posts 5

Re: How to add layer from database using layer.AddSpatialDataLayer(table,geom);

Thanks.... 

The map displayed after giving:

map.FullExtent = new AspMap.Rectangle(77.1416,8.3791,77.1701,8.3390);

1/12/2015 6:10:23 AM
MVP
Total Posts 323

Re: How to add layer from database using layer.AddSpatialDataLayer(table,geom);

See the documentation, it contains samples for all supported spatial databases.