Skip to content
Creating custom areas and their metrics
JavaScript C# Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Database
Esd.FlexibleOpenGeographies.Data
Esd.FlexibleOpenGeographies.Fuseki.Updater
Esd.FlexibleOpenGeographies.Loader
Esd.FlexibleOpenGeographies.Service.Console
Esd.FlexibleOpenGeographies.Service.Functionality
Esd.FlexibleOpenGeographies.Service
Esd.FlexibleOpenGeographies.SignIn
Esd.FlexibleOpenGeographies.Web.Services
Esd.FlexibleOpenGeographies.Web
Esd.FlexibleOpenGeographies
Examples
.gitattributes
.gitignore
Esd.FlexibleOpenGeographies.sln
README.md

README.md

Introduction

Flexible open geographies is a web application for defining areas and assigning metrics to them. Areas are defined using either KML, GeoJSON, or as a set of previously defined areas.

Projects

Esd.FlexibleOpenGeographies.Web

An ASP.NET MVC web project and the main project for the site.

Esd.FlexibleOpenGeographies

Contains business logic.

Esd.FlexibleOpenGeographies.Data

Data layer using Entity Framework.

Esd.FlexibleOpenGeographies.SignIn

Contracts and classes to use as a basis for your own sign-in implementation.

Esd.FlexibleOpenGeographies.Loader

Loads data. The executable accepts space delimited parameters of one or more of "geometry", "kml", and "aggregate".

geometry is only required when setting up data. It finds areas with KML set and creates the shape in the PostgreSQL database

kml is also only required when setting up data. It reads the KML from an external source based on the area code. You will need to amend Esd.FlexibleOpenGeographies.KmlReader.KmlStringForCode so that it reads the external resources you require.

aggregate should run constantly and I run it as a scheduled task repeating once per minute. It creates the shape in PostgreSQL when an area is defined as a collection of other areas.

When loading initial data you can create all the areas first using insert statements on the MySQL database. Load the KML using the kml parameter. When finished load the PostgreSQL data using the geometry parameter.

Esd.FlexibleOpenGeographies.Fuseki.Updater

This loads data into Fuseki automatically from the area and area type tables.

Esd.FlexibleOpenGeographies.Importer

This populates the metric types, and period tables with data from the esd web services

Esd.FlexibleOpenGeographies.Service

This handles the import of metrics in the background

Esd.FlexibleOpenGeographies.Service.Functionality

Contains the actual functionality of the Esd.FlexibleOpenGeographies.Service for importing metrics.

Esd.FlexibleOpenGeographies.Web.Services

The FOG REST web services which provides a cut down version of the more complete esd web serivces.

Languages, frameworks, databases, etc

Code is written in C# using Ninject for dependency injection and Entity Framework as an ORM.

Client script is JavaScript often using jQuery.

Bootstrap is used for much of the CSS.

A MySQL database holds most of the information about the areas and the metrics. A PostgreSQL database holds all the geographic information about the areas.

Maps are drawn using OpenLayers 3 either directly using KML/GeoJSON or via GeoServer.

Web.config

Configuration for the application is held in the Web.config file in Esd.FlexibleOpenGeographies.Web. Values you may wish to change when configuring the application are:

  • FogConnection: The connection string for the MySQL database.
  • PostgisConnection: The connection string for the PostgreSQL database.
  • GeoServerUrl: The location of your GeoServer.
  • UserProvider: The class in the format classname, namespace implementing IUserProvider which is used for authentication.
  • SubHeader: The text below the main header on each page.
  • GoogleAnalyticsCode: Your google analytics code to use on the page. Leave blank to not use google analytics.
  • HasSignIn: "true" if you want to implement some sort of sign-in functionality. Any other value otherwise.
  • DisablePermissions: "true" if you want to hide the option to set permission levels. All newly created area types will be set to public.

Implementing sign-in

To implement custom sign-in create a class implementing Esd.FlexibleOpenGeographies.UserProvider.IUserProvider. The following members need to be implemented:

  • CreateUser Add the user and organisation to the database.
  • SignOut Redirect to the sign-out page.
  • AuthenticationCheck Return false if no authentication required. Otherwise perform whatever action is required (e.g. redirect to sign-in page) and return true.

If the method signatures do not match the data you require then please fork and modify.

If OAuth is being used you can use the OAuthManager class provided. You will need to implement IOAuthSettingsProvider to configure it.

If you write custom implementations of IUserProvider and/or IOAuthSettingsProvider modify NinjectWebCommon (in App_Start of the web project) to use your implementations.

Creating databases

The database schema creation scripts are in the Database folder. This will set up the database schemas and any reference data.

PostgreSQL

Firstly install PostgreSQL and PostGIS. Manually create a database and a user with id "postgres". Then run the script postgis.sql against this database. Update Web.config with the new connection details.

MySQL

Make sure you have MySQL installed on your server. Run fog.sql to create the database and initial schema. Update Web.config with the new connection details.

Creating GeoServer

Install GeoServer and change Web.config to set the location.

In the GeoServer web admin page create a new store of type PostGIS and entering the connection details of the PostgreSQL database you created earlier. All other values can be left as default.

Create a new layer for a SQL view and name it areas_for_type. The SQL statement will be:

SELECT ST_COLLECT(shape) AS areas FROM area WHERE area_type_code = '%typecode%'

Click "Guess parameters from SQL" and the parameter will be guessed correctly. The attribute will be name: areas, type: Geometry, SRID: 4326. Everything else in the layer can be left as default.

Initial areas

If you have KML available and a small number of areas the easiest way to create your initial areas is through the application itself. Create the type first, then create your areas by uploading KML.

If you are manually creating your areas (for example because you don't have KML) you'll need to add your records to the MySQL table "area_details", then the PostgreSQL table "area". The shape column will need to be populated using a PostGIS function (see the Geometry Constructors section of this document). Alternatively use pgShapeLoader to load the shapes.

You can’t perform that action at this time.