ThinkGeo.com    |     Documentation    |     Premium Support

Spatial query or otherwise with particular shapefile and coponent version 3.1.299 or higher

Hello,


Please see the attached demo. Click select. This will enable rectangle track shapes. Make a track shape and watch the exception take place. The exception says: "An item with the same key has already been added." This is an urgent matter as we have discovered this error on a customers site on the date of installation an can't conceive a work around at this time. Other shapefiles work as expected.


I tried to run Shapefilefeaturelayer.Validate and Rebuild but nothing different happened. Please advise.


 


Thanks,


Nelson



1943-TrackToolTest.zip (321 KB)

Thank you for your post. We will look at this matter as soon as possible. You should have the response by Monday afternoon.

Nelson,


Thanks for your post and question, hope my following answer can give you some help.
 
Following screenshot shows part of the columns in the contained shape file. You can see that the third column value is “PAR_SIZE_0”, and the forth one is “PAR_SIZE_01”. When dbf read the two columns, it will only accept 8 characters which will get “PAR_SIZE_0” for both of them. So there are couple of solutions now to go around your problem:

1)      Change the DBF column name for forth column, for example, change to PAR_SIZE_1 or something.
2)      Change the code as following in your sample:

 

        Private Sub TrackOverlay_TrackEnded(ByVal sender As Object, ByVal e As TrackEndedTrackInteractiveOverlayEventArgs)
        Select Case tool_mode
            Case 0
                Exit Select
            Case 1 'Select
                map.CurrentExtent = e.TrackShape.GetBoundingBox()
                map.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear()

                Dim worldLayer As New ShapeFileFeatureLayer("C:\ThinkGeo_YangYong\MapSuite3\Support\DesktopEdition\Posts\Post7359\TrackToolTest\shp\parcels.shp")
                Dim fCollection As Collection(Of Feature)
                Dim UID_Field_SHP As String = "UID"

                If worldLayer.IsOpen = False Then worldLayer.Open()


                fCollection = worldLayer.QueryTools.GetFeaturesIntersecting(e.TrackShape, New String(-1) {})

                worldLayer.Close()


            Case 2 'ZoomOut
                Dim trackShape As New Feature(e.TrackShape)
                map.ZoomOutToCenter(135, trackShape)
                map.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear()
                Exit Select
            Case Else
                Exit Select
        End Select

        map.Refresh()
    End Sub


3)      In the above code, the return features fCollection did not contain any column value information. So if you really want these information, please get the columns collection first and then filter out the forth one (duplicate one) and then pass in the collection. That should work, while I did not test this.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Nelson,


Just change a mistake in above post after talking with our author of dbf.
 
The dbf third column and forth column are the same in dbf, you can verify this by opening it in a binary format like Notepad++. The SQL server result is processed by OLEDB by adding a 1 or 2 after if it is duplicated. We cannot do this change because this will somehow alter the data.
 
Just let you know this.
 
Thanks.
 
Yale

Thanks, Yale. I’ll recommend these changes.

Nelson, 
  
 No problem. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Yale, 
  
 I think there is a discrepency between the limitations of dbf and what you’re stating… 
  
 en.wikipedia.org/wiki/Shapefile 
  
 The maximum length of a fieldname for a dbf is 10 characters. It is clear that Map Suite can handle this because the ‘PERIMETER’ field is 9 characters, which is of course over 8. When you reach the 10th characters, which is permisible by the dbf standard, that seems to be where map suite begins to run into erratic errors during queries. I have gotten errors of invalid record and ‘An item with the same key already exists’ and so on.  
  
 I have used the ShapeFileFeatureLayer.Validate method and sometimes this seems to auto-correct some field names as I am starting to notice. This is sort of a problem though… We need to allow our users to use 10 characters in the field name because 10 characters is very limiting as it is; we can not further restrict them… 
  
 Are you sure this isn’t a bug in some validation code? Why can’t map suite accept 10 character field lengths? We are having a large quanitity of customer complaints at this time from ‘random errors’ that are really not random, they are just trying to query with datasets that have 10 character field names.  
  
 I hope I was clear. Thanks Yale.

Nelson,


I think you are clear:.
 
I am sorry to say that I made a mistake in my previous post after more investigations into our dbf code; it is 10 characters instead of 8 we can support in our dbf module. More then 10 cannot be supported. I think I mistook this with the length of the file name.
 
In our validation, we just validate the shapes in the .shp file, to see it is standard or not. We do not have any check on the Dbf.
 
Thanks.
 
Yale