In my web application, I am attempting to add in points based on longitutde and latitude colums in a SQL database. I've searced around the forums and watched the Webinars, however I have not found anyone else who has been tasked with this. I've attempted several different approches, however none of them have been successful. If anyone has done this successfully or something similar, please walk me through the steps and/or coding process. Thanks!
Plotting Points using SQL Database
James,
InMemoryFeatureLayer is the one you need. It adds the features manually and renders as image.
In your scenario, you can get a DataTable from SQLServer, and then loop to add the features into the InMemoryFeatureLayer.
We have an online sample for InMemoryFeatureLayer:
websamples.thinkgeo.com/webeditionsamples/Samples/DataProviders/CreateAnInMemoryFeatureLayer.aspx
You can use the InMemoryFeatureLayer like this:InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
layer.Open();
foreach (DataRow row in dataTable.Rows)
{
layer.InternalFeatures.Add(new Feature((double)row["x"], (double)row["y"]));
}
layer.Close();
Hope it make sense.
Any questions please let me know.
Thanks,
Howard
That does help quite a bit. I was trying to use the FeatureSource method to connect to the database. Using the InMemoryFeatureLayer method, how would that be achieved?
James,
InMemoryFeatureLayer only maintains a InMemoryFeatureSource, that’s the only way adding features into it.
I guess you want to use MsSql2008FeatureSource to automatically binding to the MsSql data, right?
You need to do some pre-work on the Database.
Fist of all, you need to add a GEOMETRY column which type is geometry in Database.
Then update the column values of all the data row depending on the x and y column.
You can have a look at this article:
msdn.microsoft.com/zh-cn/library/cc280487.aspx
Then everything is ready, let’s go over the installed sample at “Samples/DataProviders/Load a MSSQL2008FeatureLayer” to use MsSql2008FeatureLayer and roll your map.
Any questions please let me know.
Thanks,
Howard
Thanks so much for your help, Howard!
Okay, I've run into another problem. I used the MsSql2008 as you've suggested, and it loads the database fine. However, it still is not plotting the point on the map. Here is my code:
string connectString = "Data Source=test.post.acgsworld.local;Initial Catalog=BZ11;Integrated Security=True";
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString,"Event","LonX, LatY");
sql2008Layer.Open();
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer); sql2008Layer.Close();
I realize that I probably seem relatively ignorant, and I know I'm probably doing many things wrong. I literally just started using your tools yesterday, and I'm still not familiar with everything yet.
James,
I guess, the third parameter of the MsSql2008FeatureLayer is incorrect; it should be the Id column of the data. I’m not sure whether you have the column which is type of geometry in your Event table. We’ll recognize the geometry shape automatically.
Please make sure you already have the column first.
If I have any misunderstanding, please let me know.
Thanks,
Howard
I have a question. Does it have to be a GEOMETRY type or can I use a GEOGRAPHY column?
Thanks!
David
David,
The second prameter is the data table name that we will use. And the third one is identified id for each record instead of Gergraphy column or anything else. Maybe i misunderstood your meaning, if it is, could give more details?
Thanks,
Johnny
Johnny,
Howard stated that “We’ll recognize the geometry shape automatically.” Would it work if my table used Geography instead of Geometry?
i.e. I have a table with multiple columns, one of which is ‘MapPoint’ and is of Geography type. If I pass in the connection string, table name string, and the ID column would it automatically see my ‘MapPoint’ column and work properly? Also, does the ID column have to be an integer? We are using Guids due to the very large volume of records we receive from a 5500+ user base with a disconnected application using the Desktop components.
Thanks,
David
David,
Yes, you could change the name for column, but you couldn’t change the type of any columns. That means you could not modify the type of ID column.
Thanks,
Khalil