Loading Shapefiles from database and binding them to my view MVVM

13 posts, 0 answers
  1. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 27 Nov 2014 Link to this post

    Hello,

    My scenario is similar to the Hotel Floorplan given in your online demos. 

    I already have created some Shapefiles (*.shp) using OpenJump 1.7.1. which are working fine when used as local resource for a MapShapeReader
    in an InformationLayer.
    But i want the shapefiles to be stored in my database as byte[].
    Even loading of the files works perfectly in my viewmodel (via service call).

    So now to my problem and actual questions (keep in mind that I am using MVVM):
     -) Is it possible to load many (about 20-30) shapefiles from database and bind them to the same radmap control in my view and if so, HOW?
     -) Which datatypes do i have to use?
     -) Is saving *.shp files to the database the best solution?
     -) Would it be better to use *.kml or *.wkt files?

    Regards,
    Thomas

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 01 Dec 2014 Link to this post

    Hello Thomas,

    Our general advice for you is to switch from Information Layer (IL) to Visualization Layer (VL). In the following help article you can find a quick overview of the VL and what is enhanced in it (compared to IL).

    Visualization Layer Introduction

    I think the feature that will help in your scenario is the asynchronous reading of shape files (check section "Reading multiple files"). This increases the loading performance and gives you the ability to load several shape sources. 
    Do you use ViewModels in your scenarios ? Could you please elaborate more on the question regarding the DataTypes. The VL gives you the option to specify a ToolTipTemplate, specify MapShapeFill for the Stroke, Fill, StrokeThickness, etc. Or you can also change the default ShapeTemplate when reading Map Shapes.
    Whether saving shp files is the best solution or whether shp or kml is the better choice - I believe these are application specific / application design questions. You can test whether kml or shp files perform better in your concrete scenario and choose one of the two.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 02 Dec 2014 Link to this post

    Yes, I am using ViewModels in my scenarios!

    Let's just focus on my main issue: Binding from ViewModel to View!
    At this point, there is only one shapefile stored to the database which is in fact the 'Hotel_base.shp' given in your Hotel Floor demo.
    I have created an object property (public object ShapefileProperty{....}) in my viewmodel which represents the shapefile loaded from database. (And yes, I already have tried different datatypes, but I am not sure which to use, therefore --> object)
    In my view i want to set a binding to this ShapefileProperty.
    So can you tell me what is wrong with the following code snippets? Because there is nothing displayed in my radmap control
    1)
    01.<telerik:RadMap >              
    02.         <telerik:RadMap.Provider>
    03.             <telerik:EmptyProvider/>
    04.         </telerik:RadMap.Provider>
    05.         <telerik:VisualizationLayer>
    06.             <telerik:VisualizationLayer.ShapeFill>
    07.                 <telerik:MapShapeFill Fill="#6FDFEFFF" Stroke="Blue" StrokeThickness="2" />
    08.             </telerik:VisualizationLayer.ShapeFill>
    09.             <telerik:VisualizationLayer.Reader>
    10.                 <telerik:AsyncShapeFileReader Source="{Binding ShapefileProperty}" />
    11.             </telerik:VisualizationLayer.Reader>
    12.         </telerik:VisualizationLayer>           
    13.     </telerik:RadMap>

    2)
    1.<telerik:VisualizationLayer.Reader>
    2.   <telerik:AsyncShapeFileReader DataSource="{Binding ShapefileProperty}" />
    3.</telerik:VisualizationLayer.Reader>

    Can you please give me a working code snippet?
    I am just not sure where to set the binding to my ShapefileProperty.

    P.S.: I must not use Uri paths for loading my shapefiles, so storing them to the disk is no option for me.
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Dec 2014 Link to this post

    Hi Thomas,

    You can find attached a sample with HotelFloorPlan on RadMap where the path to the ShapeFile is saved in a string property in the ViewModel. We hope this is what you needed.
    A few additional notes:
    - you can track whether some errors are produced while reading the file or whether the file is not found if you subscribe for the PreviewReadShapeDataCompleted event of the reader and check its event args
    - you may not see any shapes if the Center and ZoomLevel of the Map are inappropriate
    - the path to the file can be saved in a string and then bound to the Source of the reader which is of type Uri because the XAML parser will convert the string to a URi automatically
    - the Source of the Reader must refer to the shape file and the DataSource must refer to the dbf file.
    If these files are with common name, you can simply refer the Source and the RadMap will find the DataSource (dbf file) automatically

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 03 Dec 2014 in reply to Petar Mladenov Link to this post

    Hi Petar,

    I am afraid this is still not the solution to my problems, but don't worry.
    Meanwhile I have created a sample on my own which provides a solution to the main problem.(Sample Project in my OneDrive)
    In this sample I am reading the "Hotel_base.shp" into a byte[] (similar to receiving file from database, where i would get a byte[] too).
    The next step is to create a MemoryStream-Property which i can bind to the StreamSource of the AsyncShapeFileReader.
    Maybe you can get an idea of what i wanted to achieve, by taking a look at my sample.

    regarding your additional notes:
        -) the PreviewReadShapeDataCompleted was very helpfull, especially in creating my sample project
        -) Center and ZoomLevel are working well and correct
        -) like I mentioned in my previous post: NO uri/paths
        -) if I got that right, source/datasource can only handle Uri

    Now I have to try, loading many files from database and displaying them on the radmap controll
    Regarding this I have another question:
     -) (How) is it possible to add information (e.g. room number) for
    displaying in tooltips to my shapes before binding them to the reader?
     -) is it possible to load information when a shape is selected?

    Regards,
    Thomas
  7. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 04 Dec 2014 Link to this post

    Hi Petar,
    I am facing a new Problem since yesterday.
    After loading of my shapefile (only 1 = Hotel_base.shp), i can drag/move this shape inside of my radmap controll, but when i am starting to zoom in or out, my whole application freezes and i do not get any response or error message. Even after waiting for about 10 minutes.
    Unfortunately neither was I able to reproduce this problem in my Sample Project nor have I found any helpfull threads regarding this exact issue.

    Maybe you can tell me something about this problem.

    Regards,
    Thomas
  8. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 04 Dec 2014 Link to this post

    Hi Petar,

    I am facing a new Problem since yesterday.
    After loading of my shapefile (only 1 = Hotel_base.shp) to my RadMap controll, I can darg/move it around which works great, but when i start to zoom in or out, my whole application freezes without any response or error message. Even after waiting for about 10 minutes nothing changes about that.
    Unfortunately neither was I able to reproduce this problem in my Sample Project nor have I found any helpfull threads regarding this exact issue.

    Maybe you can tell me something about this problem

    Regards,
    Thomas
  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 04 Dec 2014 Link to this post

    Hello Thomas,

    Regarding the first two questions:
      -) (How) is it possible to add information (e.g. room number) for displaying in tooltips to my shapes before binding them to the reader?
     -) is it possible to load information when a shape is selected? 
    You can check the approaches from the following help articles:
    Attaching Input events to Map shapes - you can use MouseLeftButtonDown
    Reading Map Shapes - check the section -Specifying a ToolTip
    The additional data should be stored in the DBF file and accessed via MapShapeDate.ExtendedData["some key"]  in code behind.

    As for the performance issue - we need more details from your specific scenario. This will help us reproduce it in our side, investigate it more precisely and advice you more precisely. Thank you in advance for tour cooperation.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 16 Dec 2014 Link to this post

    Hello Petar,

    The last few weeks we've been searching what causes the problem of freezing the whole application.
    We finally were able to implement a sample project you can download from onedrive or rename the attached *.png to *.rar.
    Within this sample project you can see the setting of different cultures.

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
     
                Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); // not working
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
     
                //Thread.CurrentThread.CurrentCulture = new CultureInfo("en"); // not working
                //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
     
                //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // WORKING
                //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
     
                this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.IetfLanguageTag);
     
                this.Content = new ViewModel()
                {
                };
            }
        }

    We have tried many cultures but the only one working is "en-US".
    Because we need to be able to run our application with at least two languages we cannot give up this feature.

    Hopefully this will help you investigate this error more precisely.

    Regards,
    Thomas
  11. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Dec 2014 Link to this post

    Hello Thomsa,

    Thank you for your project. We managed to reproduce this issue and we logged it as a bug in our feedback portal where you can track its status. We also updated your telerik account points as a thanks for your cooperation.
    We are also currently investigating more deeply this issue and will get back to you if we find a workaround or easy fix and we can promise this will be fixed in the next release.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Dec 2014 Link to this post

    Hello Thomas,

    The issue is not reproducible if you do no set the Language property of the MainWindow.  What do you need to achieve with setting this property ? May be we can think up another way to achieve what you need. Also, the IetfLanguageTag is marked Dprecated in MSDN. We hope this helps.

     
    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. Thomas
    Thomas avatar
    9 posts
    Member since:
    May 2012

    Posted 13 Apr 2015 in reply to Petar Mladenov Link to this post

    Hello Petar,

    It's been a while since my last post, but I had to work on other parts in the meanwhile.
    Nonetheless I am now ready to continue my work with RadMap.
    I was looking forward to use the new 2015.1.406.45 dev hotfix, so I took the sample project I already posted above and replaced the telerik assemblies, but unfortunately the problem has not been resolved/fixed yet.

    As you suggested, we checked the MSDN for "IetfLanguageTag" and according the Note :

    Note
    This property and the GetCultureInfoByIetfLanguageTag method are deprecated. Instead, you should use a the CultureInfo.Name property. IETF tags and names are identical.
     we changed it to "Name" but it is still not working

    So the MainWindow.xaml.cs now looks like:

    //this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.IetfLanguageTag); //OLD
    this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);  //NEW

    Hopefully you can either help me coming up with a solution or give a estimated time it takes for this problem to be solved.

    Regards,
    Thomas

    P.S.: We need to set the Language property because our Application needs to be multilingual. Even at Runtime users can change the language.

  14. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 15 Apr 2015 Link to this post

    Hello Thomas,

    Part of the issue is that our code in Visualization Layer goes into a state of deadlock. The Language change forces additional invalidation of geometries which we control asynchronously with lockings in order to achieve faster performance. In short - the issue has to do with concurrency, lockings, geometry parsings etc. and we currently do not have a workaround or estimate time for the fix.

    What we can suggest you is using the Information layer which process the shapes synchronously and does not have such issue when setting the Language. If you are ok with its performance, it is the easiest way to proceed, in our opinion.

    <telerik:RadMap.Provider>
             <telerik:EmptyProvider />
         </telerik:RadMap.Provider>
         <telerik:InformationLayer >
             <telerik:InformationLayer.Reader>
                 <telerik:MapShapeReader Source="C:\Hotel_base.shp" />
                 </telerik:InformationLayer.Reader>
             </telerik:InformationLayer>
     </telerik:RadMap>




    Regards,
    Petar Mladenov
    Telerik
     

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

     
Back to Top
UI for WPF is Visual Studio 2017 Ready