Class: RGeoServer::FeatureType

Inherits:
ResourceInfo show all
Defined in:
lib/rgeoserver/featuretype.rb

Overview

A feature type is a vector based spatial resource or data set that originates from a data store. In some cases, like Shapefile, a feature type has a one-to-one relationship with its data store. In other cases, like PostGIS, the relationship of feature type to data store is many-to-one, with each feature type corresponding to a table in the database.

Constant Summary collapse

OBJ_ATTRIBUTES =
{
  :catalog => "catalog", 
  :name => "name", 
  :native_name => "nativeName", 
  :workspace => "workspace", 
  :data_store => "data_store", 
  :enabled => "enabled", 
  :metadata => "metadata", 
  :metadata_links => "metadataLinks", 
  :title => "title", 
  :abstract => "abstract",
  :keywords => 'keywords',
  :native_bounds => 'native_bounds', 
  :latlon_bounds => "latlon_bounds", 
  :projection_policy => 'projection_policy'
}
OBJ_DEFAULT_ATTRIBUTES =
{
  :catalog => nil,
  :workspace => nil,
  :data_store => nil,
  :name => nil,
  :native_name => nil,
  :enabled => "true",
  :metadata => {},
  :metadata_links => {},
  :title => nil,
  :abstract => nil,
  :keywords => [],
  :native_bounds => {'minx'=>nil, 'miny' =>nil, 'maxx'=>nil, 'maxy'=>nil, 'crs' =>nil},
  :latlon_bounds => {'minx'=>nil, 'miny' =>nil, 'maxx'=>nil, 'maxy'=>nil, 'crs' =>nil},
  :projection_policy => :keep
}
METADATA_TYPES =
{
  'ISO19139' => 'text/xml',
  'TC211' => 'text/xml'
}
PROJECTION_POLICIES =
{
  :force => 'FORCE_DECLARED',
  :reproject => 'REPROJECT_TO_DECLARED',
  :keep => 'NONE'
}
@@route =
"workspaces/%s/datastores/%s/featuretypes"
@@root =
"featureTypes"
@@resource_name =
"featureType"

Instance Attribute Summary

Attributes inherited from ResourceInfo

#catalog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceInfo

#clear, #create_method, #delete, list, #new?, #profile, #profile=, #profile_xml_to_ng, #refresh, #save, #to_s, update_attribute_accessors, #update_method

Constructor Details

#initialize(catalog, options) ⇒ FeatureType

Returns a new instance of FeatureType.

Parameters:

Raises:



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
# File 'lib/rgeoserver/featuretype.rb', line 144

def initialize catalog, options
  raise GeoServerArgumentError, "FeatureType.new requires :data_store option" unless options.include?(:data_store)
  raise GeoServerArgumentError, "FeatureType.new requires :name option" unless options.include?(:name)
  super(catalog)
  _run_initialize_callbacks do
    workspace = options[:workspace] || 'default'
    if workspace.instance_of? String
      @workspace = @catalog.get_workspace(workspace)
    elsif workspace.instance_of? Workspace
      @workspace = workspace
    else
      raise GeoServerArgumentError, "Not a valid workspace: #{workspace}"
    end
    
    data_store = options[:data_store]
    if data_store.instance_of? String
      @data_store = @catalog.get_data_store(@workspace.name, data_store)
    elsif data_store.instance_of? DataStore
      @data_store = data_store
    else
      raise GeoServerArgumentError, "Not a valid datastore: #{data_store}"
    end

    @name = options[:name].strip
    @route = route
  end
end

Class Method Details

.member_xpathObject



72
73
74
# File 'lib/rgeoserver/featuretype.rb', line 72

def self.member_xpath
  "//#{resource_name}"
end

.resource_nameObject



64
65
66
# File 'lib/rgeoserver/featuretype.rb', line 64

def self.resource_name
  @@resource_name
end

.rootObject



60
61
62
# File 'lib/rgeoserver/featuretype.rb', line 60

def self.root
  @@root
end

.root_xpathObject



68
69
70
# File 'lib/rgeoserver/featuretype.rb', line 68

def self.root_xpath
  "//#{root}/#{resource_name}"
end

Instance Method Details

#messageObject



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
# File 'lib/rgeoserver/featuretype.rb', line 88

def message
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.featureType {
      xml.nativeName @native_name.nil?? @name : @native_name if new? # on new only
      xml.name @name
      xml.enabled @enabled
      xml.title @title
      xml.abstract @abstract
      xml.keywords {
        @keywords.compact.uniq.each do |k|
          xml.string RGeoServer::Metadata::to_keyword(k)
        end
      } unless @keywords.empty?

      xml.metadataLinks {
        @metadata_links.each do |m|
          raise ArgumentError, "Malformed metadata_links" unless m.is_a? Hash
          xml.metadataLink {
            xml.type_ to_mimetype(m['metadataType'])
            xml.metadataType m['metadataType']
            xml.content m['content']
          }
        end
      } unless @metadata_links.empty?
      
      xml.store(:class => 'dataStore') {
        xml.name @data_store.name
      } if new? or data_store_changed?

      xml.nativeBoundingBox {
        xml.minx native_bounds['minx'] if native_bounds['minx']
        xml.miny native_bounds['miny'] if native_bounds['miny']
        xml.maxx native_bounds['maxx'] if native_bounds['maxx']
        xml.maxy native_bounds['maxy'] if native_bounds['maxy']
        xml.crs native_bounds['crs'] if native_bounds['crs']
      } if valid_native_bounds? and (new? or native_bounds_changed?)

      xml.latLonBoundingBox {
        xml.minx latlon_bounds['minx'] if latlon_bounds['minx']
        xml.miny latlon_bounds['miny'] if latlon_bounds['miny']
        xml.maxx latlon_bounds['maxx'] if latlon_bounds['maxx']
        xml.maxy latlon_bounds['maxy'] if latlon_bounds['maxy']
        xml.crs latlon_bounds['crs'] if latlon_bounds['crs']
      } if valid_latlon_bounds? and (new? or latlon_bounds_changed?)

      xml.projectionPolicy get_projection_policy_message(projection_policy) if projection_policy and new? or projection_policy_changed?

    }
  end
  @message = builder.doc.to_xml
  @message
end

#profile_xml_to_hash(profile_xml) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/rgeoserver/featuretype.rb', line 172

def profile_xml_to_hash profile_xml
  doc = profile_xml_to_ng profile_xml
  ft = doc.at_xpath('//' + FeatureType::resource_name)
  ap({:doc => doc, :ft => ft}) if $DEBUG
  h = {
    "name" => ft.at_xpath('name').text,
    "enabled" => ft.at_xpath('enabled/text()').to_s,
    "native_name" => ft.at_xpath('nativeName').text,
    "title" => ft.at_xpath('title').text,
    "abstract" => ft.at_xpath('abstract/text()'), # optional
    "keywords" => ft.xpath('keywords/string').collect { |k| k.at_xpath('.').text},
    "workspace" => @workspace.name,
    "data_store" => @data_store.name,
    "srs" => ft.at_xpath('srs').text,
    "native_bounds" => {
      'minx' => ft.at_xpath('nativeBoundingBox/minx').text.to_f,
      'miny' => ft.at_xpath('nativeBoundingBox/miny').text.to_f,
      'maxx' => ft.at_xpath('nativeBoundingBox/maxx').text.to_f,
      'maxy' => ft.at_xpath('nativeBoundingBox/maxy').text.to_f,
      'crs' => ft.at_xpath('srs').text
    },
    "latlon_bounds" => {
      'minx' => ft.at_xpath('latLonBoundingBox/minx').text.to_f,
      'miny' => ft.at_xpath('latLonBoundingBox/miny').text.to_f,
      'maxx' => ft.at_xpath('latLonBoundingBox/maxx').text.to_f,
      'maxy' => ft.at_xpath('latLonBoundingBox/maxy').text.to_f,
      'crs' => ft.at_xpath('latLonBoundingBox/crs').text
    },
    "projection_policy" => get_projection_policy_sym(ft.at_xpath('projectionPolicy').text),
    "metadata_links" => ft.xpath('metadataLinks/metadataLink').collect{ |m|
      {
        'type' => m.at_xpath('type').text,
        'metadataType' => m.at_xpath('metadataType').text,
        'content' => m.at_xpath('content').text
      }
    },
    "attributes" => ft.xpath('attributes/attribute').collect{ |a|
      {
        'name' => a.at_xpath('name').text,
        'minOccurs' => a.at_xpath('minOccurs').text,
        'maxOccurs' => a.at_xpath('maxOccurs').text,
        'nillable' => a.at_xpath('nillable').text,
        'binding' => a.at_xpath('binding').text
      }
    }
  }.freeze
  h
end

#routeObject



76
77
78
79
80
# File 'lib/rgeoserver/featuretype.rb', line 76

def route
  raise GeoServerArgumentError, "workspace not defined" unless @workspace
  raise GeoServerArgumentError, "data_store not defined" unless @data_store
  @@route % [@workspace.name , @data_store.name]
end

#to_mimetype(type, default = 'text/xml') ⇒ Object



82
83
84
85
86
# File 'lib/rgeoserver/featuretype.rb', line 82

def to_mimetype(type, default = 'text/xml')
  k = type.to_s.strip.upcase
  return METADATA_TYPES[k] if METADATA_TYPES.include? k
  default
end

#update_params(name_route = name) ⇒ Object



233
234
235
236
# File 'lib/rgeoserver/featuretype.rb', line 233

def update_params name_route = name
  super(name_route)
  # recalculate='nativebbox,latlonbbox'
end

#valid_latlon_bounds?Boolean

Returns:

  • (Boolean)


227
228
229
230
231
# File 'lib/rgeoserver/featuretype.rb', line 227

def valid_latlon_bounds?
  bbox = RGeoServer::BoundingBox.new(latlon_bounds)
  ap bbox if $DEBUG
  not bbox.nil? and bbox.valid? and not latlon_bounds['crs'].empty?
end

#valid_native_bounds?Boolean

Returns:

  • (Boolean)


221
222
223
224
225
# File 'lib/rgeoserver/featuretype.rb', line 221

def valid_native_bounds?
  bbox = RGeoServer::BoundingBox.new(native_bounds)
  ap bbox if $DEBUG
  not bbox.nil? and bbox.valid? and not native_bounds['crs'].empty?
end