ArcGIS API for Silverlight Application Development Series (2) clients read shapefile

Source: Internet
Author: User
Tags silverlight

The system is dead, and the data is live. In some areas involving sensitive data, you may need to provide the client data access function. For example, a company has a WebGIS System Based on ArcGIS Silverlight API, which provides some common business functions to access some basic geographic data and basic business data. Some business data, due to confidentiality requirements, may not be directly provided by the system and needs to be accessed directly from the client.

Accessing shapefile on the client can be achieved through direct reading and sending data back to the server for reading. ESRI has published the shapefile format, which facilitates reading shapefile directly from the client.

The following describes how to directly read the shapefile from the client.

The followingCodeIs to process the drop event of map, that is, read shapefile by dragging and dropping files. Note that you need to drag and drop the. SHP and. DBF Files simultaneously.

Private void mymap_drop (Object sender, drageventargs e) {try {// get the file information dragged to the map idataobject dataobject = E. data as idataobject; fileinfo [] files = dataobject. getdata (dataformats. filedrop) as fileinfo []; // determines whether the drag-and-drop file is. SHP and. DBF fileinfo shapefile = NULL; fileinfo dbffile = NULL; foreach (fileinfo fi in files) {If (Fi. extension. tolower () = ". SHP ") shapefile = Fi; If (Fi. extension. tolower () = ". DBF ") d Bffile = Fi;} // read the shapefile data. shapefile shapefilereader = new shapefile (); If (shapefile! = NULL & dbffile! = NULL) {shapefilereader. Read (shapefile, dbffile);} else {MessageBox. Show ("please drag the. DBF and. SHP files to the map at the same time! "); Return;} ilist <graphic> lstgraphics = new list <graphic> (); foreach (shapefilerecord record in shapefilereader. records) {// convert the records read from the shapefile to graphic = record. topointgraphic (); If (graphic! = NULL) lstgraphics. add (graphic);} // If the spatial reference is inconsistent, you may need to project if (lstgraphics. count> 0) {geometryservice projecttask = new geometryservice ("http: // localhost/ArcGIS/rest/services/geometry/geometryserver"); projecttask. projectcompleted + = new eventhandler <graphicseventargs> (projecttask_projectcompleted); projecttask. failed + = new eventhandler <taskfailedeventargs> (projecttask_failed); // converts a plane coordinate to a latitude and longitude projecttask. projectasync (lstgraphics, mymap. spatialreference) ;}} catch (exception ex) {MessageBox. show ("drag-and-drop file error:" + ex. tostring ());}}

Then, you need to process the result in the projection completion event, specify the symbol for graphic, and add it to the layer.

Below is:

Basemap data (Portland City)

Shapefile data (ALARM dialing location in Portland 911)

Drag-and-drop effect (ALARM dialing area distribution in Portland)


Limited space, only the core code is pasted. If you need the complete code, please leave the email address in the comments.

Welcome to the ArcGIS Silverlight API discussion group: 147535735

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.