Select to view content in your preferred language

Working with Shapefiles

3066
7
12-08-2010 07:26 AM
KeithSearles
Emerging Contributor
Newbie question here

I have a Silverlight map in ESRI and want to add and plot shape files to it. How do I go about:

1) Adding Shapefiles to my application
2) Adding them to my map

I've been going through google and forums for the last few hours now and no help whatsoever. Code examples would be MUCH APPRECIATED!

Thank you.
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
Kindly look at this related thread: http://forums.arcgis.com/threads/15833-ShapeFiles-And-Text-files

You can go to Advanced Search for "Shapefile" in ArcGIS API for Microsoft Silverlight/WPF forum, to get more related threads.
0 Kudos
nakulmanocha
Esri Regular Contributor
Try this if this helps

http://esrislcontrib.codeplex.com/
0 Kudos
KeithSearles
Emerging Contributor
Try this if this helps

http://esrislcontrib.codeplex.com/


I was able to get this loaded in my project, but now I have this problem.

Here is my code for loading just one of the shape files:
List<FileInfo> shapes = new List<FileInfo>();
FileInfo runwayShp = new FileInfo("Layers\\Runway.shp");
FileInfo runwayDbf = new FileInfo("Layers\\Runway.dbf");
shapes.Add(runwayShp);
shapes.Add(runwayDbf);


However, this is the error I receive:

System.Security.SecurityException was unhandled by user code
  Message=File operation not permitted. Access to path 'Layers\Runway.shp' is denied.
  StackTrace:
       at System.IO.FileSecurityState.EnsureState()
       at System.IO.FileInfo.Init(String fileName, Boolean checkHost)
       at System.IO.FileInfo..ctor(String fileName)
       at MidwayAirportApplication.MainPage.LoadShapeFiles()
       at MidwayAirportApplication.MainPage..ctor()
       at MidwayAirportApplication.App.Application_Startup(Object sender, StartupEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException: 


The file and directory are not read-only and are inside of the Client Bin folder...how can I get it to read it?
0 Kudos
dotMorten_esri
Esri Notable Contributor
You are not allowed to just read files from disk in Silverlight (imagine what malicious hackers would use that for in their silverlight apps).
You must use an OpenFileDialog and have the user pick the file for you.

It doesn't matter if it's in the clientbin folder. Remember that Silverlight runs on the 'client' and not on the webserver where the clientbin file resides.
0 Kudos
KeithSearles
Emerging Contributor
You are not allowed to just read files from disk in Silverlight (imagine what malicious hackers would use that for in their silverlight apps).
You must use an OpenFileDialog and have the user pick the file for you.

It doesn't matter if it's in the clientbin folder. Remember that Silverlight runs on the 'client' and not on the webserver where the clientbin file resides.


So how can I go ahead and use these shape files automatically? The shapes are to load on start up, and are not to be selected by the user.
0 Kudos
DanielWalton
Frequent Contributor
You have 2 options: 1) Put the shapefile into the xap container, or 2) write code to download it from the server after the application loads.
0 Kudos
OrenGal
Regular Contributor
You can put the shp and dbf in the sl project and read it like this:

  StreamResourceInfo sr1 = Application.GetResourceStream(new Uri("RedBook;component/pics/redbook2.shp", UriKind.Relative));
                Stream pShpStream = sr1.Stream;

                StreamResourceInfo sr2 = Application.GetResourceStream(new Uri("RedBook;component/pics/redbook2.dbf", UriKind.Relative));
                Stream pDbfStream = sr2.Stream;

                ShapeFile pShapeFileReader = new ShapeFile();
                pShapeFileReader.Read(pShpStream, pDbfStream);

Where 'RedBook' is the name of the project/solution name, 'pics' is a folder inside the project.
just add ctors to the Read function  (taken from http://esrislcontrib.codeplex.com/)
It works for me.
Oren
0 Kudos