But the new release did not work for me anymore, it worked before. I opened a chart, then opened a PostgreSQLFeature layer, when the program executed the "Refresh" command, it throwed following exception and displayed a red cross on the screen, please respond as soon as possible! Thanks!
System.ArgumentException was caught
Message="An item with the same key has already been added."
Source="mscorlib"
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at ThinkGeo.MapSuite.Core.FeatureSource.GetColumnNamesInsideFeatureSource(IEnumerable`1 returningColumnNames) at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames) at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers) at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers) at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas) at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x742ba885258f6c2c(RectangleShape xb35a33b423b17f65, Overlay x99251f66cdabc2ad, Int32 xa209325f5c895f7e, Int32 x7454a0d1965919b1, GeographyUnit xbb704b4400ce6f76) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x88c2a2d6d754e692(IEnumerable`1 xa6f0db4f183189f1) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xe3cee4adb9c72451(Int32 xb565f4681f05557a) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x9ac8c50f434f4b39(Int32 xb565f4681f05557a) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.Refresh()
This isn’t really too much to go on. I can see that the error looks like it is when we are getting all of the column (ThinkGeo.MapSuite.Core.FeatureSource.GetColumnNamesInsideFeatureSource) and it seems like it is adding two columns with the same name. I do not know what layer it is happening with. It looks like the Postgre. Can you isolate the Postgre and just open it without the chart. Can you double verify that the postgre data table doesn’t in any have two columns that have the same name. Like if you had a view form two tables etc. It looks like the issue is in there somewhere.
I didnt see your last message until I posted this one. The difference between 362 and 426 are pretty substantial. Can you still check on the use of views or the column coming back. Could you try to do just create a PostgreFeatureSource and load it the lay you load your layer, i mean the same table etc, open it and call the GetAllColumnNames? I just want to try and isolate it down a bit more. I will be in realtime to help.
My PostgreFeature layer is based on a view, I checked the view, it was created properly, there are 20 columns in it, but following line of code gives me 120 columns:
Dim columns as Collection (of FeatureSourceColumn)=myPostgreFeatureLayer.QueryTools.GetColumns().
Can you see a rhyme or reason to the 120 columns? I mean do they repeat over and over? Can you hook into the event that gets raised called somethign like ExecutingSql or something and see what the exact sql is it is trying to do. Maybe that will give us an idea of what is going on. Also check if that sql to get the columns is firing multiple times. I don’t have a postgre environment to test in and the person who is the main postgre guy is out until late next week. I will take a look into the code of it but if you can try that event and tell me what you see and what the result is of the 120 columns.
For the same column, it repeats 6 times, for example two of my columns are ID and Type, it turns out to be 6 IDs, then 6 Types . That is why I got 120 columns instead of 20 columns.
Cool, I mean its bad but at least there is some reason to it. The big thing will be how often that event is firing and what the sql is and if you run that sql what it returns.
Can you see a rhyme or reason to the 120 columns? I mean do they repeat over and over? Can you hook into the event that gets raised called somethign like ExecutingSql or something and see what the exact sql is it is trying to do. Maybe that will give us an idea of what is going on. Also check if that sql to get the columns is firing multiple times. I don’t have a postgre environment to test in and the person who is the main postgre guy is out until late next week. I will take a look into the code of it but if you can try that event and tell me what you see and what the result is of the 120 columns.
David
David:
Hope I did not overlook the API document, there is nothing about PostgreFeatureLayer/FeatureSource, there are MsSQL2008FeatureLayer/FeatureSource,OracleFeatureLayer/FeatureSource. What is the exact event name to check?
Sorry for the delay. The event should be ExecutingSqlStatement in the PostgreFeatureSource. We have a HowDoI sample built in hot to use this event correctly: HowDoIsample ExtendingMapSuite AddEventInOleDbFeatureLayer
Any more questions please feel free to let me know.
Sorry for the delay. The event should be ExecutingSqlStatement in the PostgreFeatureSource. We have a HowDoI sample built in hot to use this event correctly:
Since you're in a bind you might want to just force feed your geometries to an InMemoryFeatureLayer. I think there's an IndexedInMemoryFeatureLayer floating around somewhere too.
BaseShape YourShape;
InMemoryFeatureLayer YourData = new InMemoryFeatureLayer( );
YourData.Open( );
YourData.Columns.Add( new FeatureSourceColumn( "Your_Id" ) );
YourData.Columns.Add( new FeatureSourceColumn( "Your_Other_Feature_Data" ) );
YourData.Columns.Add( new FeatureSourceColumn( "Your_Name" ) );
SqlCommand cmd = cn.CreateCommand( );
cmd.CommandText = @"SELECT Your_Geometry_Colum, Your_Name, Your_Id, Your_Other_Feature_Data FROM Your_Table WHERE Something = Something";
We have recreated this problem and confirmed it’s a bug in PostgreSqlExtension, we wil fix it in the next version. For now there are 2 ways to work around though:
1) Set the “PostgreFeatureSource.Schema” to “public” which is the default value for a postgre server. You can set it by property postgreFeatureSource.Schema = “public” or set it in the constructor “public PostgreSqlFeatureSource(string connectionString, string tableName, string featureIdColumn, int srid, string schemaName, string geometryColumnName)”;
2) Create a new PostgreFeatureSource class by inheriting the existing PostgreFeatureSource, overriding the GetColumnCore() method and make sure there are no duplicated names in the returned Column Names. You can easily call the base.GetColumnCore() first, check the returned values and remove the duplicate ones.