Building a Table Joining (Like) Service with Web Processing Services

Ian Turton, Astun Technology Ltd.

[email protected]

[email protected]

@ijturton

Table Joining Service

In 2010 the Open Geospatial Consortium (OGC) proposed a new standard called the Table Joining Service

The Table Joining Service enables the publication of tabular information about geographic features, and the joining of these tables to their geographic features so that the information can be mapped or processed in a geographic information system.

What?

Why?

Allows the publication of a single geographic base map/dataset and then publication of many different datasets for that geography.

But

8 years later no one (to my knowledge) has implemented one.

Why?

So basically a completely new service and format to carry out a relatively simple task.

Or, Could we find a simpler way?

Web Processing Service (WPS) - another OGC standard for carrying out arbitrary operations over the web.

So if we:

A Joining Process

But

Leverage CSVDataStore

@Override
 public Object decode(InputStream input) throws Exception {
     // this will be deleted for us when the process finishes
     Resource tmp = resourceManager.getTemporaryResource(".csv");

     IOUtils.copy(input, tmp.out());
     HashMap<String, Object> params = new HashMap<>();
     params.put(CSVDataStoreFactory.FILE_PARAM.key,
       tmp.file().getAbsoluteFile());
     params.put(CSVDataStoreFactory.STRATEGYP.key,
       "CSVAttributesOnlyStrategy");
     CSVDataStore store = (CSVDataStore)
        DataStoreFinder.getDataStore(params);
     SimpleFeatureCollection collection = store.getFeatureSource()
        .getFeatures();
     LOGGER.info("read in "+collection.size()+
        " features from CSV source");
     store.dispose();
     return collection;
 }
@Override
public void encode(Object value, OutputStream os)
   throws Exception {
    // will be deleted when the process finishes
    Resource tmp = resourceManager.getTemporaryResource(".csv");
    SimpleFeatureCollection collection =
       (SimpleFeatureCollection) value;
    HashMap<String, Object> params = new HashMap<>();
    params.put(CSVDataStoreFactory.FILE_PARAM.key,tmp.file()
       .getAbsoluteFile());
    params.put(CSVDataStoreFactory.STRATEGYP.key,
      "CSVAttributesOnlyStrategy");
    CSVDataStore store = (CSVDataStore) DataStoreFinder
      .getDataStore(params);
    store.createSchema(collection.getSchema());
    String name = store.getTypeName().getLocalPart();
    Transaction transaction = Transaction.AUTO_COMMIT;
    SimpleFeatureSource featureSource = store
       .getFeatureSource(name,transaction );
    if(featureSource instanceof FeatureStore) {
        CSVFeatureStore csvFeatureStore =
           (CSVFeatureStore)featureSource;
        csvFeatureStore.addFeatures(collection);
    }
    store.dispose();
    IOUtils.copy(tmp.in(),os);
}

Important Note

If you use curl to send text to a remote web service, it will remove line feeds if you send the data as ASCII. If you need the line feeds to be present you must use BINARY.

Build the process

Filters

Simple:

STATE_NAME = State

Complex

A.STATE = STATE
(Set alias A)

Functions

strToLowerCase(State) = strToLowerCase(STATE_NAME)
district = substring(0,6,ward)
contains(geom,point)

How do we handle a "Joining" filter?

Coming Soon to a Repo near you

Thanks to Astun Ltd for funding this work

SpaceForward
Right, Down, Page DownNext slide
Left, Up, Page UpPrevious slide
POpen presenter console
HToggle this help