Location Hub Viewer API

Location Hub Viewer API

Location Hub® Viewer

Location Hub Viewer is an easy-to-use online web application that allows you to visualize your customers, prospects, physical assets, and retail locations on a map. When combined with DMTI Spatial’s robust data offering, you can better manage risk, increase operational efficiency, identify new prospects, and improve business performance.

Location Hub Viewer API

The Location Hub Viewer API provides developers with the ability to access and control data uploaded and stored in the Location Hub Viewer Platform.

The following two services are available:

Authentication

The Location Hub Viewer API utilizes Basic Authentication for authorization and access of the services. Basic Authentication sends a Base64 encoded string that contains a user name and password for the client via HTTP headers. Base64 is not a form of encryption and should be considered the same as sending the user name and password in clear text. However, all traffic is encrypted and transmitted over a TLS v1.2 (Transport Layer Security) connection, and therefore the user name and password is protected during transmission.

Point in Polygon Service

Point in Polygon Service

The Location Hub Viewer Point in Polygon Service processes a geographic coordinate and quickly returns the region (KML polygon) the point falls within along with the attributes of the polygon. Developers can query any KML polygon layer that has been uploaded and stored in the Location Hub Viewer platform.

What does it do?

The Location Hub Viewer Point in Polygon service allows users to determine whether or not a location is within a Location Hub Viewer polygon layer (region, sales territory, risk zone, etc.) by passing a geographic coordinate of the location to the service. The polygon layer must have been uploaded as a KML layer and stored in the Location Hub Viewer platform and the name of the KML file must be provided as an input parameter. The input coordinates must be in Latitude and Longitude WGS84 projection.

The Location Hub Viewer Point in Polygon service returns a GeoJSON feature collection of zero, one, or multiple polygons from the given layer which contain the given coordinate. Each polygon will contain the geometry of the polygon, as well as all the attributes associated to the polygon. Please see http://geojson.org/ for full specifications of the GeoJSON format.

The Location Hub Viewer Point in Polygon service is only available using REST. SOAP/XML is not supported.

Accessing the Service

To access the Location Hub Viewer Point in Polygon service you must first be authorized for use with the Location Hub Viewer product in order to have a valid user name and password. Please contact info@dmtispatial.com for more information on how to register for the Location Hub Viewer Point in Polygon Service.

Once you have a valid user name and password, please refer to the Basic Authentication section for information on how to access the service.

REST Service

REST Operation

The following Point in Polygon service request is available through REST only:

  • GetFeatures?layer={layer}&lat={lat}&lon={lon}: Accepts a layer name and a single coordinate location as input and returns the polygon geometry at that coordinate in GeoJSON format along with all of its attributes.
    • layer (string): The name of the polygon layer to query against
    • lat (double): The WGS84 latitude of the location specified
    • lon (double): The WGS84 longitude of the location specified

Errors Messages

The Location Hub Viewer Point in Polygon service will return all errors through the following standard HTTP status codes:

  • 401 Unauthorized
    • This error code will be returned when the service was unable to authenticate the user. Make sure that the proper user name and password was provided through the HTTP header.
  • 400 Bad Request
    • This error code will be returned when the parameters provided to the services are not properly formatted.
  • 404 Not Found
    • This error code will be returned when the service was unable to find the layer name provided.
  • 200 OK
    • This code will be returned, along with the GeoJSON feature collection when successful.
    • Note that an empty feature collection will be returned if point does not lie within any polygons.

Examples:

<!-- REST Request -->
https://<PointInPoly_url>/services/v1/GetFeatures?layer=FSA_Ontario.kml&lat=43.850174&lon=-79.363277
 
<!-- REST Responses in JSON -->
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "1",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -79.325408,
                            43.88045
                        ],
                        [
                            -79.326918,
                            43.880751
                        ],
                        ...
                        ...
                        ...
                        [
                            -79.325408,
                            43.88045
                        ]
                    ]
                ]
            },
            "properties": {
                "UID": "324DC175-49A9-4AFF-8385-A99B1E3167F4",
                "FSA": "L3R",
                "PROV": "ON",
                "LONGITUDE": "-79.3125234675381",
                "LATITUDE": "43.8655324729781",
                "VINTAGE": "2015.2"
            }
        }
    ]
}

File Management Service

File Management Service

The Location Hub® Viewer File Management Service provides the ability to manage KML polygon layers in the Location Hub Viewer application. The service allows you to upload and delete KML files, as well as get a list of layers available within Location Hub Viewer.

Accessing the Service

To access the Location Hub Viewer File Management service you must first be authorized for use with the Location Hub Viewer product in order to have a valid user name and password. Please contact info@dmtispatial.com for more information on how to register for the Location Hub Viewer File Management Service.

Once you have a valid user name and password, please refer to the Basic Authentication section for information on how to access the service.

REST Service

REST Operations

The following File Management service requests are available through REST only:

  • GetSearchableLayers: Returns the list of all layers available to the authenticated user within Location Hub Viewer application.
  • GetLayerStatus?layer={layer}: Get the current status of the specified layer.
    • layer (string): The name of the layer to be queried. One of the following status codes may be returned:
      • Nonexistent: The service cannot find the layer specified
      • Ready: The layer specified has a spatial index created and is available for use in the Point in Polygon Service
      • Creating: The layer specified exists in Location Hub Viewer but the system is currently building the spatial index for the layer
      • Possible: The layer specified exists in Location Hub Viewer but the spatial index for the layer has not been created. This file cannot be used in the Point in Polygon Service
  • UploadFile?layer={layer}&ft={ft}: Upload a file as a layer in one chunk. The HTTP POST body contains the file stream. Use this method if the file size is less than 4MB. There is no need to call the UploadFinish method after using this method.
    • layer (string): The name of the polygon layer (KML File Name) to be uploaded.
    • ft (string): The file type of the polygon layer to be uploaded. Only “kml” is currently supported. HTTP Status Code 501 Not Implemented will be returned if the file type is not “kml”.
  • UploadChunk?layer={layer}&ft={ft}&chunk={index}: Upload a file as a layer in multiple chunks. The HTTP POST body contains the file stream. Use this method to upload files that are larger than 4MB. The size of each chunk should not exceed 4MB.
    • layer (string): The name of the polygon layer (KML File Name) to be uploaded in chunks.
    • ft (string): The file type of the polygon layer to be uploaded in chunks. Only “kml” is currently supported. HTTP Status Code 501 Not Implemented will be returned if the file type is not “kml”.
    • chunk (integer): The index (or sequenced id) of the current file chunk to be uploaded.
  • UploadFinish?layer={layer}&ft={ft}&size={size}: Complete the file upload process. This method must be used after uploading a file in multiple chunks. This method will also perform any post processing that is required for the uploaded layer, such as creating the spatial index.
    • layer (string): The name of the polygon layer (KML File Name) that was uploaded in chunks.
    • ft (string): The file type of the polygon layer that was uploaded in chunks. Only “kml” is currently supported. HTTP Status Code 501 Not Implemented will be returned if the file type is not “kml”.
    • size (integer): The total size in bytes of the file that was uploaded in chunks. This is to verify that the service received the complete file. HTTP Status Code GetSearchableLayers
      Conflict will be returned if the file size does not match.
  • DeleteLayer?layer={layer}: Delete the specified layer form the Location Hub Viewer application and all files that were created from the specified file.
    • layer (string): The name of the layer to be deleted from Location Hub Viewer. HTTP Status Code 404 Not Found will be returned if the layer is not found.

HTTP Status Codes Returned:

Below are the Status Codes returned from the File Management Service:

  • 200 OK
    • This code will be returned when the service request is successful, such as the file has been successfully uploaded and stitched back together.
  • 400 Bad Request
    • This error code will be returned when the parameters provided to the services are not properly formatted.
  • 401 Unauthorized
    • This error code will be returned when the service was unable to authenticate the user. Make sure that the proper user name and password was provided through the HTTP Authorization header.
  • 404 Not Found
    • This error code will be returned when the service cannot find the layer or file name specified.
  • 409 Conflict
    • This error code will be returned when the value of the size parameter does not match the total size of the file received by the server when uploading the file in chunks.
  • 501 Not implemented
    • This code will be returned when the file type provided is not supported. At the moment, only “kml” is supported.

Examples:

GetSearchableLayers

<!-- HTTP GET REST Request (GetSearchableLayers) -->
<!-- https://lhviewer.dmtispatial.com/services/v1/GetSearchableLayers -->
 
GET https://lhviewer.dmtispatial.com/services/v1/GetSearchableLayers HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: Basic ************************
Host: lhviewer.dmtispatial.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
 
<!-- HTTP Response with JSON (GetSearchableLayers) -->
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 392
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 16 Sep 2015 20:33:32 GMT
 
[
   "LDU_Ontario.kml",
   "FSA_Ontario.kml",
   "SalesTerritories.kml",
   "Insurance_Policies_Clean.csv",
   "Insurance_Policies.csv"
]

GetLayerStatus

<!-- HTTP GET REST Request (GetSearchableLayers) -->
<!-- https://lhviewer.dmtispatial.com/services/v1/GetLayerStatus?layer=FSA_Ontario.kml -->
 
GET https://lhviewer.dmtispatial.com/services/v1/GetLayerStatus?layer=FSA_Ontario.kml HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: Basic ************************
Host: lhviewer.dmtispatial.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
 
<!-- HTTP REST Response with JSON (GetLayerStatus) -->
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 7
Content-Type: application/json
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 16 Sep 2015 21:08:59 GMT
 
"Ready"

DeleteLayer

<!-- HTTP GET REST Request (DeleteLayer) -->
<!-- https://lhviewer.dmtispatial.com/services/v1/DeleteLayer?layer=FSA_Ontario.kml -->
 
GET https://lhviewer.dmtispatial.com/services/v1/DeleteLayer?layer=FSA_Ontario.kml HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: Basic ************************
Host: lhviewer.dmtispatial.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
 
<!-- HTTP REST Response with JSON (DeleteLayer) -->
HTTP/1.1 200 OK
Cache-Control: private
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 16 Sep 2015 21:30:32 GMT
Content-Length: 0

Uploading a File

The example below shows you how to upload a large file using javascript:

// Assume the following HMTL elements are on a page
    <div class="block" title="Upload a polygon KML file">
        <label style="float: left;">Upload file: </label>
        <form id="upload" enctype="multipart/form-data" method="post">
            <input style="float: left; margin-left: 5px;" type="file" id="file" size="50" />
            <input type="submit" id="uploadbtn" value="Upload" />
        </form>
    </div>
 
// javascript code to handle uploading file after clicking the Upload button
            $("#upload").on('submit', function (event) {
                var filepath = $("#file").val(); //from the File Input div element above
                var index = filepath.lastIndexOf("\");
                var authentication = getAuthorization(); //get the Base64 encoded authentication string
 
                if (index < 0) {
                    index = filepath.lastIndexOf("/");
                }
                if (index >= 0) {
                    var filename = filepath.substring(index + 1);
 
                    var filetype = "KML";
                    index = filename.lastIndexOf(".");
                    if (index >= 0) {
                        filetype = filename.substring(index + 1);
                    }
                    var chunksize = 4 * 1024 * 1024;
                    var filesize = file.size;
                    var counter = 0;
                    if (filesize < chunksize) {
                        // upload file in one chunk
                        Uploadchunk(filename, filetype, filesize, file, -1);
                    } else {
                        // upload file in multiple chunks
                        var start = 0;
                        var end = chunksize;
                        var chunkindex = 0;
                        while (start < filesize) {
                            var chunk = file.slice(start, end);
                            Uploadchunk(filename, filetype, filesize, chunk, chunkindex++);
                            start = end;
                            end = start + chunk.size;
                        }
                    }
 
                    function Uploadchunk(filename, filetype, filesize, chunk, index) {
                        var url = index > -1 ?
                            "/services/v1/UploadChunk?layer=" + filename + "&ft=" + filetype + "&chunk=" + index
                            : "/services/v1/UploadFile?layer=" + filename + "&ft=" + filetype;
 
                        $.ajax({
                            type: 'post',
                            url: url,
                            data: chunk,
                            beforeSend: function (jqXHR, settings) {
                                jqXHR.setRequestHeader("Authorization", authentication );
                            },
                            success: function () {
                                if (index > -1) {
                                    counter++;
                                    if (counter == Math.floor(filesize / chunksize) + 1) {
                                        var url = "/services/v1/UploadFinish?layer=" + filename + "&ft=" + filetype + "&size=" + filesize;
 
                                        $.ajax({
                                            type: 'get',
                                            url: url,
                                            beforeSend: function (jqXHR, settings) {
                                                jqXHR.setRequestHeader("Authorization", authentication );
                                            },
                                            success: function () {
                                                // File upload complete
                                            }
                                        });
                                    }
                                } else {
                                    // File upload complete
                                }
                            },
                            error: function (err) {
                                ; //handle errors
                            },
                            processData: false,
                            contentType: file.type
                        });
                    }
                }
            });

Basic Authentication

Basic Authentication

The Location Hub® Viewer API utilizes Basic Authentication for authorization and access of the services. Basic Authentication sends a Base64 encoded string that contains a user name and password for the client via HTTP headers. Base64 is not a form of encryption and should be considered the same as sending the user name and password in clear text. However, all traffic is encrypted and transmitted over a TLS v1.2 (Transport Layer Security) connection, and therefore the user name and password is protected during transmission.

The user credentials are sent using the HTTP Authorization header. The header is constructed as follows:

  • Concatenate username and password into a string with a colon between as shown: “username:password”
  • Encode the resulting string in a Base64 variant
  • Prefix the encoded string with “Basic ”; the space after Basic is required

These encoded credentials are then sent in the HTTP Authorization header with every Location Hub Viewer API request.

 

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
 
namespace BasicAuthenticationTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string requestURL = "https://the.service.url/v1/";
            string serviceMethod = "GetRequest";
            string username = "YourUserName";
            string password = "YourPassword!";
 
            Console.Out.WriteLine();
            Console.Out.WriteLine("Request Url: " + requestURL);
 
            WebRequest request = WebRequest.Create(requestURL + serviceMethod);
            WebResponse response = null;
            try
            {
                if (username != null)
                {
                    string authInfo = username + ":" + password;
                    authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                    Console.Out.WriteLine("Base64 Encoded String: " + authInfo);
                    request.Headers["Authorization"] = "Basic " + authInfo;
                }
 
                response = request.GetResponse();
 
                Console.Out.WriteLine("Response Header:");
                foreach (var header in response.Headers)
                {
                    Console.Out.WriteLine("t" + header + " = " + response.Headers[header.ToString()]);
                }
 
            }
            catch (WebException ex)
            {
                Console.Out.WriteLine("HTTP Status: " + ex.Message);
            }
            finally
            {
                if (response != null)
                {
                    Console.Out.WriteLine("HTTP Status: " + ((HttpWebResponse)response).StatusCode);
                    response.Close();
                }
                Console.ReadLine();
            }
        }
    }
}