Running ShapeFileFeatureLayer.QueryTools.ExecuteQuery()
on a shape file layer with the latest ThinkGeo MapSuite NuGet packages throws the following exection:
System.ArgumentOutOfRangeException
HResult=0x80131502
Message=StartIndex cannot be less than zero.
Parameter name: startIndex
Source=mscorlib
StackTrace:
at System.String.Substring(Int32 startIndex, Int32 length)
at hyY=.kEk=.kkk=(String sqlStatement, String shapePathFilename)
at hyY=.kEk=.ExecuteQuery(String sqlStatement, String pathFilename)
at ThinkGeo.MapSuite.Layers.ShapeFileFeatureSource.ExecuteQueryCore(String sqlStatement)
at CSHowDoISamples.SqlQueryAFeatureLayer.btnExecute_Click(Object sender, RoutedEventArgs e) in D:\HowDoISample-ForWpf-master\HowDoI\Querying Feature Layers\SqlQueryAFeatureLayer.xaml.cs:line 54
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at WpfApplication1.App.Main()
I thought I might be using the MapSuite’s API the wrong way, so I checked the samples provided by ThinkGeo on github. The result were the same.
The sample I tried was : Querying feature layer > Sql query a feature layer
with the default values.
and the code is (taken from that repository) is the following:
public partial class SqlQueryAFeatureLayer : UserControl
{
public SqlQueryAFeatureLayer()
{
InitializeComponent();
}
private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
wpfMap1.MapUnit = GeographyUnit.Meter;
wpfMap1.CurrentExtent = new RectangleShape(-14833496.0849081, 32062644.1224434, 14126965.1917795, -26821163.932136);
wpfMap1.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet();
// Please input your ThinkGeo Cloud Client ID / Client Secret to enable the background map.
ThinkGeoCloudRasterMapsOverlay backgroundOverlay = new ThinkGeoCloudRasterMapsOverlay("ThinkGeo Cloud Client ID", "ThinkGeo Cloud Client Secret");
wpfMap1.Overlays.Add(backgroundOverlay);
ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(Samples.RootDirectory + @"Data\USStates_3857.shp");
statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round;
statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.TransitionEffect = TransitionEffect.None;
staticOverlay.Layers.Add("StatesLayer", statesLayer);
wpfMap1.Overlays.Add(staticOverlay);
wpfMap1.Refresh();
}
private void btnExecute_Click(object sender, RoutedEventArgs e)
{
ShapeFileFeatureLayer statesLayer = (ShapeFileFeatureLayer)wpfMap1.FindFeatureLayer("StatesLayer");
statesLayer.Open();
DataTable dataTable = statesLayer.QueryTools.ExecuteQuery(tbxSQL.Text); // <== this line throws exception
statesLayer.Close();
dgridResult.DataContext = dataTable;
}
}
Is there a per-requisite that is not followed, raising this exception?
Is there another way to query feature layers that are loaded by shape files (.shp files)?
Environment:
Windows 10
.NET 4.6.1