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 (3/6) within the Virtual Earth Blogs forums, part of the Blogs category; Using Spatial-Methods Now we will start using spatial methods in SQL Server 2008. We will extend the previous example ...
| |||||||
| 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 (3/6) Using Spatial-MethodsNow we will start using spatial methods in SQL Server 2008. We will extend the previous example where we mapped occurrences of “Foot and Mouth Disease” (FMD) in a way that we can analyse the outbreak. We want to be able to map the area that has been infected after the 1st day, after the 2nd day and so on. SQL Server 2008 has a number of methods which will support this scenario. Ultimately we need to create a CONVEXHULL, i.e. the smallest convex polygon that contains the given geometry instance. The method to use is STConvexHull and it can be applied to any geometry but if applied to a POINT or a LINESTRING it will return a geometry of the same type. In our case we have multiple points which represent the occurrences of FMD and we have to aggregate them into a MULTIPOINT first before we can apply the STConvexHull function. We can create such a MULTIPOINT by opening a cursor which returns all the points representing infections before a key date. While we loop through this cursor we use the STUnion method to aggregate the single points into a single MULTIPOINT. This logic is implemented in a stored procedure as shown below: CREATE PROCEDURE GetConvexHull @UpTo nvarchar(11) The result of the stored procedure will be a string representing a polygon like the following: POLYGON ((51.594378140755 0.2863533329218626, 51.590768386609852 0.31522062048316, 51.556323000229895 0.24923799932003021, 51.594378140755 0.2863533329218626)) You probably noticed that we aren’t using the original spatial-column Geom but a column Geom2. Why is that? Not all spatial functions are available for both the geography and the geometry data type but fortunately it is pretty simple to convert between the two. In our example the method STConvexHull can only be applied to a geometry data type and not to the geography data type we used before. We could have used the geometry data type right from the start but we wanted to demonstrate how you can easily create a geometry from a geography. Consequently, we added a new column, Geom2, of type geometry and simply execute the following SQL statement: UPDATE FMD Now that we have extended our database schema and added a stored procedure, we will add the function to our application. First we add another checkbox and a textbox to our accordion pane “VEShape-Objects”. The function that will be executed when we check the checkbox shall be AddFMDArea: <input id="cbFMDArea" type="checkbox" onclick="AddFMDArea('cbFMDArea')"/><a href='javascript:ShowLocation(54.41893, -3.735352, 6);'>FMD-Areaa><br /> It is probably a good idea to add the polygon to a new VEShapeLayer, so we define a new global variable in our javascript: //VEShape-Objects When we check the control we build a URL which contains a relative path to another HTTP-handler (VEShapeFMDArea.ashx) and adds a parameter “upto”. This parameter is retrieved directly from the textbox in our accordion pane and represents the end date for the aggregatation of the FMD infections. As before, we then determine the XMLHTTP-object that can be used in our browser and execute the AJAX-call asynchronously. Now we wait for the HTTP-handler to respond with a JavaScript which will then be executed using the eval-function: function AddFMDArea(control) In the HTTP-Handler we set the culture again to make sure we don’t get into trouble with the decimal separators in the latitudes and longitudes, as mentioned before. Then we retrieve the target date from the URL-parameter, prepare our database connection and execute the stored procedure GetConvexHull. As a result, we receive a polygon object in string format and we can now use some string manipulation methods to create a JavaScript which will add this polygon to our Virtual Earth map: 'set culture to en-UK to avoid potential problems with decimal-separators We can now compile the code and compare the results for 2 different days. You can clearly see that the infection started at the east coast of England and after only 4 days it already reached the west coast of Wales. (to be continued) Technorati Tags: Virtual Earth,SQL Server 2008 ![]() ![]() Click here to view the article. Last edited by Eric Frost; 03-03-2008 at 08:18 AM. |
![]() |
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 3: Getting Started with Virtual Earth | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 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 |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (2/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (1/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
| Virtual Earth & SQL Server 2008 - Part 1: Introduction (1/2) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 07:30 AM |
Cheap Flight to Tenerife
Get a cheap flight to Tenerife and a cheap hotel in Tenerife giving you a great value holiday in Tenerife. Holiday Hypermarket can make it happen.
Honeymoon Holidays
Book your Honeymoon holiday with Travel Counsellors. A personal advisor will help you plan the perfect honeymoon holiday.
Holidays to Thailand
The best cultures and backgrounds make Thailand an interesting and memorable country to visit. Book great value holidays to Thailand online at dealchecker.co.uk.
Barbados Holidays
Barbados holidays can be a wonderful break from the rat race or an exciting, action packed adventure. Plan the perfect holiday in Barbados.
Holidays
For bargain holidays to destinations including Mexico, South Africa, India and more, visit ULookUBook online today. Check out our free travel guides to help you make an informed decision for your holidays.
Travel Tickets
Travel tickets need not always be expensive. Check out your best travel comparison site, Travel.co.uk
Holidays in Gran Canaria
Have some fun in the sun on the Canary Islands! See On The Beach for information on holidays in Gran Canaria.