Пример #1
0
// Process a layer and add labels.
simplet_status_t
simplet_layer_process(simplet_layer_t *layer, simplet_map_t *map, simplet_lithograph_t *litho, cairo_t *ctx){
  simplet_listiter_t *iter; OGRDataSourceH source;
  if(!(source = OGROpenShared(layer->source, 0, NULL)))
    return set_error(layer, SIMPLET_OGR_ERR, "error opening layer source");

  // Retain the datasource because we want to cache open connections to a
  // data source like postgres.
  if(OGR_DS_GetRefCount(source) == 1) OGR_DS_Reference(source);
  if(!(iter = simplet_get_list_iter(layer->filters))){
    OGRReleaseDataSource(source);
    return set_error(layer, SIMPLET_OOM, "out of memory getting list iterator");
  }

  // Loop through the layer's filters and process them.
  simplet_filter_t *filter;
  simplet_status_t status = SIMPLET_OK;
  while((filter = simplet_list_next(iter))) {
    status = simplet_filter_process(filter, map, source, litho, ctx);

    if(status != SIMPLET_OK){
      simplet_list_iter_free(iter);
      OGRReleaseDataSource(source);
      return status;
    }

    simplet_lithograph_apply(litho, filter->styles);
  }
  OGRReleaseDataSource(source);
  return SIMPLET_OK;
}
Пример #2
0
// The atexit handler used to close all connections to open data stores
static void
cleanup(){
	for(int i = 0; i < OGRGetOpenDSCount(); i++)
    while(OGRGetOpenDS(i) && OGR_DS_GetRefCount(OGRGetOpenDS(i)))
      OGRReleaseDataSource(OGRGetOpenDS(i));
  assert(!OGRGetOpenDSCount());
  OGRCleanupAll();
}