Community of VE/MapPoint Users and Developers
This is a discussion on Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (6/6) within the Virtual Earth Blogs forums, part of the Blogs category; Inserting data into SQL Server 2008 In the previous parts we have first been looking on the database side and ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (6/6) Inserting data into SQL Server 2008In the previous parts we have first been looking on the database side and how we can use various mechanisms to load and extract data and we even implemented a geocoder in the database. Then we moved on and investigated various ways to retrieve data from SQL Server 2008 and visualize them in Virtual Earth. In this final part we will now focus on using Virtual Earth as a simple data editor which allows us to write data back to SQL Server 2008. We will implement the data editor in form of a query builder. In the user interface we will have some drawing tools which allow us to draw points, lines, polygons and circles on the map and to store them temporarily in our browser window. Each of the temporarily stored geographies will have a checkbox next to it and when we check these boxes we will dynamically create a SQL statement which automatically determines the appropriate feature-type. The SQL-statement will be displayed in a textarea and we will be able to manually edit it. Once we click on the image with the SQL Server logo we will create an AJAX-call which sends the SQL-statement via HTTP-Post request to a HTTP handler and this handler will actually execute the statement. Let’s start with a fresh table in our SQL Server. We create a table with a column of type geography. CREATE TABLE [FeatureDemo] In our ASP.NET page we first add a new accordion pane. This pane first displays a notice which reminds you that drawings which shall be added as a geography data type to the database must be drawn counter-clockwise. It also hosts buttons to draw various types of geographies and textboxes which will display the latitude and longitude under the mouse-cursor. In the “Geometry”-section it provides 2 links: delete all drawings and reset the SQL statement in the textarea. Finally there is an empty DIV-element in which we will temporarily store our drawing objects with a checkbox next to them: <cc1:AccordionPane ID="paneQueryBuilder" runat="server"> We will also need some more DIV-elements for the interaction with our geographies as well as the visualization and the editing of our SQL statement. Below you find the ASP.NET sources for a textarea where the SQL statement will be displayed, a clickable image which allows us to execute the AJAX-call as well as 2 elements which display the length of polylines and polygons while we draw as well as a dialog which allows us to enter the title and description of a geography. <textarea id="txtSQL" rows="2" style="position:absolute; left:300px; bottom:5px; width:300px; height:94px" >textarea> If we click a button to draw a geography we change the cursor to a crosshair and attach an onclick- and an onmousemove-event to the map. While we move the mouse we continuously update the latitude and longitude in the textboxes on the accordion pane. When we click with the left mouse-button we add a point to our temporary geography. If the geography is a polyline or polygon we will also determine the length of the line. For a circle the value in the divDistance will be the radius. To finish the drawing we will hit the right mouse-button. This will detach the map-events and also bring up the divShapeInfo so that we can enter a title and a description. The distance will automatically be added to the shape. When we click on “Set” in the dialogue above we will add the geography to our divGeom in the accordion pane. Next to the geography we have a checkbox and a JavaScript-function will update the textarea txtSQL with a statement appropriate for the selected geometries. For example if we have a polygon the statement will reflect that, if we have 2 polygons the statement will show a MULTIPOLYGON and if we have 2 polygons and a point the statement will show a GEOMETRYCOLLECTION. The drawing part on top of Virtual Earth leverages a couple of events which can be attached to the Virtual Earth Map and I published the complete code on Via Virtual Earth. So I don’t want to go into detail for this part. [I just noticed that this sample has been removed so now you'll find it here]. The major difference between the code on “Via Virtual Earth” and the code in this sample application is that we create an additional checkbox with an onclick-event attached. Once we activate the checkbox we call a function to update the SQL statement in the textarea: function SetInfo() Updating the SQL-statement in the textarea requires first to determine the types of the VEShape-objects which have been activated. function UpdateSQLQuery(id) Now we determine which type of geography in SQL Server 2008 matches our selection. if (pointCount == 1 && polylineCount == 0 && polygonCount == 0) geomType = "POINT"; Finally we create our SQL-statement. switch (geomType) Now that we have drawn our geographies and dynamically created our SQL-statement we only need to execute it. As in previous examples we will use an AJAX-call but unlike in the previous examples we will use an HTTP-Post request since the SQL-statements with all the coordinates can become quite long. function SqlInsert() The HTTP-handler which is being called by the AJAX-call is even simpler than anything we had before. We just fetch the SQL-statement from the, set up the database connection and execute the statement. A message will be returned to the AJAX-call to indicate success or possible problems with the statement. 'Fetch URL-parameter All right, we’re done. Run your page and test it. You can also retrieve the results within SQL Server Management Studio... SELECT Geom.STAsText() FROM FeatureDemo …and do further analysis like determining the size of the area which is covered by a polygon. SELECT Geom.STArea() FROM FeatureDemo WHERE ID = 4 Note: Polygons must be drawn counter clockwise and each polygon figure must be within a single, logical hemisphere. Individual spatial objects do not need to be within the same logical hemisphere in order to run spatial operations between them. * Technorati Tags: Virtual Earth,SQL Server 2008 ![]() ![]() Click here to view the article. Last edited by Eric Frost; 03-22-2008 at 05:54 PM. |
![]() |
| ||||
| Posted By | For | Type | Date | |
| The Magazine for MapPoint - MP2K Magazine | This thread | Refback | 03-27-2008 08:42 AM | |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (6/6) - MapPoint Forums | This thread | Refback | 03-26-2008 05:57 PM | |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (6/6) - MapPoint Forums | This thread | Refback | 03-26-2008 05:57 PM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (4/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-03-2008 12:51 PM |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (3/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 03:52 PM |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (2/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 03:52 PM |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (1/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 03:52 PM |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (3/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
Cheap Flights Paphos
Have a fantastic holiday in Paphos. Enjoy the lively seafront atmosphere and the picturesque mediaeval port. Book cheap flights online at Holiday Hypermarket.
Italy Holidays
Find and book Italy Holidays with Travel Counsellors. Holiday destinations around the world including Italy.
Holiday in Turkey
A Holiday in Turkey is great value when you book with dealchecker.co.uk. There is an abundance of things to see and do. Check out the well-preserved Greco-Roman ruins.
Holidays in Egypt
A holiday in Egypt will stimulate your mind, captivate your heart and spark your senses. Visit this exceptional country, book today!
Cyprus
Before visiting Cyprus, make sure you are well informed to make the most of your holiday. Online at ulookubook.com you check out our useful travel guides. Find out all about the Cyprus nightlife, shopping, eating and customs.
All inclusive holiday
Travel.co.uk is a travel comparison service which makes it easy to search and find your all inclusive holiday.
Holidays in Goa
Want to know more about Indian culture? Visit On The Beach for information on holidays in Goa.