Blogs

DK for ASPNET - Easy way to publish REST services

The DK.ASPNET can be used to easily create REST services exposing the full TatukGIS functionality using JSON encoding.

A sample REST project, demonstrating reprojection between coordinate systems, can be tested here

The code behind the Geometry/Project sample:

  1. <%@ Page Language="VB" Debug="True" %>
  2. <%@ Import Namespace="TatukGIS.Web.Extensions.Rest" %>
  3. <%@ Import Namespace="TatukGIS.NDK" %>
  4.  
  5. <!DOCTYPE html>
  6.  
  7. <script runat="server">
  8.   Function DoRest(_context As RestHelper) As Object
  9.     Dim geo As JsonGeometry
  10.     Dim res As JsonGeometry
  11.             
  12.     Dim i_from_cs As Integer = _context.ParamAsInteger("FromCS")
  13.     Dim i_to_cs As Integer = _context.ParamAsInteger("ToCS")
  14.     Dim s_geo As String = _context.ParamAsString("Geometry")
  15.             
  16.     Dim from_cs As TGIS_CSCoordinateSystem = TGIS_CSFactory.ByEPSG(i_from_cs)
  17.     If from_cs.EPSG = 0 Then
  18.       Throw New Exception("'FromCS' is unknown")
  19.     End If
  20.            
  21.     Dim to_cs As TGIS_CSCoordinateSystem = TGIS_CSFactory.ByEPSG(i_to_cs)
  22.     If to_cs.EPSG = 0 Then
  23.       Throw New Exception("'ToCS' is unknown")
  24.     End If
  25.  
  26.     If from_cs.EPSG = to_cs.EPSG Then
  27.       _context.Message = "'FromCS & 'ToCS' represent same CS"
  28.     End If
  29.  
  30.     Try
  31.       geo = _context.FromJson(Of JsonGeometry)(s_geo)
  32.     Catch ex_tmp As Exception
  33.       Throw New Exception("Bad 'geometry'. " + ex_tmp.Message)
  34.     End Try
  35.                           
  36.     If (geo.Value Is Nothing) Or (geo.Value.IsEmpty) Then
  37.       Throw New Exception("'Geometry' is null or empty")
  38.     End If
  39.  
  40.     Dim la As TGIS_LayerVector = New TGIS_LayerVector()
  41.     la.CS = from_cs
  42.     la.Open()
  43.     Dim shp_tmp = la.AddShape(geo.Value)
  44.     res.Value = shp_tmp.CreateCopyCS(to_cs)
  45.       
  46.     Return res
  47.   End Function
  48.     
  49.   Sub Page_Load()
  50.     Dim rest As New RestHelper( AddressOf DoRest )
  51.   End Sub
  52. </script>
  53.  
  54. <head runat="server">
  55.   <title>Rest - Project</title>
  56. </head>
  57. <body>
  58.   Usage etc.
  59. </body>
  60. </html>
 
Posted: December 30, 2013
Filed under: ASP.NET, DK, IS, WMS