I am trying to work through a seemingly very basic and yet frustrating issue...
If the 3.x version of the desktop component, my application uses ShapeFileFeatureLayer.UsingSpatialIndex to check if we need to create one on the fly for them.
Unfortunately, it seems that even if an idx file exists for the file, or if we even recreate the file manually, when loading the shapefile, this property is always false and the idx file is never leveraged. The exact same source works as expected with the older component.
Did something change about the behavior of the ShapeFileFeatureLayer to cause this? I tried explicity designating the idx file in the constructor of the ShapefileFeatureLayer object, but this did not seem to work either.
Also, randomly, I am getting “An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll” when retrieving map.CurrentScale during the CurrentScaleChanged event. This does not always happen but is happening often enough during debugging alone.
I think its possible this error could in some way be related to the lack of SpatialIndex however, so I am posting it here as well.
Stack: at QRQ=.QBQ=.cxQ=(Double dBQ=, Double dRQ=, Double dhQ=, String dxQ=) at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.set_CurrentScale(Double value) at GeoTMSMapViewer.fmMain.InitializeComponent() in C:\Users\NSoto.DESLAURIERS\Documents\Visual Studio 2008\Projects\GeoTMS\GeoMapViewer\GeoMapViewer\fmMain.Designer.vb:line 508 at GeoTMSMapViewer.fmMain…ctor() in C:\Users\NSoto.DESLAURIERS\Documents\Visual Studio 2008\Projects\GeoTMS\GeoMapViewer\GeoMapViewer\fmMain.vb:line 136
Clearly, these values are within range. This is right at application load during the form New() constructor. My application is over 10000 lines of code so it is not feasible for me to right a sample in this situation. All I have done is upgrade my components from 3.x to 5.x. I may have to revert to the latest 3.x components but I am hoping this is not the case.
About UsingSpatialIndex, I use following code to test, the result is true. ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"…\SampleData\Data\Countries02.shp"); worldLayer.Open(); bool result = worldLayer.UsingSpatialIndex;
Could you do the same tests for your data, if the result is still false, could you provide your data and we could check the problem?
About the StackOverflowException and other exception, I also couldn’t recreate in my machine, could you try to get the latest dev version dll from helpdesk, and also you can check the InitializeComponent Method, make sure the CurrentScale is set after MaximumScale and MinimumScale are set.
In regards to the StackOverflow exception and min/max scale, the issue seemed to be that the minimum scale was capped now at 200, but in the passed before I upgraded, my locus map was sset to 50 still in the .vb.design. Manually changing this to 200 fixed the scale related issues.
Also, in order to check for the existence of the spatial index, in the passed if a file did not have a spatial index, we could not load it without setting RequireIndex = false
So the code to check would follow a flow like the following:
Dim wl As New ShapeFileFeatureLayer wl.RequireIndex = False wl.ShapePathFileName = “C:\Program Files (x86)\ThinkGeo\Map Suite Desktop Full Edition 5.0\Samples\SampleData\Data\Countries02.shp”
Try wl.Open()
MsgBox(wl.UsingSpatialIndex)
Catch ex As Exception MsgBox(ex.Message)
Finally wl.Close() End Try
In this situation, the value returns false. This is different that 3.x behavior in the api because this used to work ebfore. I notice now that in the sample code, if I comment out RequireIndex = False, the file is actually unable to load during wl.open. The error is “FileName cannot be null”.
The reason I coded this way because in the passed, if you tried to open a layer with layer.open and there was no spatial index, you would receive an ‘exception’ with the message indication to generate an index first if RequireIndex were not set to false. This remains true in 5.x based on my tests, which is expected.
However, MapSuite seems to not be detecting the idx file when setting RequireIndex = false.
Ultimately, I want the user to add any shp file they desire, and if there is no idx, I want to create it for them on the fly. This was the means I used in the passed. Please advise.
Usually, we check .idx and .ids files directly by simple line code, you can use following code If (Not File.Exists(layer.IndexPathFileName)) OrElse (Not File.Exists(layer.IndexPathFileName.ToUpper().Replace(".IDX", “.IDS”))) Then ’ no index files End If
This still doesn’t solve the problem of the fact that when settings RequiresIndex = false, that I get UsesSpatialIndex = false EVEN if the index does in fact exist.
I have not followed this post in its entirety but I did a little test on my own based on your last comment on RequireIndex and UsingSpatialIndex properties. In my test, I set to false RequireIndex on a shapefile that does have a spatial index and indeed the value returned for UsingSpatialIndex is false when in fact I would expect to have returned true. I am intrigued as to how UsingSpatialIndex is supposed to behave in relation to RequireIndex property. I asked for some explanation to the Development team and I will pass to you the info I receive from them. Thank you.
The Development team is working on fixing the core problem. In the meantime, I suggest you use the following function to check if a shapefile has a spatial index or not:
Public Shared Function DoesSpatialIndexExist(shapeFileLayer As ShapeFileFeatureLayer) As Boolean
Dim exist As Boolean = False
Dim shpFileName As String = shapeFileLayer.ShapePathFileName
Dim idxFileName As String = System.IO.Path.ChangeExtension(shpFileName, ".idx")
Dim idsFileName As String = System.IO.Path.ChangeExtension(shpFileName, ".ids")
If System.IO.File.Exists(idxFileName) AndAlso System.IO.File.Exists(idsFileName) Then