Friday, August 26, 2016

Making GIS shape files with data from AutoCAD to import as maps to Maricopa County DDMSW

We AutoCAD people are going to make the GIS files that Maricopa County DDMSW needs so we don't have to risk our time and our reputation by typing our data into DDMSW.  And we are going to do it from our usual AutoCAD work space. 2017 Update: Open source helper here.
Watch the 12.5-minute video



What DDMSW Needs

DDMSW uses GIS shapes with data (called "maps") for the following maps:

Rainfall
Sub Basin
Soil
Land Use
Tc

Of those, the minimum maps it needs for partial GIS control are:

Rainfall
Sub Basin

Let's start with the minimum, Rainfall and Sub Basin.

New AutoCAD Commands

We will need the following AutoCAD commands you may not already know:

ADESETCRDSYS to set our GIS coordinate system
GEOMAP (optional; requires your free Autodesk A360 login)
ADEDEFDATA to set up tables for our data
ADEATTACHDATA to attach data to our polylines
MAPEXPORT to create GIS shape files

Prepare Your Drawing

Coordinate System

Use the ADESETCRDSYS command to set your drawing GIS coordinate system to Arizona State Plane Coordinates Central Zone NAD 83 International Feet (AZ83-CIF) or whatever is appropriate for your area if you are using this tutorial for other purposes.

If you want, use the GEOMAP command to import a background map to verify your coordinate system or to help you draw.

Layers

Create National CAD Standard (of course!) style layers for your polylines:
C-STRM-DDMS-RAIN cyan, of course!
C-STRM-DDMS-SBAS white

Use the layer names above if you want some scripts below to work unmodified.

Use This Script

Save yourself some work by pasting the lines below to a plain text document file, and save it as ddmsw-rainfall-subbasin-layers.scr.  Then run it using the SCRIPT command.  Or run the open source helper at AutoCAD Wiki.

;----
-layer
thaw
C-STRM-DDMS-RAIN
unlock
C-STRM-DDMS-RAIN
make
C-STRM-DDMS-RAIN
color
cyan

thaw
C-STRM-DDMS-SBAS
unlock
C-STRM-DDMS-SBAS
make
C-STRM-DDMS-SBAS
color
white

thaw
C-STRM-DDMS-LAND
unlock
C-STRM-DDMS-LAND
make
C-STRM-DDMS-LAND
color
green

thaw
C-STRM-DDMS-SOIL
unlock
C-STRM-DDMS-SOIL
make
C-STRM-DDMS-SOIL
color
red

thaw
C-STRM-DDMS-TCON
unlock
C-STRM-DDMS-TCON
make
C-STRM-DDMS-TCON
color
blue


;----

Data Tables

Use the ADEDEFDATA command to set up two tables, Rainfall and SubBasin.  For each table, define the fields that DDMSW requires.  Each field has a data type. We will only need the Character and Real data types.  

The required field names, data types, and their optional descriptions are given below.
Use ADEDEFDATA to define data tables for export to GIS

Rainfall table

BASINID field, Character type, Major Basin getting the Rainfall (01 is the basic name we will use)
RAINID field, Character type, Rainfall data set for the Major Basin (DEFAULT is the basic name we will use)

SubBasin table

BASINID field, Character type, Name of the Major Basin the Sub Basin belongs to (01 is the basic name we will use)
AREAID field, Character type, Name of the subbasin (such as HEC-1 operation name) 
AREASF field, Real type, Size of the Sub Basin (we will leave it as 0 and let DDMSW supply the data)

Use This Script

Save yourself some work by pasting the lines below to a plain text document file, and save it as ddmsw-rainfall-subbasin-defdata.scr.  Then run it using the SCRIPT command. Or run the open source work-flow optimized helper at AutoCAD Wiki.

;----
cmddia
0
adedefdata
new
dummy
dummy1
No description
character
01
no
delete
Rainfall
new
Rainfall
BASINID
Major Basin getting the Rainfall
character
01
yes
RAINID
Major Basin Rainfall data set
character
DEFAULT
no
delete
SubBasin
new
SubBasin
AREAID
6-character-max name
character
999999
yes
BASINID
Parent Major Basin
character
01
yes
AREASF
Size of the Sub Basin
real
0
no
delete
LandUse
new
LandUse
LUCODE
DDMSW Land Use code
character
999
no
delete
Soil
new
Soil
SOIL_LID
DDMSW Soil ID
integer
999
no
delete
TC
new
TC
AREAID
Determined by DDMSW
character
999999
yes
BASINID
Determined by DDMSW
character
01
yes
LENGTH
Determined by DDMSW
real
0.0
yes
USGE
Upstream ground elevation
real
0.0
yes
DSGE
Downsream ground elevation
real
0.0
no
delete
dummy
exit
cmddia
1
;----

Enter Your Data

Draw closed polylines

Draw closed polylines representing your major basin (your rainfall area) and your sub-basins.  Put them on correct layers.

Attach data tables to your polylines

Use the ADEATTACHDATA command to attach the Rainfall table to the Rainfall polyline and the SubBasin table to the SubBasin polylines.

Use This Script

Save yourself some work by pasting the lines below to a plain text document file, and save it as ddmsw-rainfall-subbasin-attachdata.scr.  Then run it using the SCRIPT command. Or run the open source work-flow optimized LISP helper at AutoCAD Wiki.

;----
cmddia
0
ssx

layer
C-STRM-DDMS-RAIN

adeattachdata
Rainfall
attach
no
previous

exit
ssx

layer
C-STRM-DDMS-SBAS

adeattachdata
SubBasin
attach
no
previous

exit
ssx

layer
C-STRM-DDMS-LAND

adeattachdata
LandUse
attach
no
previous

exit
ssx

layer
C-STRM-DDMS-SOIL

adeattachdata
Soil
attach
no
previous

exit
ssx

layer
C-STRM-DDMS-TCON

adeattachdata
TC
attach
no
previous

exit
cmddia
1
;----

Enter data for each polyline

DDMSW will automatically provide some of the data.  The list below indicates which data is filled out later by ddmsw and which is by the user (you) in AutoCAD.

Rainfall: BASINID user, RAINID user
SubBasin: AREAID user, BASINID user, AREASF ddmsw
LandUse: LUCODE user
Soil: SOIL_LIDuser
TC: AREAID ddmsw, BASINID ddmsw, LENGTH ddmsw, USGE user, DSGE user

Highlight the polylines individually or in groups and use the Properties palette to enter their data.
Enter data for each polyline.  Leave AREASF for DDMSW to fill in.

Export to GIS


Use the MAPEXPORT command to export to ESRI shape files.  Or run the Visual LISP helper at AutoCAD Wiki. ESRI shape files are actually a group of similarly named files in a folder.  You will specify the name of the SHP file, but the export will consist of several files.  We will export Rainfall.shp and SubBasin.shp.

Selection Tab

Object type: Polygon
Select objects to export: Select manually the polylines on that layer

Data Tab

Data: Select Attributes..., Object Data, choose the appropriate table, Rainfall or SubBasin

You can, but don't have to Create unique key field.

Options Tab

Check Treat closed polylines as polygons (you must do this; GIS thinks in polygons).

Use in DDMSW

Under the Hydrology menu, Rainfall Ids, Rainfall ID, DEFAULT, Source, choose GIS .

Under the Hydrology menu, Rainfall, paste or browse the folder you exported to and select the appropriate SHP file.  Then click Update.  DDMSW will magically find the rainfall for your area.

Under the Maps menu, Update Hydrology, paste or browse the folder you exported to and select the appropriate SHP file.  Then click Update.  DDMSW will add up the sub basins for their major basin.

Add Soil, Land Use, and Tc

I hope to add Soil, Land Use, and TC in an upcoming post, but it is the same procedure.  You can find the required fields (not all of them are truly required, as we see by the limited three we used from the SubBasin list) by clicking the Required Map Fields button under Hydrology menu, Rainfall or Maps menu, Update Hydrology.

Feedback

Feedback is the best form of payment you can give me.  Please leave mistake reports and questions below.

1 comment:

Nick said...

EXTREMELY interesting HawsTom! I salivate at the thought of discussion of ALL this with you as soon as we both have time.