Open the shapfile and raster file.

Source: Internet
Author: User
Open the shapfile. The Code is as follows:

1 // open the workspace and the corresponding workspace factory is required
2 IWorkspaceFactory PWorkSpaceFactory = new ShapefileWorkspaceFactory ();
3
4 IFeatureWorkspace PFeatureWorkSpace;
5 IFeatureLayer PFeatureLayer = new FeatureLayerClass ();
6 OpenFileDialog Open = new OpenFileDialog ();
7
8 Open. Title = "Select File ";
9 Open. Filter = "shapefiel (. shp) | *. shp ";
10
11 Open. ShowDialog ();
12
13 string strFullPath = Open. FileName;
14 if (strFullPath = "") return;
15
16 // extract the file name and open path
17 int index = strFullPath. LastIndexOf ("\\");
18 string filepath = strFullPath. Substring (0, index );
19 string filename = strFullPath. Substring (index + 1 );
20
21 // set the shapefile workspace, that is, the open path
22 PFeatureWorkSpace = (IFeatureWorkspace) PWorkSpaceFactory. OpenFromFile (filepath, 0 );
23
24 // open a class Element
25 PFeatureLayer. FeatureClass = PFeatureWorkSpace. OpenFeatureClass (filename );
26 // PFeatureLayer. Name = PFeatureLayer. FeatureClass. AliasName;
27
28 // first clear the existing Layer
29 axMapControl1.Map. ClearLayers ();
30
31 // Add a Layer
32 axMapControl1.Map. AddLayer (PFeatureLayer );
33 axMapControl1.Refresh ();

Open Raster file 1 IWorkspaceFactory PWorkSpaceFactory = new RasterWorkspaceFactory ();
2 IRasterWorkspace PRasterWorkSpace;
3 IRasterDataset PRasterDataset = new RasterDatasetClass ();
4 IRasterLayer PRasterlayer = new RasterLayerClass ();
5 OpenFileDialog Open = new OpenFileDialog ();
6
7 Open. Title = "Select File ";
8 Open. Filter = "Layer File (*. lyr) | *. jpg; *. bmp; *. tiff ";
9
10 Open. ShowDialog ();
11 string strFullPath = Open. FileName;
12 if (strFullPath = "") return;
13
14 // extract the grid dataset name and open path
15 int index = strFullPath. LastIndexOf ("\\");
16 string filepath = strFullPath. Substring (0, index );
17 string filename = strFullPath. Substring (index + 1 );
18
19 PRasterWorkSpace = (IRasterWorkspace) PWorkSpaceFactory. OpenFromFile (filepath, 0 );
20 PRasterDataset = (IRasterDataset) PRasterWorkSpace. OpenRasterDataset (filename );
21
22 // initialize a new Rasterlayer in three ways: CreateFromDataset, CreateFromFilePath, and CreateFromRaster
23
24 // CreateFromDataset
25 PRasterlayer. CreateFromDataset (PRasterDataset );
26
27 // CreateFromFilePath
28 // PRasterlayer. CreateFromFilePath (strFullPath );
29
30 axMapControl1.Map. ClearLayers ();
31 axMapControl1.AddLayer (PRasterlayer );
32 axMapControl1.Refresh ();

Other types of files, such as Coverage, Geodatabase, CAD, and so on. The principle is similar. paste it on another day.

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.