Convert CAD to SHP

Source: Internet
Author: User
VBA-based SCS data classification and conversion to shape file Author: FFFF Source: blog Park Release Date: Read: 170 Original article links [add to favorites] Use VBA-based SCS data classification to convert to shape files
Gao hongbing, Li Fengbin, Wang Jin, Liu Yu
(Dalian jiucheng ing enterprise group, Dalian, Liaoning 116400, China)
ABSTRACT Data is the basis for GIS development and the establishment of various thematic Geographic Information Systems. Currently, the source of basic data is provided mainly
The DWG data edited by the secondary development software of AutoCAD has encoding rules to distinguish different features. Therefore, it is necessary to study
Conversion method. In learning other data conversion methods, this paper proposes a new method based on ArcMap built-in VBA.
The DWG classification conversion method is well applied in the data conversion of cadastral surveys in a region in Dalian.
Keyword encoding gis dwg vba Geodatabase data conversion
Chinese map: P208 Document ID code: B Article No.: 1672-4097 (2007) 04-0037-03
This article is based on the DWG data drawn by kaisi in a region in Dalian.
For example
For example, convert a data type to a shape data format.
Data format: describes the current conversion method. Based on the work of the author,
Use ArcMap's built-in VBA to classify and convert DWG data
The principle and conversion process of changing to shape data are also critical.
Code .
1. General Data Conversion Method
111 arc toolbox Conversion Method
ESRI's arc toolbox software provides powerful
Information processing function to provide solutions for different types of tasks
Path. Main tools include: data management tools, analysis tools, conversion engineers
Tools and custom tools (my tool S ). In the arc toolbox, first
Convert DWG to Geodatabase data format and select "con2"
Version tools (Conversion Tool)-> Import to geodata2
Base-> CAD to Geodatabase ";
Convert to shape format and select "Conversion Tool S (Conversion Engineer
With)-> Import to shapefile-> Geodatabase
Shapefile ". This conversion simply converts DWG data
Point, line, and surface cannot achieve classification and extraction.
Results required by the user.
112 switch using other software
Currently, many GIS software can also convert data, such
Supermap worker pro. There are also dedicated Data Conversion
FME software, which can implement more than 100 types of GIS and CAD
Data formats, such as DWG, DXF, dgn, shape file,
ArcSDE and so on. However, for professional data
Software management is generally expensive and complicated data needs to be customized.
For conversion tasks, you need to use personnel to participate in training and learning.
The investment in the project is a lot of money, so this conversion is not
Optional.
2. Use ArcMap built-in VBA to write classification Conversion
Program
The following describes how to use the VBA program
Convert the DWG format data category generated by component editing to shape
Format.
211 Program Design Ideas
21111 understand kensc coding system
Kaisi adopts the classification and encoding rules for objects.
Things are divided by layer, mainly including 10 categories (see table 1). Other layers also
Bound (frame line), axes (axis line), and value (skeleton line)
. Classify and encode different features under each layer
It is described with a 7-digit number and the structure is primary encoding (4-bit + 1-bit)
+ Encoding (2 digits). The first four digits are in accordance with the requirements of the national standard, followed
The 7-bit encoding is stored in the thickness attribute.
For blocks, use different block names for 7 characters.
Number encoding.
21112 create a conversion File
Build DWG data and
Shape conversion file (zhwj. t XT ). Format: type, type
Property field, property value, and shape file name. 1. File description:
① Convert the text attribute values in the vertex data into gc113 and gc200
To Cl KZD. SHP (Measurement Control Point) ② put thick2 in the line data
The property value of Ness is 3231000 and 3232000 to xzdw.
SHP (linear feature) ③ set the thickness attribute value in the surface data
Transfer 2110100 and 2110200 to mzfw. SHP (area-shaped house)
④ Convert the layer attribute value 002 in the annotation data to TK.
SHP (profile note) ⑤ set the layer attribute value in the note point data
ZJ to zzj. SHP (note ).
212 Procedure and Code Description
21211 procedure
Start ArcMAP, run macros, and read the DWG file.
Select conditions for converting file structure to extract features from DWG data
Convert to the specified shape file. The detailed process is shown in Figure 1 ).
Figure 1 procedure
31211 main program code Description
The program consists of three parts: reading a DWG file and reading
Convert the file, select and maintain the file to the shape according to the conversion file category
File. Due to space limitations, the following section describes the main code.
(1) read the DWG file.
Set pworkspace = pcadwksfact. openfromfile
(DWG-path, 0) '/sets the DWG file path/
Set P featuredataset = pworkspace. openfeaturedataset
(DWG-name) '/open the DWG feature data/
Set P featureclasscontainer = P featuredataset
For Count = 0 to P featureclasscontainer. classcount
-1'/classification feature data/
Escape '/Code omitted, read DWG data, generate vertex D, vertex Z, line
X, face M featurelayer/
Next count
Pmxdoc. updatecontent s'/refresh display/
(2) read the conversion file.
Open "zhwj. txt" for input as # 1'/Open Conversion
File/
Do while not EOF (1) '/number of reads from the conversion file in a loop
In group zh/
Input #1, ZH (number, 1), ZH (number, 2 ),
Zh (number, 3), ZH (number, 4)
Number = Number + 1'/loop to the next row of the array/
Loop
Close #1 '/Close the conversion file/
(3) Select Based on the Conversion file category and store it as shape
File, and add attributes according to the Liaoning Province urban cadastral data library standards
Field.
Set pmxdoc = application. Document '/get focus Map
Object/
Set pmap = pmxdoc. focusmap '/set the current activity view/
'/Create a new space bookmarks object and set it to the Focal Point
Current visible range of the graph/
Set pactiveview = pmap
For I = 1 to number-1 '/store the converted file cyclically by row
Array/
Select case ZH (I, 1) '/According to the first column of the array/
Case "Z" '/If ZH (I, 1) = "Z/
Set P featurelayer = pmap. layer (0)
Set P featureselection = P featurelayer '/specify Query
The query layer is the note Layer/
Case "M" '/If ZH (I, 1) = "M", the query layer is
Surface Layer (Code omitted )/
Case "X"/If ZH (I, 1) = "X", the query layer is
Line layer (Code omitted )/
Case "D" '/If ZH (I, 1) = "D", the query layer is
Point layer (Code omitted )/
End select'/end of the statement
Set pqueryfilter = new queryfilter '/query filter/
Pqueryfilter. whereclause = "" + zh (I, 2) + "=" + zh
(I, 3) + "" '/create a query filter/
'/The following shape file exists, does not exist, and must be added to the cadastral map
Insert the selection result/
If check-for-shapefile (path, ZH (I, 4) = false then
'/Define a function by yourself, create a shape file in the specified path, and add
Fields required for cadastral encryption/
Fun-create-addfield (PATH)
End if
Set pnewfeatureclass = P targetworkspace. openfea2
Tureclass (ZH (I, 4) '/open the shape/
Set pcursor = P featureclass. Search (pqueryfilter,
False) '/execute the selection to obtain the selection pointer/
Set P feature = pcursor. Next feature '/cursor pointer
Above the first position/
Do until (P feature is nothing) or (babort) '/select
Not blank. Traverse elements by pointer/
Set P Geom = P feature. shapecopy
Set pbuffer. Shape = P Geom '/space for retrieving Elements
Range/
For I = 0 to P feature. Fields. fieldcount-1 '/Return
Number of returned fields/
'/Code omitted, attributes and values of elements selected cyclically/
Next
P insert. Insert feature pbuffer '/insert to shape
File/
Set P feature = pcursor. Next feature '/cursor pointer
Move to the next location/
Loop '/return to do statement/
Next '/move to the next row of the array/
213 program running result
The conversion file is based on the urban cadastral data of Liaoning Province.
The conversion program is used to classify the image.
Conversion, and added attribute fields using the program.
38 current generation test drawing 30th volumes
Standards for building urban cadastral data in Liaoning Province.
3 conclusion
This conversion method uses the built-in ArcMap VBA program
Sort, convert DWG data directly to categories based on the Conversion File
By layer, color ),
Linear (linetype), thickness (thickness), block name (text), etc.
For classification conversion, you can also extract part of the data you are interested in.
Users do not need to understand the storage format of DWG data, but only need to edit the conversion
File, the program can extract different data according to the conversion File
And convert to shape format. This program has been verified and completed
Good results. Therefore, the conversion of DWG to shape data is required.
.
References
1 xue wei. MapObject Geographic Information System Program Design [M]. Beijing: China
Anti-Industry Press, 2004
2 Tian pengbo, Liu Qing. Topographic Map conversion from AutoCAD to map info [J].
City Survey, 2003 (1): 32-34
3 LIU Guang, Liu Xiaodong. tutorial on Secondary Development of Geographic Information System-VB. NET and
Implementation of MapObject [M]. Beijing: Tsinghua University Press, 2004
4. Use VBA to develop the AutoCAD application [M]. Beijing: person
Min post and telecommunications Press, 1999: 97-145

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.