class RGeoServer::FeatureType
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.
Constants
- METADATA_TYPES
- OBJ_ATTRIBUTES
- OBJ_DEFAULT_ATTRIBUTES
- PROJECTION_POLICIES
Public Class Methods
member_xpath()
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 72 def self.member_xpath "//#{resource_name}" end
new(catalog, options)
click to toggle source
@param [RGeoServer::Catalog] catalog @param [Hash] options
Calls superclass method
# 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
resource_name()
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 64 def self.resource_name @@resource_name end
root()
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 60 def self.root @@root end
root_xpath()
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 68 def self.root_xpath "//#{root}/#{resource_name}" end
Public Instance Methods
message()
click to toggle source
# 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)
click to toggle source
# 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
route()
click to toggle source
# 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')
click to toggle source
# 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)
click to toggle source
Calls superclass method
# File lib/rgeoserver/featuretype.rb, line 233 def update_params name_route = name super(name_route) # recalculate='nativebbox,latlonbbox' end
valid_latlon_bounds?()
click to toggle source
# 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?()
click to toggle source
# 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
Private Instance Methods
get_projection_policy_message(value)
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 249 def get_projection_policy_message value k = value k = value.strip.to_sym if not value.is_a? Symbol if PROJECTION_POLICIES.has_key? k PROJECTION_POLICIES[k] else raise GeoServerArgumentError, "Invalid PROJECTION_POLICY: #{k}" end end
get_projection_policy_sym(value)
click to toggle source
# File lib/rgeoserver/featuretype.rb, line 240 def get_projection_policy_sym value v = value.strip.upcase if PROJECTION_POLICIES.has_value? v PROJECTION_POLICIES.invert[v] else raise GeoServerArgumentError, "Invalid PROJECTION_POLICY: #{v}" end end