Class: Geoiq::Dataset

Inherits:
BaseModel show all
Defined in:
lib/geoiq/dataset.rb

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#auth

Instance Method Summary collapse

Methods inherited from BaseModel

api_methods, crud

Constructor Details

#initialize(auth, options = {}) ⇒ Dataset

Returns a new instance of Dataset.



11
12
13
14
15
16
17
# File 'lib/geoiq/dataset.rb', line 11

def initialize(auth, options = {})
  self.geoiq_id = options.delete(:geoiq_id) if options.include?(:geoiq_id)
  self.title = options[:title] || "Untitled"
  self.description = options[:description] || ""
  self.tags = options[:tags] || ""
  super
end

Instance Attribute Details

#data_typeObject

Returns the value of attribute data_type.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def data_type
  @data_type
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def description
  @description
end

#feature_countObject

Returns the value of attribute feature_count.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def feature_count
  @feature_count
end

#geoiq_idObject

Returns the value of attribute geoiq_id.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def geoiq_id
  @geoiq_id
end

#jsonObject

Returns the value of attribute json.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def json
  @json
end

Returns the value of attribute link.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def link
  @link
end

#publishedObject

Returns the value of attribute published.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def published
  @published
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/geoiq/dataset.rb', line 5

def title
  @title
end

Instance Method Details

#attributesObject



7
8
9
# File 'lib/geoiq/dataset.rb', line 7

def attributes
  %w{title description tags published data_type feature_count link}
end

#csv_upload(filename, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/geoiq/dataset.rb', line 54

def csv_upload(filename,  options={})
  type = "text/csv"

  content = File.read(filename)
  response = request(:post, "/datasets.json",
  {:body => content,
    :headers =>{ "Content-Type" => "#{type}"},
  :query => options})

  id =  response.headers["location"].match(/(\d+)\.json/)[1].to_i

  return find(id)
end

#deleteObject



38
39
40
41
42
# File 'lib/geoiq/dataset.rb', line 38

def delete
  requires_geoiq_id
  response = request(:delete, "/datasets/#{self.geoiq_id}.json")
  return true if response["status"].to_i == 204
end

#features(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/geoiq/dataset.rb', line 45

def features(options={})
  requires_geoiq_id

  response = request(:get, "/datasets/#{self.geoiq_id}/features.json", {:query => options})
  features = JSON.parse(response.body)


end

#find(id, options = {}) ⇒ Object

datasets.find(123)



20
21
22
23
24
25
# File 'lib/geoiq/dataset.rb', line 20

def find(id, options={})
  options = {:include_geometry=>0}
  response = request(:get, "/datasets/#{id}.json", {:query => options})
  dataset = Geoiq::Dataset.parse(response, auth, {:geoiq_id => id})
  dataset
end

#shp_upload(shp_file, dbf_file, shx_file) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/geoiq/dataset.rb', line 68

def shp_upload(shp_file, dbf_file, shx_file)

  body = shp_upload_body(shp_file, dbf_file, shx_file)
  response = request(:post, "/datasets.json",
  {:body => body,
    :headers =>{ "Content-Type" => "multipart/form-data, boundary=89d6e3836995"}
  })
  id =  response.headers["location"].match(/(\d+)\.json/)[1].to_i

  return find(id)

end

#update(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/geoiq/dataset.rb', line 27

def update(options)
  requires_geoiq_id
  self.title ||= options[:title]
  self.description ||= options[:description]
  self.tags ||= options[:tags]
  self.attributes ||= options[:attributes]
  overlay = {:overlay => options}
  response = request(:put, "/datasets/#{self.geoiq_id}.json", {:query => overlay})
  return true if response["status"].to_i == 200 || response["status"].to_i == 201
end

#url_upload(url, options = {}) ⇒ Object

Create a new dataset by passing in a url, and optional type type = csv,kml,rss, wms, tile



83
84
85
86
87
88
89
# File 'lib/geoiq/dataset.rb', line 83

def url_upload(url, options={})
  query = {:url => url}.merge(options)
  response = request(:post, "/datasets.json", {:query => query})
  id =  response.headers["location"].match(/(\d+)\.json/)[1].to_i

  return find(id)
end