Format Exception when reading shapefile

14 posts, 0 answers
  1. Josh
    Josh avatar
    8 posts
    Member since:
    Nov 2012

    Posted 14 Dec 2012 Link to this post

    What I am trying to accomplish is this:  I have autocad drawings of a commercial ship and it's decks.  I converted each deck drawing to a shapefile with ArcGIS.  I can view the shapefiles just fine with a variety of different software, so the shapefiles appear to be ok.  All I am trying to do is display these shapefiles using the RadMap.  What is happening is I am getting a "Input string was not in a correct format" when calling ShapeFileReader.Read().  Is there something wrong with my shapefiles?  This is my code below:

    Dim shapeResourceInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("/Silverlight.Gis;component/Images/ShapeFiles/TankTop.shp", UriKind.RelativeOrAbsolute))
            Dim dbfResourceInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("/Silverlight.Gis;component/Images/ShapeFiles/TankTop.dbf", UriKind.RelativeOrAbsolute))
            Dim shapes As List(Of FrameworkElement) = ShapeFileReader.Read(shapeResourceInfo.Stream, dbfResourceInfo.Stream)
     
            For Each Shape In shapes
                InformationLayer.Items.Add(Shape)
            Next


    And my XAML:

    <telerik:RadMap x:Name="RadMap">
                <telerik:RadMap.Provider>
                    <telerik:EmptyProvider />
                </telerik:RadMap.Provider>
                <telerik:InformationLayer x:Name="InformationLayer">
                </telerik:InformationLayer>
            </telerik:RadMap>


    Any ideas?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 17 Dec 2012 Link to this post

    Hello Josh,

    It is complicated and it is hard to reproduce the problem without your shape-files, but using just the code snippet you sent.
    Could you, please, provide us with a small sample solution which reproduces it? Thanks.

    Regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Josh
    Josh avatar
    8 posts
    Member since:
    Nov 2012

    Posted 18 Dec 2012 Link to this post

    Hi, Thank you for your response.  i was able to figure out the problem...my coordinate system was not right and I fixed it.  I can now see the shapefiles on the map.  I am however having another issue...when panning and zooming there is a lot of lag time.  Typical deck shapefile has about 11,000 PolyLines.  Is this just simply too much data to process?
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 20 Dec 2012 Link to this post

    Hi Josh,

    The rendering performance can be insufficient when you add a lot of shapes on a map. We could propose using the dynamic layer for loading shapes according to zoom level and region. The DyamicLayer was designed for use with large number of items but when the number of items in the layer does not exceed 50-100 at the same time.
    Please take a look at the Using Dynamic Layer topic of our documentation and the Items Virtualization example:
    http://www.telerik.com/help/silverlight/radmap-features-dynamic-layer.html
    http://demos.telerik.com/silverlight/#Map/DynamicLayer

    Also when you have a need to show a large GIS data on the map and it should be displayed for all zoom levels then I would recommend to consider the possibility of server side rendering of GIS data to the tile images like  OpenStreet and Bing.

    Best regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Shawn
    Shawn avatar
    3 posts
    Member since:
    Oct 2011

    Posted 12 Aug 2013 Link to this post

    Hi,

    I got FormatException: When converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object.
    In the dbf I have values like this: 20110713, 20060110 etc.
    I guess it can't parse.
    Is there any way to force the ShapeFileReader to handle the properties as string?

    thanks a lot
  7. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 13 Aug 2013 Link to this post

    Hello Shawn,

    You can specify your own set of properties including a type of each property which should be read by the ShapeFileReader. So, you can specify the date-time field as the property of the string type.
    You don't need to specify all DBF fields. You can specify only the fields which are required in your application.
    The sample code is below.
    ExtendedPropertySet properties = new ExtendedPropertySet();
    properties.RegisterProperty("Field #1", "Field #1", typeof(string), string.Empty);
    properties.RegisterProperty("Field #2", "Field #2", typeof(string), string.Empty);
     
    List<FrameworkElement> shapes = ShapeFileReader.Read(shpfile, dbffile, properties);

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Shawn
    Shawn avatar
    3 posts
    Member since:
    Oct 2011

    Posted 13 Aug 2013 Link to this post

    Hi Andrey, thanks for your quick response.

    My second question is, how can I list the available properties? I have a shpstream and a dbfstream.
    I would like to go through all available properties before the ShapeFileReader.Read method (since here I got the exception).

    Thanks a lot
  9. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 14 Aug 2013 Link to this post

    Hi Shawn,

    The RadMap does not support this functionality. The DBF-file is processed inside the ShapeFileReader.Read method.
    Unfortunately we can't reproduce the problem without your shape-file. So, I also would recommend you to open a support ticket and attach your shape-file for detail analysis.

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  10. Alice
    Alice avatar
    4 posts
    Member since:
    Oct 2013

    Posted 20 Jan 2014 Link to this post

    I am getting FormatException (Input string was not in a correct format) and can't figure out what's wrong. Exception is thrown before PreviewReadCompleted get executed. Coordinate system of both shapefile and map is WGS 84, EPSG: 4326. Also I can view and edit the shapefile in QGIS, MapWindow GIS and fGIS.

    XAML:
    <telerik:RadMap>
        <telerik:RadMap.Provider>
            <telerik:EmptyProvider />
        </telerik:RadMap.Provider>
        <telerik:InformationLayer>
            <telerik:InformationLayer.Reader>
                <telerik:MapShapeReader SourceType="ShapeFile" 
                                       DataSource="DataSources/roads.dbf" 
                                       Source="DataSources/roads.shp"                                      
                                       PreviewReadCompleted="MapShapeReader_PreviewReadCompleted" />
            </telerik:InformationLayer.Reader>
        </telerik:InformationLayer>
    </telerik:RadMap>


    Stack Trace:
    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
    at System.String.System.IConvertible.ToInt64(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at Telerik.Windows.Controls.Map.ShapeReaderHelper.ReadDbfRecord(ExtendedData record, DbfHeader header, Byte[] recordContent)
    at Telerik.Windows.Controls.Map.DbfReader.GetNextRecord()
    at Telerik.Windows.Controls.Map.DbfReader.MoveNext()
    at Telerik.Windows.Controls.Map.ShapeFileReader.GetExtendedData(DbfReader dbfReader)
    at Telerik.Windows.Controls.Map.ShapeFileReader.GetShape(EndianBinaryReader reader, DbfReader dbfReader, List`1 list, ShapeFileReaderParameters parameters)
    at Telerik.Windows.Controls.Map.ShapeFileReader.GetShapes(EndianBinaryReader reader, DbfReader dbfReader, ShapeFileReaderParameters parameters)
    at Telerik.Windows.Controls.Map.ShapeFileReader.Read(ShapeFileReaderParameters parameters)
    at Telerik.Windows.Controls.Map.MapShapeReader.ReadShapeFileByType(ShapeReaderStatus status)
    at Telerik.Windows.Controls.Map.MapShapeReader.CompleteReading(ShapeReaderStatus status, Exception error)
    at Telerik.Windows.Controls.Map.MapShapeReader.CheckComplete(Exception serviceError, Object userState, Stream stream, Boolean data)
    at Telerik.Windows.Controls.Map.MapShapeReader.ReadShapesCompleted(Object sender, OpenReadCompletedEventArgs e)
    at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
    at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

    Shape file:
    http://files.mail.ru/5391386A21574E37AEA4436312FAE624
  11. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 20 Jan 2014 Link to this post

    Hello Alice,

    Unfortunately we cannot tell for sure what is the particular cause for this problem by looking at the code snippet you sent. In order to be able to assist you we will need a small sample demonstrating your shape file as well or at least your shape file so we can test the solution locally.

    However, usually this problem occurs when the dbf-file contains incorrect data in numeric fields. For example when some records contain asterisk symbol in numeric fields or the field is empty.

    Basically the MapShapeReader converts each dbf record to the ExtendedData value. By default it converts numeric types to integer, long or double .Net type. So, it can't convert a numeric field which does not contain correct numeric data.

    To avoid this problem you should update these records with correct data. Or you can set the ExtendedPropertySet of the MapShapeReader using a string type for the numeric field.

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

    Sign up for Free application insights >>
  12. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 01 Apr 2015 in reply to Andrey Link to this post

    Hi Andrey,

    I have tried your ExtendedPropertySet approach

    StreamResourceInfo shapeResourceInfo = Application.GetResourceStream(new Uri("/RailCapacityModel.Wpf;component/AppData/RailLinesNational.shp", UriKind.RelativeOrAbsolute));
    StreamResourceInfo dbfResourceInfo = Application.GetResourceStream(new Uri("/RailCapacityModel.Wpf;component/AppData/RailLinesNational.dbf", UriKind.RelativeOrAbsolute));
    ExtendedPropertySet properties = new ExtendedPropertySet();
    properties.RegisterProperty("LINKNAME", "Link Name", typeof(string), string.Empty);
    properties.RegisterProperty("STATIONA", "Station A", typeof(string), string.Empty);
    properties.RegisterProperty("STATIONB", "Station B", typeof(string), string.Empty);
    List<FrameworkElement> shapes = ShapeFileReader.Read(shapeResourceInfo.Stream, dbfResourceInfo.Stream, properties);

    but no get the following error:

    System.ArgumentOutOfRangeException was unhandled
      HResult=-2146233086
      Message=Index and count must refer to a location within the buffer.
    Parameter name: bytes
      Source=mscorlib
      ParamName=bytes
      StackTrace:
           at System.Text.EncodingNLS.GetString(Byte[] bytes, Int32 index, Int32 count)
           at Telerik.Windows.Controls.Map.ShapeReaderHelper.ReadDbfRecord(ExtendedData record, DbfHeader header, Byte[] recordContent)
           at Telerik.Windows.Controls.Map.DbfReader.GetNextRecord()
           at Telerik.Windows.Controls.Map.DbfReader.MoveNext()
           at Telerik.Windows.Controls.Map.ShapeFileReader.GetExtendedData(DbfReader dbfReader)
           at Telerik.Windows.Controls.Map.ShapeFileReader.GetShape(EndianBinaryReader reader, DbfReader dbfReader, List`1 list, ShapeFileReaderParameters parameters)
           at Telerik.Windows.Controls.Map.ShapeFileReader.GetShapes(EndianBinaryReader reader, DbfReader dbfReader, ShapeFileReaderParameters parameters)
           at Telerik.Windows.Controls.Map.ShapeFileReader.Read(ShapeFileReaderParameters parameters)
           at Telerik.Windows.Controls.Map.ShapeFileReader.Read(Stream shapeStream, Stream dbfStream, ExtendedPropertySet extendedPropertySet, Encoding encoding, ICoordinateConverter coordinateConverter)
           at Telerik.Windows.Controls.Map.ShapeFileReader.Read(Stream shapeStream, Stream dbfStream, ExtendedPropertySet extendedPropertySet)
           at RailCapacityModel.Wpf.MainWindow.FillInformationLayer() in c:\Software\Microsoft\RailCapacityModel\RailCapacityModel.Wpf\MainWindow.xaml.cs:line 116
           at RailCapacityModel.Wpf.MainWindow.radMap_Initialized(Object sender, EventArgs e) in c:\Software\Microsoft\RailCapacityModel\RailCapacityModel.Wpf\MainWindow.xaml.cs:line 51
           at System.EventHandler.Invoke(Object sender, EventArgs e)
           at Telerik.Windows.Controls.RadMap.OnInitializeCompleted(EventArgs args)
           at Telerik.Windows.Controls.RadMap.Initialize()
           at Telerik.Windows.Controls.RadMap.OnApplyTemplate()
           at System.Windows.FrameworkElement.ApplyTemplate()
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
           at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
           at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
           at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
           at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Border.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Window.MeasureOverrideHelper(Size constraint)
           at System.Windows.Window.MeasureOverride(Size availableSize)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Interop.HwndSource.SetLayoutSize()
           at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
           at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
           at System.Windows.Window.SetRootVisual()
           at System.Windows.Window.SetRootVisualAndUpdateSTC()
           at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
           at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
           at System.Windows.Window.CreateSourceWindowDuringShow()
           at System.Windows.Window.SafeCreateWindowDuringShow()
           at System.Windows.Window.ShowHelper(Object booleanBox)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.ProcessQueue()
           at System.Windows.Threading.Dispatcher.WndProcHook(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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, 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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.Run()
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at RailCapacityModel.Wpf.App.Main() in c:\Software\Microsoft\RailCapacityModel\RailCapacityModel.Wpf\obj\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    Unfortunately the file contains sensitive data so I cannot attach, but if I open the DBF file in something like DBFView there is now problem opening the file and I am using the fieldnames from theat file for the PropertyName when registring the property in the ExtendedPropertySet. 
  13. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 06 Apr 2015 Link to this post

    Hello Renier,

    As Andrey suggested earlier in this thread, you can check if the fields of your DBF file contains valid data. In other words you can check if all fields contain valid data that can be cast to and is it in the range of the .NET types such as int or double.

    The most obvious reason behind the ArgumentOutOfRangeException is the format of the fields of your DBF file.

    Regards,
    Pavel R. Pavlov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  14. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 06 Apr 2015 in reply to Pavel R. Pavlov Link to this post

    Hi Pavel,

    Thanks for the reply. Indeed there was a problem with the DBF file as it contained corrupted data in the last two entries. Being a binary format just makes it a bit harder to trace. It would be very helpful if the exception could return the row and field name that generated the error.

    Regards

    Renier

  15. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 08 Apr 2015 Link to this post

    Hello Renier,

    Thank you for this feedback. You can actually submit a feature request in our feedback portal when you feel some functionality can be built-in. We will later review, discuss it internally and probably approve it for future implementation.

    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner