Introduction

The GeoJSON format is part of the open JSON (JavaScript Object Notation) specification.   FME Server allows users to easily create a spatial data service in the GeoJSON format.  The example below shows how to use FME Server to create a GeoJSON spatial data web service from a data source in any of the hundreds of formats FME can read.  If you are considering creating an GeoJSON Service with FME Server you may also want to have a look at a similar article which deals with streaming XML  with FME Server here:
For web developers, we also show the basic syntax for requesting data from an FME Server GeoJSON web service. The second part of the demo shows a simple JavaScript example where we request data from our GeoJSON service for use in an OpenLayers map.

You can view a live version of the Open Layers Map which includes two GeoJSON layers provided by FME Server:
View it Live
Use View Source in your browser to see the syntax for requesting data from an FME Server Data Streaming Service.
 

Basic Steps to Create the Service

1. Create an FME workspace that reads the data you wish to serve and writes the data out in GeoJSON format. The easiest way to get started is by using the Generate Workspace dialog in FME to select your data and format and set up the GeoJSON writer. The attached workspace uses an SDF datasource from the FME training sample dataset.  You may need to project you data depending on the client application. In our example we reproject the data to EPSG:4326 for using in OpenLayers. If the data has multiple layers (feature types) the advanced writer parameter Feature Types to Read should be published so client can ask for whichever layer is needed.  Select a single layer as the default for testing.

FME Workspace can read any data and write GeoJSON

2. Publish the workspace to FME Server ensuring that any file paths to your source data are available on the machine running FME Server. Make note of the repository you have published the workspace into. Register the workspace with the Data Streaming Service.  

3. Go to the FME Server Web  User Interface and browse to the Data Streaming Service and then into the repository you published the data to. Click on the workspace you published. The Run button will run the workpace and return the GeoJSON directly to your browser. FME Server will provide the GeoJSON MIME type in the response header as well: Content-Type: application/json
 
4. Go back in the browser to the previous form and Click the Show Request button. This shows the url to use  to request data from the service. If you change the value of the Feature Types to Read parameter and click Show Request again you will see the syntax for including this parameter in a request. 

Find the URL to service in the FME Server Web UI

5. If you don’t want to try your own FME Server you can try this live on FME Server.com by going here:

http://www.fmeserver.com/fmeserver/services/fmedatastreaming/kbragg/GeoJson.fmw
 

Using FME Server's GeoJSON Service in a Client Appication

The URL obtained in step 4 above can be provided to any client application that consumes GeoJSON. FME Server will dynamically return the data in GeoJSON when the url is invoked.  The sample OpenLayers web page attached provides  an example of this. OpenLayers allows us to add a map layer in the GeoJSON format (among others). 

OpenLayers can use a GeoJSON service from FME Server as a map layer
 
Here is the relevant part of the syntax for adding a GeoJSON layer in OpenLayers using Java Script:
BusRoutes = new OpenLayers.Layer.GML( "Austin Bus Routes", http://fmeserver.com/fmedatastreaming/kbragg/GeoJson.fmw?FEATURE_TYPES=Default.BusRoutes....

Notice the url to the Data Streaming Service is exactly how we saw it when we used the Show Request button in the FME Server WebUI in step 4 above.  Any URL to FME Server’s Data Streaming service includes the following components:
  • FME Server Host:  http://fmeserver.com/
  • Service Name: fmedatastreaming/
  • Repository Name:  kbragg/
  • Workspace Name: GeoJson.fmw
  • Parameter Names and Values:  ?FEATURE_TYPES=Default.BusRoutes       
 

 

You can view a live version of the Open Layers Map which includes two GeoJSON layers provided by FME Server:
View it Live

Use View Source in your browser to see the syntax for requesting data from an FME Server Data Streaming Service.
More Information
For more backround on FME and GeoJSON please see Jason Birch’s excellent blog post here:
And Safe founder Dale Lutz’s blog post here: