for example, I have one spatial layer Country polygon, and then another table saves other business data for each country. Then can I use a sql view or just a sql query to return both spatial and associated business data as data source to render on map?
Thanks,
Guangming
View as datasource to combine spatial data and associated business data in different sql server tables?
Hi Guangming,
Yes, we can use the view to do that but don’t forget to add the geometry column into the view.
If any questions, please feel free to let us know.
Regards,
Troy
can I use a sql query (in my case, the query will be dynamical - means the business data is coming from different tables with different set of columns)?
Hi Guangming,
We can register the ExecutingSqlStatement event in MsSql2008FeatureSource and then modify the T-SQL string in the event. the statement like this:
MsSql2008FeatureSource ms = new MsSql2008FeatureSource(connectionString,"tablename or viewname","your featureIdColumn");
ms.ExecutingSqlStatement += new System.EventHandler<ExecutingSqlStatementMsSql2008FeatureSourceEventArgs>(ms_ExecutingSqlStatement);
void ms_ExecutingSqlStatement(object sender, ExecutingSqlStatementMsSql2008FeatureSourceEventArgs e)
{
e.SqlStatement = e.SqlStatement; // do the modification
}
However, please notice that the returned columns in your SqlStatement should be equal to the columns in the view table.
Hope it helps.
Thanks,
Troy
that does not work. The original sql statement is:
SELECT allTypes.name
FROM sys.columns allColumns, sys.types allTypes, sys.all_views allViews
WHERE allColumns.object_id=allViews.object_id AND allColumns.user_type_id=allTypes.user_type_id
AND allTypes.system_type_id=240 AND allViews.name=‘stateview’
union
SELECT allTypes.name
FROM sys.columns allColumns, sys.tables allTables, sys.types allTypes
WHERE allColumns.object_id=allTables.object_id AND allColumns.user_type_id=allTypes.user_type_id
AND allTypes.system_type_id=240 AND allTables.name='stateview’
My codes to define the sql layer:
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, “stateview”, “id”);
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =
AreaStyles.State1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =
ApplyUntilZoomLevel.Level15;
sql2008Layer.Srid = 4326;
My new sql statement:
e.SqlStatement =
@"SELECT sv.id, sv.state_name, sv.state_abbr, sp.TerritoryID as ReportField, sv.geom
FROM [AdventureWorks].[dbo].stateview sv
join [AdventureWorks].person.stateprovince sp on sv.STATE_ABBR = sp.StateProvinceCode
where sp.CountryRegionCode = ‘US’"
THe error msg: cannot cast int32 to system.string.
;
Hi Guangming,
Can you show more the details of the error? Besides the error message, can you show the stack trace here, I guess the problem is that you didn’t check the type of the SqlStatement from the eventArgs, seems like the sql script posted in the thread is about checking if the specific column is valid in the table, maybe that’s the reason. Can you have a try?
Thanks,
Johnny
That helps, with a little more debugging, I learned a lot of things here:
That event was triggered several times: GetSpatialDataType, BuildIndex, GetBoundingBox, GetFeaturesInsideBoundingBoxEx,. All these were called two times when I zoom a map.
The other thing I learned is that only when the statement type is GetFeaturesInsideBoundingBoxEx is called with other attribute fields, if we use these attributes for styling/labeling. Otherwise only geometry field and id field are retrieved.
It is good design. But where is the document on how this works?
Hi guangming,
Sorry that it takes your time and thanks for you feedback, we have set up a team mainlybfor good ducumentions, vedios, examples etc. recently, but now i guess we just can get a short description at wiki.thinkgeo.com/wiki/ThinkGeo.MapSuite.Core.MsSql2008FeatureSource#ExecutingSqlStatement.
Thanks,
Johnny
I read that but it did not cover the common scenarios an end dev user will see. These documents are too generic and seems generated from codes/comments automatically. There are too many things covered but an entry level programmers already knew: basically does not help too much.
I recommend to focus on scenarios of normal customization your end users will use your product. Your codes examples are cool.
Another note is that your document has critical errors for long time: just the function above ExecutingSqlStatement: CustomColumnFetch.
in Remarks, To integrate this SQL data, you simply create a file name that does not exist in the .dbf file. It is kind of had to believe that this has existed for several years, it seems a so useful event: it should be field, I guess.
Hi guangming,
I agree with you and thank you very much on these suggestions. I will show them to the documentation team later, besides, we are designning the complete new examples for the upcoming release V8.0, It will be much more complicated than the ones shown to you before, we will try to focus on these aspects. Any more suggestions will be appreciated.
Thanks
Johnny