-05: 57. Create the. SHP file extension of ArcGIS.

Source: Internet
Author: User
Tags polyline
08: 57arcgis (. SHP file extension)

The format Suffix of the file to be calculated by arcamp must be. SHP. The method described on the internet is complicated and difficult. How can I create a. SHP file?

1. Open the ArcMap software and click "add XY data" in the "Tools" drop-down menu on the menu bar. In the "add XY data" dialog box, add workbook data. dbf3 format file (refer to "3rd GPS"), click OK, And the GPS collection point is displayed.

2. Right-click the file name in the layer column "add XY Data". In the displayed dialog box, select "data". In the drop-down menu, select "export data ", name this layer file and save it as the suffix ". SHP file. In this way, the process of making the. SHP file with the extension name is completed, and various operations of the local statistics can be performed in the next step.

The following is how to create a. SHP file extracted from the Internet:

1. method 1

How to createSHPFile<? XML: namespace prefix = o ns = "urn: Schemas-Microsoft-com: Office: office"/>


In ArcGIS, after the topographic map is registered, you need to create some SHP files for Vectorization. This section describes how to create a SHP file.
(1) Start arccatalog.
You can click the yellow button on the ArcMap toolbar, or click Start> program> ArcGIS> arccatalog.
(2) In the directory tree of arccatalog, click the directory to store SHP, and right-click it. The shortcut menu-> New-> SHP is displayed.
In the create new shapefile dialog box, enter name, that is, the name of the SHP file.
Feature type: type of SHP to be created (point, line, or surface ).
Spatial Reference: spatial reference. For example, if we want to vectorize a topographic map of 1 W (if it is Xi'an 80), click the edit button.
In the space reference Properties dialog box, click Select and select projected coordinate systems-> Gauss Kruger-> Xian 1980. Then select the corresponding projection parameters under the xian1980 directory.
So far, half of SHP has been created.
(3) Right-click the SHP file and select Properties From the shortcut menu. In the Properties dialog box, click fields to create an attribute field.
In this way, the SHP file is created, and you can load the SHP File In ArcMap to perform vectoring.

Method 2

Create a SHP file based on an Excel table
Xiao zeyun, School of Civil Engineering and hydropower, Three Gorges University
Creating a SHP file based on an Excel table mainly creates a SHP data file by using the numerical information in the Excel table, such as the X value, Y value, and attribute information used to represent the coordinate of a vertex, the geometric position of the midpoint in this file is the value specified in the Excel table, and relevant attribute information is added as required. Specifically, the entire process involves importing an Excel data table, creating a SHP data file, and adding data (including geometric data and attribute data ). The following describes how to generate a SHP data file based on an Excel table:
1. Import an Excel Data Table
There are two main ways to import an Excel data table. One is to open an Excel table in the form of an oledb data source, and the other is to open the table by calling an Excel object in the form of an application. Because the use of oledb data sources is more universal, this method can not only open an Excel table, but also open an Access database, SQL database, etc. (the specific call method is slightly different ), the following describes the first method: first, define the data source connection object in the global variable, as follows: oledbconnection oledbcconnection; // connect to excel and then add a menu item or button to open the Excel data table, add the following code for its click () event:
Openfiledialog opendg = new openfiledialog ();
Opendg. Title = "open an Excel table ";
Opendg. Filter = "Excel table (*. xls) | *. xls | CSV format
(*. CSV) | *. CSV | all files (*. *) | *.*";
Opendg. showdialog ();
String filename;
Filename = opendg. filename;
String strconn
= @ "Provider = Microsoft. Jet. oledb.4.0; Data Source ="
+ Filename + "; extended properties = Excel 8.0 ";
Oledbcconnection = new oledbconnection (strconn );
Oledbcconnection. open ();
Datatable table = new datatable ();
Table =
Oledbcconnection. getoledbschematable (oledbschemaguid. Tables, new
Object [] {null, "table "});
Excelbookcomboboxex. Items. Clear ();
Foreach (datarow DR in table. Rows)
Excelbookcomboboxex. Items. Add (string) Dr ["table_name"]);

Excelbookcomboboxex. Text =
Excelbookcomboboxex. items [0]. tostring ();
Catch (exception)
MessageBox. Show (exception. Message );
Among them, excelbookcomboboxex is a ComboBox component used to display the table name in the Excel file (an Excel file may contain many tables, and each table name is different, and the name of the first data table is not necessarily "sheet1 "). To avoid an error because the table name does not exist in the Excel file, use a ComboBox component to name all the tables in the Excel file. The variable table stores information about all tables in the Excel table. Therefore, "Dr [" table_name "]" is used to obtain the corresponding table name in the row. In the excelbookcomboboxex control, select the Excel worksheet to be opened in the Excel table and use a database connection command to connect to the data source defined earlier to obtain the data in the worksheet. Add a button to open a worksheet in Excel and add the following code for its click () event:
String sheetname = excelbookcomboboxex. text;
String strcom = @ "select * from [" + sheetname + "]";
Oledbdataadapter mycommand = new
Oledbdataadapter (strcom, oledbcconnection );
Dataset mydataset = new dataset ();
Mycommand. Fill (mydataset, "[" + sheetname + "]");
Exceldatagridviewx. datamember = "[" + sheetname + "]";
Exceldatagridviewx. datasource = mydataset;
Catch (exception)
MessageBox. Show (exception. Message );
In the above Code, exceldatagridviewx represents a data table control used to display data in an Excel table.

Ii. Create a SHP Data File
Creating a SHP data file through an Excel table may involve creating a SHP data file. Here we will first introduce the process of creating a SHP data file. Create a new form to create the SHP file interface, set the form name attribute to "createshpfile", and add the as shown in the figure on the interface (the red font indicates the name of the Control ): this section describes the main controls in the form. The filepathtextbox control is used to represent the file path, the savefilebutton control is used to represent the path browsing, And the filenametextbox control is used to represent the new file name, shptypecombobox indicates the new data type (such as point, polyline, and polygon). The create button is used to create a new SHP File Based on the settings, and the cancel button is used to cancel the creation of a new SHP file. First, define three variables in the global variables, as shown in the following code:
Private axmapcontrol;
Private string filepath;
Private string filename;
Axmapcontrol indicates the mapcontrol control (mainly used to add the newly created data file to the map), filepath indicates the path of the newly created data file, and filename indicates the name of the newly created data file. The constructor for changing the createshpfile form is as follows:
Public createshpfile (axmapcontrol _ axmapcontrol)
Axmapcontrol = _ axmapcontrol;
Initializecomponent ();
In this way, the mapcontrol object must be specified when the createshpfile class is defined. Add the following code for the click () event of the Save file path button (savefilebutton:
Private void savefilebutton_click (Object sender, eventargs E)
Savefiledialog savedg = new savefiledialog ();
Savedg. Title = "Creating a SHP file ";
Savedg. Filter = "SHP file (*. SHP) | *. SHP ";
Savedg. showdialog ();
String SaveFilePath = savedg. filename;
Int I = SaveFilePath. lastindexof (@"\");
Int length = SaveFilePath. length;
Filepath =
Microsoft. VisualBasic. Strings. Left (SaveFilePath, I + 1 );

Filepathtextbox. Text = filepath;
Filename =
Microsoft. VisualBasic. Strings. Right (SaveFilePath, length-I-1 );
Filenametextbox. Text = filename;
Catch (exception E)
MessageBox. Show (E. Message );
In the above Code, the saved full path name SaveFilePath identifies the file path and file name through the symbol. When you change the text content in the filepathtextbox control and filenametextbox control, you must change the global variables filepath and filename accordingly. Therefore, add the following code for the textchanged () event of the filepathtextbox control and filenametextbox control:
Private void filepathtextbox_textchanged (Object sender,
Eventargs E)
Filepath = filepathtextbox. text;
Private void filenametextbox_textchanged (Object sender,
Eventargs E)
Filename = filenametextbox. text;
You can create a new SHP data file through the iworkspacefactory interface and ifeatureworkspace interface. The following code is added for the click () event of the "Create" button:
Private void create _ click (Object sender, eventargs E)
Iworkspacefactory pshpwksfact = new
Shapefileworkspacefactory ();
Ifeatureworkspace pfeatwks;
Pfeatwks =
(Ifeatureworkspace) pshpwksfact. openfromfile (filepath, 0 );
Const string strshapefieldname = "shape ";
// Define attribute Fields
Ifields pfields;
Ifieldsedit pfieldsedit;
Pfields = new fieldsclass ();
Pfieldsedit = (ifieldsedit) pfields;
Ifield pfield = new fieldclass ();
Ifieldedit pfieldedit = new fieldclass ();

Pfieldedit. name_2 = strshapefieldname;
Pfieldedit. type_2 = esrifieldtype. esrifieldtypegeometry;
Pfield = (ifield) pfieldedit;
// Define Geometric Attributes
Igeometrydef pgomdef = new geometrydefclass ();
Igeometrydefedit pgomdefedit = new geometrydefclass ();
Pgomdefedit = (igeometrydefedit) pgomdef;
Switch (shptypecombobox. Text)
Case "point ":
Pgomdefedit. geometrytype_2 =
Esrigeometrytype. esrigeometrypoint;
Case "polyline ":
Pgomdefedit. geometrytype_2 =
Esrigeometrytype. esrigeometrypolyline;
Case "polygon ":
Pgomdefedit. geometrytype_2 =
Esrigeometrytype. esrigeometrypolygon;
Case "multipoint ":
Pgomdefedit. geometrytype_2 =
Esrigeometrytype. esrigeometrymultipoint;
Case "multipatch ":
Pgomdefedit. geometrytype_2 =
Esrigeometrytype. esrigeometrymultipatch;
Pgomdefedit. spatialreference_2 = (ispatialreference) New
Unknowncoordinatesystem ();
Pfieldedit. geometrydef_2 = pgomdef;
Pfieldsedit. addfield (pfield );
Pfields = (ifields) pfieldsedit;
Ifeatureclass pfeatureclass;
Pfeatureclass = pfeatwks. createfeatureclass (filename,
Pfields, null, null, esrifeaturetype. esriftsimple, strshapefieldname,
// Add new data to map
Axmapcontrol. addshapefile (filepath, filename );
This. Hide ();

Specifically, the process of creating a SHP file is divided into four steps: Step 1: Create an iworkspacefactory and ifeatureworkspace workspace (based on the file path); Step 2: Define the attribute fields of the data, by default, an attribute field named "shape" is created for it to represent its geometric shape. The field format is esrifieldtype. esrifieldtypegeometry; Step 3: Define the geometric attributes. The SHP data type (point, line, and plane) has been specified before. In this case, define the geometrytype and specify the space reference system, the default value is unknowncoordinatesystem. Step 4: Create a SHP data file in the ifeatureworkspace workspace.

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.