This is a migrated thread and some comments may be shown as answers.

Format Exception when reading shapefile

13 Answers 178 Views
Map
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 14 Dec 2012, 06:14 PM
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?

13 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 17 Dec 2012, 04:34 PM
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.

0
Josh
Top achievements
Rank 1
answered on 18 Dec 2012, 07:38 PM
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?
0
Andrey
Telerik team
answered on 20 Dec 2012, 09:49 AM
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.

0
Shawn
Top achievements
Rank 1
answered on 12 Aug 2013, 07:42 PM
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
0
Andrey
Telerik team
answered on 13 Aug 2013, 12:32 PM
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 >>
0
Shawn
Top achievements
Rank 1
answered on 13 Aug 2013, 02:24 PM
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
0
Andrey
Telerik team
answered on 14 Aug 2013, 06:20 AM
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 >>
0
Alice
Top achievements
Rank 1
answered on 20 Jan 2014, 10:18 AM
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
0
Andrey
Telerik team
answered on 20 Jan 2014, 04:28 PM
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 >>
0
Renier Pretorius
Top achievements
Rank 1
Iron
Iron
Iron
answered on 01 Apr 2015, 09:37 AM
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. 
0
Pavel R. Pavlov
Telerik team
answered on 06 Apr 2015, 07:47 AM
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.

 
0
Renier Pretorius
Top achievements
Rank 1
Iron
Iron
Iron
answered on 07 Apr 2015, 02:21 AM

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

0
Petar Mladenov
Telerik team
answered on 08 Apr 2015, 12:26 PM
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.

 
Tags
Map
Asked by
Josh
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Josh
Top achievements
Rank 1
Shawn
Top achievements
Rank 1
Alice
Top achievements
Rank 1
Renier Pretorius
Top achievements
Rank 1
Iron
Iron
Iron
Pavel R. Pavlov
Telerik team
Petar Mladenov
Telerik team
Share this question
or