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

How to load shapefile from external location

6 Answers 159 Views
Map
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 21 Jan 2015, 06:48 AM
Hi There 

I have been loading shapefiles which are copied into the project whose Build Action is set to Resource.

Now I have a situation where we are creating shapefiles at runtime and are saved to different location i.e c:\\Shapefile\\

1. How can I load shapefile created at runtime using UI Virtualization asyn reader.

2. It is good practice to create virtualization layer for each shapefiles or load all shapefiles in one virtualization layer. Each shapefiles have different properties i.e. zoom level, fill etc, so i assume I should create virtualization layer for each shapefiles.

3. The property of shapefiles are saved in .dbf file.Can we read .dbf files to create a property window to get/set shapefile properties.Do you have any similar project on GitHub.

Thanks in Anticipation.

6 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 23 Jan 2015, 02:14 PM
Hello Sanjay,

Let me get straight to your questions:

1. One possible loading sequence is demonstrated in the attached project. Please take a look at it and let me know if it works in your scenario. I also tried to load files that are outside the project and it worked as well. So I think you can load the shp file that you created.

2. There is no rule to follow when it comes to specific implementation. It is good to sort the shape that are loaded in one layer so that you will easily be able to control them. However, if the number of layers is big and the performance starts to drop, you can think of some kind of grouping the shapes.

3. Once the shape is loaded you can traverse the Items collection of the VisualizationLayer and cast each item to MapShapeData. This will allow you to read the properties that are described in the dbf file. This approach is also demonstrated in the attached project.

Regards,
Pavel R. Pavlov
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.

 
0
Sanjay
Top achievements
Rank 1
answered on 26 Jan 2015, 03:20 PM
Hi Pavel.

Thanks for the solution , it works!

1. I'm able to upload files from external location.However if I upload another file and add it to 

AsyncShapeFileReader<br>

Source Collection like below,

this.mapShapeDataReader.SourceCollection.Add(
                  new AsyncReaderSource()
                  {
                      Source = new Uri(FileNameTextBox.Text.ToString(), UriKind.RelativeOrAbsolute),
                  });

It always shows the first shapefile which was uploaded. I tried setting ClearCache of
MapShapeDataVirtualizationSource
 to false.
 
<telerik:MapShapeDataVirtualizationSource x:Name="mapShapeDataVirtualizationSource" ClearCache="False" >
                       <telerik:MapShapeDataVirtualizationSource.Reader>
                           <telerik:AsyncShapeFileReader x:Name="mapShapeDataReader"></telerik:AsyncShapeFileReader>
                       </telerik:MapShapeDataVirtualizationSource.Reader>
                   </telerik:MapShapeDataVirtualizationSource>
          
2. Is the order in which shapefiles are added to AsyncShapeFileReader plays a role in the visibility of shapefiles? Can I determine which the order in which the shapefile should be loaded and visible in .AsyncShapeFileReader? In attached project, in the listBox I try to change the order of shapefiles names, can we reflect same on rad map.

3. I saw an example where RadDiagram properties were set to RadPropertyGrid, can we do the same for VirtualizatioLayer for radMaps.The idea is to change the property of Virtualization layer by the use to PropertyGrid. I am currently binding the PropertyGrid with ObservableCollection,but the I'm not able to trace back the changes in PropertyGrid so that i can update VirtualizationLayer.

a.Can we set VirtualizationLayer to ObservableCollection of generic type which is set to PropertyGrid to achieve this.
b.Objective : To Change MapShapeFill Fill property and see the change on RadMap,Any sample project would be highly appreciated.
Let me know if this query is applicable to PropertyGrid forum, I shall post there.

Sample project download here

Thanks in Anticipation
0
Pavel R. Pavlov
Telerik team
answered on 29 Jan 2015, 12:52 PM
Hi,

I am currently working on your case. However, I will need more time to completely investigate this case. I will get back to you in a couple of hours.

Regards,
Pavel R. Pavlov
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.

 
0
Pavel R. Pavlov
Telerik team
answered on 29 Jan 2015, 02:11 PM
Hello Sanjay,

I am happy to hear that the earlier provided approach works in your specific case. Let me now address the rest of your questions:

2. The short answer is yes. The order of adding the shapes plays role in visualization. Keep in mind that the z index of the shape that is added first is the lowest. Also, each following shape is with higher z index. What this means for you is that if you need to stack all 3 shapes you and visualize them simultaneously, you will need to first add the shape that is with the largest size. After that, on top of it you can add the shapes that are with smaller size - respectively takes less total area. In your project you should add first the coast shape, then the BuildupGeneral shape and last the Motorway2014 shape. This way all 3 shapes will be visualized. If you need to change the order of the shapes you will need to clear the layer and load the shapes again in the new order.

3. As for the questions for the RadPropertyGrid you should be able to use it in your case. However, your requirements will be handled in a better way if you open separate thread and ask your questions there.

Regards,
Pavel R. Pavlov
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.

 
0
Sanjay
Top achievements
Rank 1
answered on 02 Feb 2015, 07:16 AM
Hi Pavel,

Appreciate if you could answer my query #1 as well.

For query #2,if i have 5 visualizationlayer,each have one shapefile,so can we determine the order in which visualizationlayer are added.I'm adding them at runtime.Once added can we change the order at runtime.

Thanks in Anticipation.
0
Pavel R. Pavlov
Telerik team
answered on 04 Feb 2015, 02:11 PM
Hi Sanjay,

In order to visualize the shape that is lastly added you can try to first clear the collection of the async reader, add again all shapes that were already loaded, on top of them add the new shape and then read all the collection. The point is to read the collection only once.

As for having multiple layers, please note that at the end of the day the RadMap control visualizes all shapes in one Canvas. This means that if you are using asynchronous loading each async reader will add its shapes into the Items collection of the control whenever it finishes reading the shape. This means that you do not have the control over the z-order of the shapes because you do not know which reader will finish loading first or second. In other words using async readers restricts you from controlling the z order of the shapes. To control the z-order you will need to first load one shape, wait till it is properly loaded and then start loading the next one.

I hope this answers all your questions.

Regards,
Pavel R. Pavlov
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.

 
Tags
Map
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Sanjay
Top achievements
Rank 1
Share this question
or