ThinkGeo.com    |     Documentation    |     Premium Support

Problem pulling shape data from SQL 2008

I have been looking at your example of using the MsSql2008FeatureLayer trying to get this layer to pull the country shapes that i have imported to my database. When I run it I get an error- "Object reference not set to an instance of an object."  Before adding the layer i do a check to make sure that the layer has data in it. From what I can see the layer has all of the data except the geometry column.



sql2008Layer.Open(); 
Collection<feature> features = sql2008Layer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);

I can see all of the elements in the feature. I am using a tool found on the internet to import the data. This is the tool that I am using SqlSpatialTools. Any ideas on what I need to do so that I can get these features to show up? This is the code that I am using to set up the map.


 



string connectString = "Data Source=jcasper01;Initial Catalog=Atlas;Persist Security Info=True;Integrated Security=True;"; 
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "Country", "ID"); 
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
sql2008Layer.Open(); 
Collection<feature> features = sql2008Layer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns); 
Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);


Jeremy, 


Just wonder what tool are you using for the importing? Here is one post where you can find what tool we are using as well as the steps of importing, please have a try and let me know if you have any issues.
 
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/4903/afv/topic/Default.aspx
 
Thanks,
 
Ben

Thanks! I will give it a try. I have decided that I need to get the shapes from the database on my own. I need to know the current language from the browser so we can get the right translation of the country names.

Jeremy, 
  
 Let me know what you find out.  Also, could you tell me where I can find the importing tool you were using? We want to have a test with that and see if there are some potential problem in our system.  
  
 Thanks, 
  
 Ben

Now that I am pulling the shape data from the database with my own query I can get the shapes to show up. Another issue that I have run into though is that I try to set the column values for each feature and when I get the shape by calling queryTools.GetFeaturesContaining I get the feature but the values that I placed in the column values are not there.


Here is my code for adding the feature to the overlay:


 


rdr is a data reader that contains the shape information from the database



if (rdr != null) 

Dictionary columns; 
while (rdr.Read()) 

columns = new Dictionary(); 
columns.Add("Country_Name", rdr["Value"].ToString()); 
columns.Add("ID", rdr["ID"].ToString()); 
var baseShape = BaseShape.CreateShapeFromWellKnownData(rdr["geom"].ToString());
overlay.FeatureSource.BeginTransaction(); 
overlay.FeatureSource.AddFeature(baseShape, columns); overlay.FeatureSource.CommitTransaction(); 



The tool that I was using is shape2Sql found sharpgis.net/page/SQL-Se...Tools.aspx



Jeremy, 
  
 I guess that’s because you added column info for every feature, but didn’t add the column name to the header of the layer . 
  
 
overlay.Columns.Add(new FeatureSourceColumn(“ColumnName”)); 
 
  
 Let me know if you have any issues. And thanks for that tool, we will do some research on it. 
  
 Ben.

Seems that’s the same tool we are using. Anyway, it’s great your data works fine now and if you have any converting problems in the future, let us know. 
  
 Ben.

On my overlay there is no property to set the column headers. I am using a InMemoryFeatureLayer. What layers has this property?

I found that i need to add the column headers in the constructor of the layer. It now shows the names of the countries. But I still am unable to see the column data when I select that feature by clicking on the shape. It looks like i get the correct shape feature but there is no column information. I need this information to set the style of that shape so that it looks like it is selected.

Jeremy, 
  
 Can you show us more codes how you select that shape and render it in a different way? Usually to highlight a feature,  what we did is to get that feature and add it to an inMemoryFeatureLayer in a separate LayerOverlay, in that way we just need to redraw that LayerOverlay which only includes the layer we want to refresh. That’s easier and have better performance. 
  
 Thanks, 
  
 Ben