User Tools

Site Tools


soft:server-apps-gis

GIS Application

This application provides support for geolocate a resource, providing an interfice via django admin and generating a map using Google Maps API.

Geolocation

Base class for introduce geolocation info into a model.

Attributes

  • address
  • geolocation (latitude,longitude)

NodeGeolocation

Attributes

  • ID

Node

The model that has been georeferenciated.

Adding Geolocation to a Resource

This application provides base classes than must be extended to provide GIS capabilities.

  1. models.py: create a new class that inherits from Geolocation adding a new a field to associate with

the related model.

class FooGeolocation(Geolocation):
    foo = models.ForeignKey(FooModel, *options)

- admin.py: extends the base class (django admin TabularInline) providing the associated model (class created in step 1 at models.py, e.g. FooGeolocation). And, after that, hook to the admin iface of the model using Monkey-Patching:

 class NodeGisInline(GisInline):
    model = FooGeolocation
 
# Monkey-Patching section
insert_inline(FooModel, FooGisInline)

Generating a Resources Geolocation Map

The application provides a basic support for showing in a map the resources. The current version only provides this functionality for nodes resources but can be easily extended for supporting any kind of testbed resource. The source code is located in views.py

def generate_kml(request):  # generate a Google Maps compatible KML file
    ...
 
def map(request): # shows in a map the associated geolocation of the KML file
    ...

REST API (controller)

Controller provides REST API access to node gis information. A related link is included on objects that supports this endpoint (e.g nodes):

# GET /api/nodes/7
...
Link: 
<http://vct:8888/api/nodes/7/ctl/gis/>; rel="http://confine-project.eu/rel/controller/gis", 
...

Retrieve gis information

Node doesn't have information

# GET /api/nodes/7/ctl/gis/
 
HTTP 404 NOT FOUND
Content-Type: application/json
Vary: Accept
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
 
{
    "detail": "Not found"
}

A node with associated gis information:

# GET /api/nodes/3/ctl/gis/
 
HTTP 200 OK
Vary: Accept
Content-Type: application/json
Link: <http://vct:8888/api/>; rel="http://confine-project.eu/rel/server/base", 
<http://vct:8888/api/>; rel="http://confine-project.eu/rel/controller/base"
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
 
{
    "address": "Mount Everest",
    "coordinates": "27.9878943,86.9247837",
    "lat": 27.9878943, 
    "lon": 86.9247837
}

Create gis information

# PUT /api/nodes/7/ctl/gis/
# {
#     "address": "Mount Everest", 
#     "coordinates": "27.9878943,86.9247837"
# }
 
HTTP 201 CREATED
Content-Type: application/json
Vary: Accept
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
 
{
    "address": "Mount Everest",
    "coordinates": "27.9878943,86.9247837",
    "lat": 27.9878943,
    "lon": 86.9247837
}

Update gis information

# PATCH /api/nodes/7/ctl/gis/
# {
#     "address": "Mount Everest (Sagarmatha)",
# }
 
HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
 
{
    "address": "Mount Everest (Sagarmatha)", 
    "coordinates": "27.9878943,86.9247837", 
    "lat": 27.9878943, 
    "lon": 86.9247837
}
soft/server-apps-gis.txt · Last modified: 2014/07/07 18:52 by santiago