Join Gordon Luckett for an in-depth discussion in this video Understanding SQL Server spatial geometry, part of Using SQL Server Spatial with AutoCAD Map 3D.
- View Offline
- Understanding out SQL Server stores spatial data, such as geometry, is key to knowing how AutoCAD Map 3D will store that same data. We'll use the SQL Server Management Studio to create databases, tables, and to edit that information directly within SQL Server. Let's begin. First, we're gonna login to Microsoft SQL Server Mangement Studio. You have to know the name of your SQL server. In this case, it's littleSQLthatcould. The login is "sa" which stands for system administrator. And I have to put in the system administrator password.
Let's connect now. Under databases, there's no databases. So I have to quickly create a new one. Simply, right-click on Databases and click New Database. I'm gonna call this database, "TEST" for now. And click OK. That should create a brand new blank database. There are no tables. Next, we'll go into our Exercise Files. And we'll double-click on create_table.sql Make sure that your database is listed at the top, TEST. This will insert a brand new table with three columns: an ID, a geometry type, and a geometry itself.
So let's click Execute. This should create a brand new table. So, let's expand Tables. And you'll see a SPATIAL_TABLE. Again, if I expand that and look at the columns, you'll see an ID, a geometry type, and a geometry itself. Next, we'll go into Exercise Files and double-click on the insert.sql This will insert points, lines, and polygons into that same table. So we're gonna insert two values, just a string that's called "point" in the first item.
And the point will be inserted at 50 X and 50 Y. So the 50 50, meaning at X 50 and Y 50, will be inserted. In terms of the second item, we are going to insert a linestring from point 100 100, to 100 200, to 200 200. So it should be an L-shaped line. Finally, we're gonna create a polygon in the table and this one, we'll be using the polygon command. Now, you notice the first item says POINT with two brackets and 50 50, same with the linestring.
But the polygon has double brackets at the beginning. So that's a syntactical change that you'll have to watch for. Let's run this. It should insert three different rows. If we now right-click on the SPATIAL_TABLE, select 1000 Rows, we are able to see the three records we just inserted. A point, a linestring, and some polygons. Now there is a tab inside of Management Studio that allows you to preview what the graphics look like. Click on Spatial results, you should now see the point, the line, and the polygon inside of Management Studio.
You've learned how to insert records manually into SQL Server and how to view that spatial data. Although there are only two spatial datatypes, geometry and geography, we will focus mainly on geometry. Since that is the only type AutoCAD Map 3D supports.
Before you begin this course, we recommend watching AutoCAD Map 3D Essential Training for a solid understanding of the program.