ThinkGeo.com    |     Documentation    |     Premium Support

Database Features not showing

Hi, I feel like I should be able to figure this out, but I've been playing with it for a while and just feel like I'm going in circles.


I created a test application that is really simple to test with.


On my map, I'm using a google overlay as the base and then I have only one other overlay with only one layer on it. The data from the layer is coming from a table in MsSQL2008. The data in the database is using the SRID of 4326. After the map has loaded, it says that there are ~9000 features on the layer, which is the amount of items in the database. In the database table all of the items are points. I'll copy in my code below, but I've tried swapping the internal and external sides of the projection thinking maybe I was confused. I'm sure you'll look at this and just immediately be able to point out my mistake.


If I query the database using the extent I've set (converted to the external projection), I come back with 11 rows from the database, so I think I should be able to see the entries when the map first loads.


Do you need to see anything else?


 


MsSql2008FeatureLayer layer = new MsSql2008FeatureLayer(connString, tableName, idColumn); Proj4Projection projection = new Proj4Projection(); projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); projection.InternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); layer.FeatureSource.Projection = projection; //layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.DarkOrange)); //layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.MajorRoad1; layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1(textColumn); layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1; layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //layer.Srid = 4326; Kimberly



Kimberly, I’m pretty sure your Internal projection needs to be the 4326, and the external is the one you want to display in.  At least that’s what I do with all of my raw data, which is also in 4326  (lon/lat geographic). 
   
 I’ve never understood the default styles.   I thought you could only set one of those.  You’re setting two, but, one is text.   And I don’t think that has anything to do with why you have 9000 features in the layer.    Again, I don’t have much experience doing it like you are.   But I’m pretty sure your projection stuff was backwards. 
  


Ted Thanks for your sharing!


Kimberly, I think there are 2 problems according to your descriptions and codes!
 
1)      Wrong internal and external string set as Ted said.
2)      In the Spatial query API, use the External bounding box to query.
 
Following code you can take reference, we tested against the “cntry02” data table transferred from cntry02.shp, and it works fine:

string internalProjectionString = Proj4Projection.GetEpsgParametersString(4326);
string externaleProjectionString = Proj4Projection.GetGoogleMapParametersString();
Proj4Projection googleProjection = new Proj4Projection(internalProjectionString, externaleProjectionString);
  
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "cntry02", "ID");            
sql2008Layer.FeatureSource.Projection = googleProjection;
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country2;//new AreaStyle(new GeoPen(GeoColor.SimpleColors.Blue, 5));
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            
sql2008Layer.Open();        
// Get the external query boundingbox.
RectangleShape boundingBox = sql2008Layer.GetBoundingBox();
Collection<Feature> features = sql2008Layer.QueryTools.GetFeaturesInsideBoundingBox(boundingBox, ReturningColumnsType.NoColumns);
sql2008Layer.Close();

Any more questions just let me know.


 
Thanks.
 
Yale

Hello! Ted, I haven't ever had any issues with setting multiple default styles, but I think if you set a custom style, you can't have any default styles.


Yale, I'm confused a little bit. It makes sense to limit the dataset to something smaller than the entire table since I'll only want to show the data for the area I'm really looking at, but it seems that if I do what you suggested, I end up with a collection of features and not a layer. I'm comparing what you have in your post to the example of the MS SQL feature layer in the Winforms C# sample application and they seem very different. If I have a collection of features, it seems I'll need to add them to an InMemoryFeatureLayer or something, but if that's the case, why is it called 'MsSql2008FeatureLayer'? Shouldn't I just be using that as a data source and adding them myself?


It seems there would be some benefits to that, however, then I have to deal with requerying if the user scrolls out or pans and I have to manage the view myself, which I thought your software did. I guess I'm just confused. Can you show how you add that to the actual map?


I did utilize your code to see how many features I would get back. My bounding box is set with layer.GetBoundingBox and then I'm querying for features inside the bounding box and I'm not getting anything returned. This is curious behavior that I wasn't expecting so I guess that means I'm probably more confused than I initially thought! >:-)


How accurate is the example in the c# sample application, does it really work? I think the bigger immediate issue is not why I'm getting 9000 records following that example, but why aren't they showing up?


Thanks,


Kimberly



Kimberly, 
  
 I am sorry to make you confused.  
  
 First, I tested against the codes in HowDoIsamples\Data Providers&#160;LoadMsSql2008FeatureLayer sample, if I set the parameters (db connection string, table name like use cntry02, featureId like using Id) correctly, it works, but it seems the Map size is very small. 
  
 Well, there is a big difference between this how do I sample with your application is it did not use any projection. 
  
 Second, the codes in my previous post ONLY show how to do spatial query when projection set on the layer. Almost every querying API will return a collection of features and you can do anything based on it, for example, you can save it to disk or you need to add it to another InMemoryLayer while you want to highlight it etc. 
  
 If you want to display it on the map control and only want to draw features within the current map view (or extent), what need to be done is just add this layer to the map control. We do not need to control it by our self, this will be the default behavior of map control. 
  
 Can you maps display correctly? Or you just have the querying result not correct problems? It is better you can paste some code snippet and make a notice where is the problem, that would make things much easier. 
  
 Any questions just let me know. 
  
 Thanks. 
  
 Yale 


I figured this out. It turns out that for these layers, when I imported them, I imported them as geometry and not geography. I was pretty sure I had checked that, but I guess I hadn’t. It’s weird to me that when I queried the feature layer, it had all the features and when I looked at their location, they seemed correct, but then they just didn’t show up.  
  
 Also, just to let you know about an error I got that I think should have a different message. In the process of reloading my tables, I accidentally changed the name of one of them. When I ran the software again, it gave me the error, “Could not find the geometry column.” I was immediately able to figure out my mistake however, I think the error message should say something about the table not existing instead. 
  
 Thanks,Kimberly

Kimberly, 
  
 Thanks for your ideas and letting us know your progress, I am glad to hear about it. 
  
 Do not hesitate to let me know if you have any questions. 
  
 Thanks. 
  
 Yale