Puppet Class: ckan::ext::spatial

Defined in:
manifests/ext/spatial.pp

Summary

Installs the "spatial" extension.

Overview

Allows for the association of datasets with geographic locations, and for searches across datasets to be restricted to a particular geographical area. Additionally, it provides some support for previewing geographical datasets.

Parameters:

  • template (String)

    The name the template that spatial will modify. Note, this will overwrite the following files:

    • templates/package/search.html

    • templates/package/read_base.html

  • map_provider (String) (defaults to: 'mapquest')

    Which map provider to use. Options:

    • ‘mapquest’

    • ‘openstreetmap’

  • default_extent (Optional[String]) (defaults to: undef)

    Sets the default extent for the map. Should be a string in the format:

    “‘ ’[[15.62, -139.21], [64.92, -61.87]]‘ “`

    or GeoJSON
    

    “‘ ’{ "type":

    \"Polygon\", \"coordinates\": [[[74.89, 29.39],[74.89, 38.45], [60.50,
    38.45], [60.50, 29.39], [74.89, 29.39]]]}'
    ```
    

    If undefined, will not set an extent.

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'manifests/ext/spatial.pp', line 40

class ckan::ext::spatial (
  String           $template,
  String           $map_provider   = 'mapquest',
  Optional[String] $default_extent = undef,
){
  $package_root = "${ckan::ckan_ext}/ckanext-${template}/ckanext/${template}/templates/package"
  $search       = "${package_root}/search.html"
  $read_base    = "${package_root}/read_base.html"

  if $default_extent {
    $use_default_extent = true
  }else {
    $use_default_extent = false
  }

  # check for OS version
  if $::lsbdistrelease == '12.04' or $::lsbdistrelease == '14.04' {
    $required_packages = [
      'python-dev',
      'libxml2-dev',
      'libxslt1-dev',
      'libgeos-c1',
    ]
  }else{
    $required_packages = [
      'python-dev',
      'libxml2-dev',
      'libxslt1-dev',
      'libgeos-c1v5',
    ]
  }

  ensure_packages($required_packages)

  # check if need to install external libraries for solr
  if $ckan::solr_schema_version == 'spatial-ext'{
    solr::shared_lib{'jts':
      url     => $ckan::jts_url,
      require => Class['solr']
    }
    solr::shared_lib{'mmseg4j':
      url     => 'http://central.maven.org/maven2/com/chenlb/mmseg4j/mmseg4j-solr/2.3.0/mmseg4j-solr-2.3.0.jar',
      require => Class['solr']
    }
    $backend = 'solr-spatial-field'
  }else {
    $backend = 'solr'
  }

  postgresql_psql{'init_db_spatial':
    db      => 'ckan_default',
    command => 'create extension postgis',
    unless  => 'select * from pg_extension where extname=\'postgis\'',
    require => Postgresql::Server::Database['ckan_default'],
  }

  postgresql_psql{'init_db_topology':
    db      => 'ckan_default',
    command => 'create extension postgis_topology',
    unless  => 'select * from pg_extension where extname=\'postgis_topology\'',
    require => Postgresql_psql['init_db_spatial'],
  }

  postgresql::server::grant{'schema_grant_all':
    privilege   => 'ALL PRIVILEGES',
    object_type => 'SCHEMA',
    object_name => 'topology',
    db          => 'ckan_default',
    role        => 'ckan_default',
    require     => Postgresql_psql['init_db_topology'],
  }

  postgresql::server::grant{'grant_all_tables':
    privilege   => 'ALL PRIVILEGES',
    object_type => 'ALL TABLES IN SCHEMA',
    object_name => 'topology',
    db          => 'ckan_default',
    role        => 'ckan_default',
    require     => Postgresql::Server::Grant['schema_grant_all'],
  }

  ckan::ext { 'spatial':
    plugin    => ['spatial_metadata', 'spatial_query'],
    run_setup => true,
    require   => Postgresql::Server::Grant['grant_all_tables'],
  }

  ckan::conf::setting{'ckanext.spatial.search_backend':
    value   => $backend,
  }

  # ensure the package directory exists
  file{$package_root:
    ensure  => directory,
    #require => Package['python-ckan'],
    require => File['/usr/lib/ckan/default/src'],
  }

  # add spatial search widget
  file{$search:
    ensure  => file,
    content => template('ckan/ext/search.html.erb'),
    require => File[$package_root],
  }
  file {$read_base:
    ensure  => file,
    content => template('ckan/ext/read_base.html.erb'),
    require => File[$search],
  }

  case $map_provider {
    'mapquest': {
      #Nothing to do, it's the default
    }
    'openstreetmap': {
      ckan::conf::setting{'ckanext.spatial.common_map.type':
        value   => 'custom',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting{'ckanext.spatial.common_map.custom.url':
        value   => 'http://a.tile.openstreetmaps.org/{z}/{x}/{y}.png',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting{'ckanext.spatial.common_map.attribution':
        value   => "&copy <a href=\"http://www.openstreetmap.org/copyright\" target=\"_blank\">OpenStreetMap</a> contributors.\
  Tiles provided by <a href=\"https://maptiles.xyz\">MapTiles</a>.",
        require => Class['ckan::conf::production'],
      }
    }
    default: {
      error('Unknown map_provider')
    }
  }
}