arcserver.rb 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +274 -0
- data/LICENSE +20 -20
- data/README.md +160 -0
- data/Rakefile +9 -62
- data/arcserver.rb.gemspec +35 -0
- data/lib/arcserver.rb +33 -7
- data/lib/arcserver/Identifiable.rb +10 -0
- data/lib/arcserver/Queryable.rb +10 -0
- data/lib/arcserver/feature_server.rb +19 -0
- data/lib/arcserver/geometry/geometry.rb +91 -0
- data/lib/arcserver/geometry_service.rb +18 -0
- data/lib/arcserver/gp_server.rb +20 -0
- data/lib/arcserver/graphics/feature.rb +23 -0
- data/lib/arcserver/graphics/feature_set.rb +26 -0
- data/lib/arcserver/map_server.rb +34 -40
- data/lib/arcserver/rest/feature_server.rb +30 -0
- data/lib/arcserver/rest/geometry_service.rb +54 -0
- data/lib/arcserver/rest/gp_server.rb +80 -0
- data/lib/arcserver/rest/identify.rb +66 -0
- data/lib/arcserver/rest/map_server.rb +230 -230
- data/lib/arcserver/rest/query.rb +68 -0
- data/lib/arcserver/url_helper.rb +31 -25
- data/lib/arcserver/util/legend_image.rb +0 -0
- data/lib/arcserver/version.rb +6 -6
- data/spec/custom_spec.rb +50 -0
- data/spec/factories/feature.rb +21 -0
- data/spec/feature_server_spec.rb +52 -0
- data/spec/feature_spec.rb +20 -0
- data/spec/geometry_service_spec.rb +31 -0
- data/spec/geometry_spec.rb +80 -0
- data/spec/gp_server_spec.rb +57 -0
- data/spec/identify_spec.rb +21 -0
- data/spec/query_spec.rb +38 -0
- data/spec/shared_context.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- metadata +217 -158
- data/README.rdoc +0 -57
- data/lib/arcserver/soap/map_server.rb +0 -263
- data/test/functional/soap/map_server_test.rb +0 -193
- data/test/test_helper.rb +0 -25
- data/test/unit/map_server_test.rb +0 -61
- data/test/unit/url_helper_test.rb +0 -54
- data/test/unit/util/legend_image_test.rb +0 -69
@@ -0,0 +1,30 @@
|
|
1
|
+
module ArcServer
|
2
|
+
module REST
|
3
|
+
class FeatureServer
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
format :json
|
7
|
+
# debug_output $stdout
|
8
|
+
|
9
|
+
# The REST url of a feature service
|
10
|
+
attr_reader :url
|
11
|
+
|
12
|
+
# @param [String] url the REST url of a map service
|
13
|
+
# @example
|
14
|
+
# ArcServer::MapServer.new("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/LandusePlanning/FeatureServer")
|
15
|
+
def initialize(url)
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
def applyEdits(layer, adds=[], updates=[], deletes=[])
|
20
|
+
options = { body: { f: 'json', rollbackOnFailure: 'true' } }
|
21
|
+
options[:body].merge!( { adds: adds.to_json(only: [ :geometry, :attributes ]) } ) if adds.any?
|
22
|
+
options[:body].merge!( { updates: updates.to_json(only: [ :geometry, :attributes ] ) } ) if updates.any?
|
23
|
+
options[:body].merge!( { deletes: deletes } ) unless deletes.empty?
|
24
|
+
results = self.class.post("#{@url}/#{layer}/applyEdits", options)
|
25
|
+
results.with_indifferent_access
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
module REST
|
5
|
+
class GeometryService
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
# debug_output $stdout
|
10
|
+
|
11
|
+
# The REST url of a feature service
|
12
|
+
attr_reader :url
|
13
|
+
|
14
|
+
# @param [String] url the REST url of a map service
|
15
|
+
def initialize(url)
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_params(hash)
|
20
|
+
if hash[:geometries]
|
21
|
+
hash[:geometries] = hash[:geometries].to_json
|
22
|
+
end
|
23
|
+
hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def project(attrs={})
|
27
|
+
params = {
|
28
|
+
f: 'json',
|
29
|
+
geometries: '',
|
30
|
+
inSR: '',
|
31
|
+
outSR: ''
|
32
|
+
}.merge(attrs)
|
33
|
+
response = self.class.get("#{url}/project", query: to_params(params))
|
34
|
+
response["geometries"].map { |g| ArcServer::Geometry::Geometry.create(g) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def buffer(attrs={})
|
38
|
+
params = {
|
39
|
+
f: 'json',
|
40
|
+
geometries: '',
|
41
|
+
inSR: '',
|
42
|
+
outSR: '',
|
43
|
+
bufferSR: '',
|
44
|
+
distances: '',
|
45
|
+
unit: '',
|
46
|
+
unionResults: 'false'
|
47
|
+
}.merge(attrs)
|
48
|
+
response = self.class.get("#{url}/buffer", query: to_params(params))
|
49
|
+
response["geometries"].map { |g| ArcServer::Geometry::Geometry.create(g) }
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
module REST
|
5
|
+
class GPServer
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
# debug_output $stdout
|
10
|
+
|
11
|
+
# The REST url of a map service
|
12
|
+
attr_reader :url
|
13
|
+
|
14
|
+
# @param [String] url the REST url of a map service
|
15
|
+
# @example
|
16
|
+
# ArcServer::GPServer.new("http://sampleserver2.arcgisonline.com/ArcGIS/rest/services/PublicSafety/EMModels/GPServer/ERGByChemical")
|
17
|
+
def initialize(url)
|
18
|
+
@url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute(params)
|
22
|
+
defaults = { f: 'json' }.merge(params)
|
23
|
+
self.class.get("#{url}/execute", query: defaults)['results']
|
24
|
+
end
|
25
|
+
|
26
|
+
def checkJobStatus
|
27
|
+
@status
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_params(results, esri_job_id)
|
31
|
+
|
32
|
+
all_params = {}
|
33
|
+
results['results'].each do |r|
|
34
|
+
result_param = self.class.get("#{url}/jobs/#{esri_job_id}/#{r[1]['paramUrl']}", query: { f: 'json' }).with_indifferent_access
|
35
|
+
case result_param['dataType']
|
36
|
+
when 'GPFeatureRecordSetLayer'
|
37
|
+
all_params[result_param['paramName']] = Graphics::FeatureSet.new(result_param['value'])
|
38
|
+
else
|
39
|
+
all_params[result_param['paramName']] = result_param['value']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
all_params.with_indifferent_access
|
43
|
+
end
|
44
|
+
|
45
|
+
def submitJob(params)
|
46
|
+
|
47
|
+
defaults = { f: 'json' }.merge(params)
|
48
|
+
esri_job_id = self.class.get("#{url}/submitJob", query: defaults)['jobId']
|
49
|
+
|
50
|
+
s = Rufus::Scheduler.new
|
51
|
+
s.every '2s' do |job|
|
52
|
+
|
53
|
+
results = self.class.get("#{url}/jobs/#{esri_job_id}", query: { f: 'json' })
|
54
|
+
@status = results['jobStatus']
|
55
|
+
|
56
|
+
case @status
|
57
|
+
when 'esriJobSucceeded'
|
58
|
+
yield build_params(results, esri_job_id)
|
59
|
+
s.shutdown
|
60
|
+
when 'esriJobWaiting'
|
61
|
+
nil
|
62
|
+
when 'esriJobSubmitted'
|
63
|
+
nil
|
64
|
+
when 'esriJobExecuting'
|
65
|
+
nil
|
66
|
+
when 'esriJobCancelled'
|
67
|
+
nil
|
68
|
+
when 'esriJobFailed'
|
69
|
+
nil
|
70
|
+
when 'esriJobCancelling'
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
s.join
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
module REST
|
5
|
+
class Identify
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
# debug_output $stdout
|
10
|
+
|
11
|
+
def initialize(attr={})
|
12
|
+
defaults = {
|
13
|
+
f: "json",
|
14
|
+
geometry: "",
|
15
|
+
geometryType: "esriGeometryEnvelope",
|
16
|
+
sr: "",
|
17
|
+
layerDefs: "",
|
18
|
+
time: "",
|
19
|
+
layerTimeOptions: "",
|
20
|
+
layers: "all",
|
21
|
+
tolerance: "2",
|
22
|
+
mapExtent: "",
|
23
|
+
imageDisplay: "",
|
24
|
+
returnGeometry: true,
|
25
|
+
maxAllowableOffset: ""
|
26
|
+
}.merge(attr)
|
27
|
+
defaults.each { |k,v| instance_variable_set("@#{k}",v) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def params
|
31
|
+
hash = Hash[instance_variables.map { |name| [name.to_s[1..-1].to_sym, instance_variable_get(name)] } ]
|
32
|
+
if hash[:geometry]
|
33
|
+
hash[:geometryType] = hash[:geometry].geometryType
|
34
|
+
hash[:geometry] = hash[:geometry].to_json
|
35
|
+
end
|
36
|
+
hash[:mapExtent] = hash[:mapExtent].join(',') if hash[:mapExtent]
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(url)
|
41
|
+
response = self.class.get("#{url}/identify", query: params)
|
42
|
+
response.with_indifferent_access[:results].map { |r| IdentifyResult.new(r) }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class IdentifyResult
|
48
|
+
|
49
|
+
attr_accessor :layerId, :layerName, :value, :displayFieldName, :feature
|
50
|
+
|
51
|
+
def initialize(attrs={})
|
52
|
+
@layerId = attrs[:layerId]
|
53
|
+
@layerName = attrs[:layerName]
|
54
|
+
@value = attrs[:value]
|
55
|
+
@displayFieldName = attrs[:displayFieldName]
|
56
|
+
if attrs[:geometry]
|
57
|
+
@geometryType = attrs[:geometryType]
|
58
|
+
@geometry = ArcServer::Geometry::Geometry.build(attrs[:geometry], @geometryType)
|
59
|
+
end
|
60
|
+
@feature = Graphics::Feature.new({ geometry: @geometry, attributes: attrs[:attributes] })
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -1,230 +1,230 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module ArcServer
|
4
|
-
module REST
|
5
|
-
# Map services offer access to map and layer content. Map services can either
|
6
|
-
# be cached or dynamic. A map service that fulfills requests with pre-created
|
7
|
-
# tiles from a cache instead of dynamically rendering part of the map is called
|
8
|
-
# a cached map service. A dynamic map service requires the server to render
|
9
|
-
# the map each time a request comes in. Map services using a tile cache can
|
10
|
-
# significantly improve performance while delivering maps, while dynamic map
|
11
|
-
# services offer more flexibility. Map services should always be published as
|
12
|
-
# pooled services.
|
13
|
-
#
|
14
|
-
# The REST API map service resource represents a map service. This resource
|
15
|
-
# works only with the default data frame of your published map document. This
|
16
|
-
# resource provides basic information about the map, including the layers that
|
17
|
-
# it contains, whether the map is cached or not, its spatial reference, initial
|
18
|
-
# and full extents, map units, and copyright text. It also provides some metadata
|
19
|
-
# associated with the service such as its service description, its author, and
|
20
|
-
# keywords. If the map is cached, then additional information about its tiling
|
21
|
-
# scheme such as the origin of the cached tiles, the levels of detail, and tile
|
22
|
-
# size is included. Note that multi-layer caches are only accessible in REST
|
23
|
-
# via export, and these requests are treated as a dynamic map service. Tile
|
24
|
-
# access is not supported in REST for multi-layer caches.
|
25
|
-
#
|
26
|
-
# The map service resource supports several operations:
|
27
|
-
#
|
28
|
-
# * Export map - Used to export a map image from a dynamic map service. The
|
29
|
-
# resulting map can be used for display and be in a different projection from
|
30
|
-
# the original data source. When generating a map image, map services are
|
31
|
-
# not able to change feature rendering for an existing layer, add a dynamic
|
32
|
-
# layer, or change the layer draw order.
|
33
|
-
#
|
34
|
-
# * Identify - Returns information about features in one or more layers based
|
35
|
-
# on where a user clicks on the map.
|
36
|
-
#
|
37
|
-
# * Find - Returns information about features in one or more fields in one or
|
38
|
-
# more layers based on a key word.
|
39
|
-
#
|
40
|
-
# * Generate KML - Generates a KML document wrapped in a kmz file. The document
|
41
|
-
# contains a network link to the KML service endpoint with specified properties
|
42
|
-
# and parameters. This operation is valid on services that have not been restricted
|
43
|
-
# by using a token service.
|
44
|
-
#
|
45
|
-
# * Query on a Layer - Returns a subset of features in a layer based on query
|
46
|
-
# criteria.
|
47
|
-
#
|
48
|
-
# * Map services do not expose editing capabilities. They provide read-only
|
49
|
-
# access to feature and attribute content.
|
50
|
-
class MapServer
|
51
|
-
# The REST url of a map service
|
52
|
-
attr_reader :url
|
53
|
-
|
54
|
-
# @param [String] url the REST url of a map service
|
55
|
-
# @example
|
56
|
-
# ArcServer::MapServer.new("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer")
|
57
|
-
def initialize(url)
|
58
|
-
@url = url
|
59
|
-
end
|
60
|
-
|
61
|
-
# The export operation is performed on a map service resource. The result
|
62
|
-
# of this operation is a map image resource. This resource provides information
|
63
|
-
# about the exported map image such as its URL, its width and height, extent
|
64
|
-
# and scale.
|
65
|
-
#
|
66
|
-
# Apart from the usual response formats of html and json, users can also
|
67
|
-
# request a format called image while performing this operation. When users
|
68
|
-
# perform an export with the format of image, the server responds by directly
|
69
|
-
# streaming the image bytes to the client. One must note that with this
|
70
|
-
# approach you don't get any information associated with the exported map
|
71
|
-
# other than the actual image.
|
72
|
-
#
|
73
|
-
# Note that the extent displayed in the exported map image may not exactly
|
74
|
-
# match the extent sent in the bbox parameter when the aspect ratio of the
|
75
|
-
# image size does not match the aspect ratio of the bbox. The aspect ratio
|
76
|
-
# is the height divided by the width. In these cases the extent is re-sized
|
77
|
-
# to prevent map images from appearing stretched. The exported map’s extent
|
78
|
-
# is sent along with the json and html responses and may be used in client
|
79
|
-
# side calculations. So it is important that the client-side code update its
|
80
|
-
# extent based on the response.
|
81
|
-
#
|
82
|
-
# @param [Hash] params the query parameters to pass to the export operation
|
83
|
-
#
|
84
|
-
# @option params [String, Symbol] :f (:image) The response format. The default response
|
85
|
-
# format is html. If the format is image, the image bytes are directly streamed
|
86
|
-
# to the client.
|
87
|
-
#
|
88
|
-
# # Values: html | json | image | kmz | pjson (pretty json)
|
89
|
-
# # Examples:
|
90
|
-
# :f => :json
|
91
|
-
# :f => 'kmz'
|
92
|
-
#
|
93
|
-
# @option params [required, String, Array] :bbox The extent (bounding box) of
|
94
|
-
# the exported image. Unless the bboxSR parameter has been specified, the
|
95
|
-
# bbox is assumed to be in the spatial reference of the map.
|
96
|
-
#
|
97
|
-
# # Syntax: <xmin>, <ymin>, <xmax>, <ymax>
|
98
|
-
# # Examples:
|
99
|
-
# :bbox => "-104,35.6,-94.32,41"
|
100
|
-
# :bbox => [-104,35.6,-94.32,41]
|
101
|
-
#
|
102
|
-
# # Note: The bboxcoordinates should always use a period as the decimal separator
|
103
|
-
# # even in countries where traditionally a comma is used.
|
104
|
-
#
|
105
|
-
# @option params [String, Array] :size ([400, 400]) The size (width * height) of the exported
|
106
|
-
# image in pixels. If the size is not specified, an image with a default
|
107
|
-
# size of 400 * 400 will be exported.
|
108
|
-
#
|
109
|
-
# # Syntax: <width>, <height>
|
110
|
-
# # Examples:
|
111
|
-
# :size => "600,550"
|
112
|
-
# :size => [600,550]
|
113
|
-
#
|
114
|
-
# @option params [Integer] :dpi (96) The device resolution of the exported
|
115
|
-
# image (dots per inch).
|
116
|
-
#
|
117
|
-
# # Example:
|
118
|
-
# :dpi => 300
|
119
|
-
#
|
120
|
-
# @option params [Integer] :imageSR The well-known ID of the spatial reference
|
121
|
-
# of the exported image. If the imageSR is not specified, the image will
|
122
|
-
# be exported in the spatial reference of the map.
|
123
|
-
#
|
124
|
-
# # Example:
|
125
|
-
# :imageSR => 4326
|
126
|
-
#
|
127
|
-
# @option params [Integer] :bboxSR The well-known ID of the spatial reference
|
128
|
-
# of the bbox. If the bboxSR is not specified, the bbox is assumed to be
|
129
|
-
# in the spatial reference of the map.
|
130
|
-
#
|
131
|
-
# # Example:
|
132
|
-
# :bboxSR => 4326
|
133
|
-
#
|
134
|
-
# @option params [String, Symbol] :format (:png) The format of the exported
|
135
|
-
# image.
|
136
|
-
#
|
137
|
-
# # Values: png | png8 | png24 | jpg | pdf | bmp | gif | svg | png32
|
138
|
-
# # Examples:
|
139
|
-
# :format => :png32
|
140
|
-
# :format => 'jpg'
|
141
|
-
#
|
142
|
-
# # Note: Support for the png32 format was added at 9.3.1. This format is only
|
143
|
-
# # available for map services whose supportedImageFormatTypes property includes PNG32
|
144
|
-
#
|
145
|
-
# @option params [String] :layerDefs Allows you to filter the features of
|
146
|
-
# individual layers in the exported map by specifying definition expressions
|
147
|
-
# for those layers.
|
148
|
-
#
|
149
|
-
# # Syntax: layerId1:layerDef1;layerId2:layerDef2
|
150
|
-
# # (where layerId1, layerId2 are the layer ids returned by the map service resource)
|
151
|
-
# # Example:
|
152
|
-
# :layersDefs => "0:POP2000 > 1000000;5:AREA > 100000"
|
153
|
-
# :layersDefs => { 0 => "POP2000 > 1000000", 1 => "AREA > 100000" }
|
154
|
-
#
|
155
|
-
# @option params [String, Hash<Symbol, Array>] layers Determines which layers appear on the exported
|
156
|
-
# map. There are four ways to specify which layers are shown:
|
157
|
-
#
|
158
|
-
# * show: Only the layers specified in this list will be exported.
|
159
|
-
# * hide: All layers except those specified in this list will be exported.
|
160
|
-
# * include: In addition to the layers exported by default, the layers specified in this list will be exported.
|
161
|
-
# * exclude: The layers exported by default excluding those specified in this list will be exported.
|
162
|
-
#
|
163
|
-
# # Syntax: [show | hide | include | exclude]:layerId1,layerId2
|
164
|
-
# # where layerId1, layerId2are the layer ids returned by the map service resource
|
165
|
-
# # Examples:
|
166
|
-
# :layers => "show:2,4,7"
|
167
|
-
# :layers => { :show => [2,4,7] }
|
168
|
-
#
|
169
|
-
# @option params [true, false] transparent (false) If true, the image will be exported
|
170
|
-
# with the background color of the map set as its transparent color. The default
|
171
|
-
# is false. Only the png and gif formats support transparency. Internet
|
172
|
-
# Explorer 6 does not display transparency correctly for png24 image formats.
|
173
|
-
#
|
174
|
-
# @example
|
175
|
-
# # create a map service
|
176
|
-
# map_service = MapServer.new("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer")
|
177
|
-
#
|
178
|
-
# # Export a map
|
179
|
-
# map_service.export(:bbox => "-127.8,15.4,-63.5,60.5")
|
180
|
-
#
|
181
|
-
# # Export a map and change imageSR to 102004 (USA_Contiguous_Lambert_Conformal_Conic projection)
|
182
|
-
# map_service.export(:bbox => "-127.8,15.4,-63.5,60.5", :imageSR => 102004, :f => "html")
|
183
|
-
#
|
184
|
-
# # Export a map, change imageSR to 102004 (USA_Contiguous_Lambert_Conformal_Conic projection),
|
185
|
-
# # set image size to a width and height of 800x600, format to gif, and transparent to true.
|
186
|
-
# map_service.export(:bbox => "-115.8,30.4,-85.5,50.5", :size => "800,600", :imageSR => 102004, :format => "gif", :transparent => false, :f => "html")
|
187
|
-
#
|
188
|
-
# # Export the same map as above but change the output format to pretty json (f=pjson).
|
189
|
-
# map_service.export(:bbox => "-115.8,30.4,-85.5,50.5", :size => "800,600", :imageSR => 102004, :format => "gif", :transparent => false, :f => "pjson")
|
190
|
-
#
|
191
|
-
# @example
|
192
|
-
# JSON Response Syntax:
|
193
|
-
# {
|
194
|
-
# "href" : "<href>",
|
195
|
-
# "width" : <width>,
|
196
|
-
# "height" : <height>,
|
197
|
-
# "extent" : {<envelope>},
|
198
|
-
# "scale" : <scale>
|
199
|
-
# }
|
200
|
-
#
|
201
|
-
# JSON Response Example:
|
202
|
-
# {
|
203
|
-
# "href" : "http://atlantic/arcgisoutput/_ags_map42ef5eae899942a9b564138e184a55c9.png",
|
204
|
-
# "width" : 400,
|
205
|
-
# "height" : 400,
|
206
|
-
# "extent" : {
|
207
|
-
# "xmin" : -109.55,
|
208
|
-
# "ymin" : 25.76,
|
209
|
-
# "xmax" : -86.39,
|
210
|
-
# "ymax" : 49.94,
|
211
|
-
# "spatialReference" : { "wkid" : 4326 }
|
212
|
-
# },
|
213
|
-
# "scale" : 2.53E7
|
214
|
-
# }
|
215
|
-
#
|
216
|
-
# @return [HTTParty::Response] the HTTP response
|
217
|
-
def export(params = {})
|
218
|
-
params = {
|
219
|
-
:bbox => params[:bbox],
|
220
|
-
:f => params[:f] || :image,
|
221
|
-
:format => params[:format] || :png24,
|
222
|
-
:transparent => params[:transparent] || true,
|
223
|
-
:size => params[:size],
|
224
|
-
:dpi => params[:dpi]
|
225
|
-
}
|
226
|
-
HTTParty.get("#{url}/export", :query => params)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ArcServer
|
4
|
+
module REST
|
5
|
+
# Map services offer access to map and layer content. Map services can either
|
6
|
+
# be cached or dynamic. A map service that fulfills requests with pre-created
|
7
|
+
# tiles from a cache instead of dynamically rendering part of the map is called
|
8
|
+
# a cached map service. A dynamic map service requires the server to render
|
9
|
+
# the map each time a request comes in. Map services using a tile cache can
|
10
|
+
# significantly improve performance while delivering maps, while dynamic map
|
11
|
+
# services offer more flexibility. Map services should always be published as
|
12
|
+
# pooled services.
|
13
|
+
#
|
14
|
+
# The REST API map service resource represents a map service. This resource
|
15
|
+
# works only with the default data frame of your published map document. This
|
16
|
+
# resource provides basic information about the map, including the layers that
|
17
|
+
# it contains, whether the map is cached or not, its spatial reference, initial
|
18
|
+
# and full extents, map units, and copyright text. It also provides some metadata
|
19
|
+
# associated with the service such as its service description, its author, and
|
20
|
+
# keywords. If the map is cached, then additional information about its tiling
|
21
|
+
# scheme such as the origin of the cached tiles, the levels of detail, and tile
|
22
|
+
# size is included. Note that multi-layer caches are only accessible in REST
|
23
|
+
# via export, and these requests are treated as a dynamic map service. Tile
|
24
|
+
# access is not supported in REST for multi-layer caches.
|
25
|
+
#
|
26
|
+
# The map service resource supports several operations:
|
27
|
+
#
|
28
|
+
# * Export map - Used to export a map image from a dynamic map service. The
|
29
|
+
# resulting map can be used for display and be in a different projection from
|
30
|
+
# the original data source. When generating a map image, map services are
|
31
|
+
# not able to change feature rendering for an existing layer, add a dynamic
|
32
|
+
# layer, or change the layer draw order.
|
33
|
+
#
|
34
|
+
# * Identify - Returns information about features in one or more layers based
|
35
|
+
# on where a user clicks on the map.
|
36
|
+
#
|
37
|
+
# * Find - Returns information about features in one or more fields in one or
|
38
|
+
# more layers based on a key word.
|
39
|
+
#
|
40
|
+
# * Generate KML - Generates a KML document wrapped in a kmz file. The document
|
41
|
+
# contains a network link to the KML service endpoint with specified properties
|
42
|
+
# and parameters. This operation is valid on services that have not been restricted
|
43
|
+
# by using a token service.
|
44
|
+
#
|
45
|
+
# * Query on a Layer - Returns a subset of features in a layer based on query
|
46
|
+
# criteria.
|
47
|
+
#
|
48
|
+
# * Map services do not expose editing capabilities. They provide read-only
|
49
|
+
# access to feature and attribute content.
|
50
|
+
class MapServer
|
51
|
+
# The REST url of a map service
|
52
|
+
attr_reader :url
|
53
|
+
|
54
|
+
# @param [String] url the REST url of a map service
|
55
|
+
# @example
|
56
|
+
# ArcServer::MapServer.new("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer")
|
57
|
+
def initialize(url)
|
58
|
+
@url = url
|
59
|
+
end
|
60
|
+
|
61
|
+
# The export operation is performed on a map service resource. The result
|
62
|
+
# of this operation is a map image resource. This resource provides information
|
63
|
+
# about the exported map image such as its URL, its width and height, extent
|
64
|
+
# and scale.
|
65
|
+
#
|
66
|
+
# Apart from the usual response formats of html and json, users can also
|
67
|
+
# request a format called image while performing this operation. When users
|
68
|
+
# perform an export with the format of image, the server responds by directly
|
69
|
+
# streaming the image bytes to the client. One must note that with this
|
70
|
+
# approach you don't get any information associated with the exported map
|
71
|
+
# other than the actual image.
|
72
|
+
#
|
73
|
+
# Note that the extent displayed in the exported map image may not exactly
|
74
|
+
# match the extent sent in the bbox parameter when the aspect ratio of the
|
75
|
+
# image size does not match the aspect ratio of the bbox. The aspect ratio
|
76
|
+
# is the height divided by the width. In these cases the extent is re-sized
|
77
|
+
# to prevent map images from appearing stretched. The exported map’s extent
|
78
|
+
# is sent along with the json and html responses and may be used in client
|
79
|
+
# side calculations. So it is important that the client-side code update its
|
80
|
+
# extent based on the response.
|
81
|
+
#
|
82
|
+
# @param [Hash] params the query parameters to pass to the export operation
|
83
|
+
#
|
84
|
+
# @option params [String, Symbol] :f (:image) The response format. The default response
|
85
|
+
# format is html. If the format is image, the image bytes are directly streamed
|
86
|
+
# to the client.
|
87
|
+
#
|
88
|
+
# # Values: html | json | image | kmz | pjson (pretty json)
|
89
|
+
# # Examples:
|
90
|
+
# :f => :json
|
91
|
+
# :f => 'kmz'
|
92
|
+
#
|
93
|
+
# @option params [required, String, Array] :bbox The extent (bounding box) of
|
94
|
+
# the exported image. Unless the bboxSR parameter has been specified, the
|
95
|
+
# bbox is assumed to be in the spatial reference of the map.
|
96
|
+
#
|
97
|
+
# # Syntax: <xmin>, <ymin>, <xmax>, <ymax>
|
98
|
+
# # Examples:
|
99
|
+
# :bbox => "-104,35.6,-94.32,41"
|
100
|
+
# :bbox => [-104,35.6,-94.32,41]
|
101
|
+
#
|
102
|
+
# # Note: The bboxcoordinates should always use a period as the decimal separator
|
103
|
+
# # even in countries where traditionally a comma is used.
|
104
|
+
#
|
105
|
+
# @option params [String, Array] :size ([400, 400]) The size (width * height) of the exported
|
106
|
+
# image in pixels. If the size is not specified, an image with a default
|
107
|
+
# size of 400 * 400 will be exported.
|
108
|
+
#
|
109
|
+
# # Syntax: <width>, <height>
|
110
|
+
# # Examples:
|
111
|
+
# :size => "600,550"
|
112
|
+
# :size => [600,550]
|
113
|
+
#
|
114
|
+
# @option params [Integer] :dpi (96) The device resolution of the exported
|
115
|
+
# image (dots per inch).
|
116
|
+
#
|
117
|
+
# # Example:
|
118
|
+
# :dpi => 300
|
119
|
+
#
|
120
|
+
# @option params [Integer] :imageSR The well-known ID of the spatial reference
|
121
|
+
# of the exported image. If the imageSR is not specified, the image will
|
122
|
+
# be exported in the spatial reference of the map.
|
123
|
+
#
|
124
|
+
# # Example:
|
125
|
+
# :imageSR => 4326
|
126
|
+
#
|
127
|
+
# @option params [Integer] :bboxSR The well-known ID of the spatial reference
|
128
|
+
# of the bbox. If the bboxSR is not specified, the bbox is assumed to be
|
129
|
+
# in the spatial reference of the map.
|
130
|
+
#
|
131
|
+
# # Example:
|
132
|
+
# :bboxSR => 4326
|
133
|
+
#
|
134
|
+
# @option params [String, Symbol] :format (:png) The format of the exported
|
135
|
+
# image.
|
136
|
+
#
|
137
|
+
# # Values: png | png8 | png24 | jpg | pdf | bmp | gif | svg | png32
|
138
|
+
# # Examples:
|
139
|
+
# :format => :png32
|
140
|
+
# :format => 'jpg'
|
141
|
+
#
|
142
|
+
# # Note: Support for the png32 format was added at 9.3.1. This format is only
|
143
|
+
# # available for map services whose supportedImageFormatTypes property includes PNG32
|
144
|
+
#
|
145
|
+
# @option params [String] :layerDefs Allows you to filter the features of
|
146
|
+
# individual layers in the exported map by specifying definition expressions
|
147
|
+
# for those layers.
|
148
|
+
#
|
149
|
+
# # Syntax: layerId1:layerDef1;layerId2:layerDef2
|
150
|
+
# # (where layerId1, layerId2 are the layer ids returned by the map service resource)
|
151
|
+
# # Example:
|
152
|
+
# :layersDefs => "0:POP2000 > 1000000;5:AREA > 100000"
|
153
|
+
# :layersDefs => { 0 => "POP2000 > 1000000", 1 => "AREA > 100000" }
|
154
|
+
#
|
155
|
+
# @option params [String, Hash<Symbol, Array>] layers Determines which layers appear on the exported
|
156
|
+
# map. There are four ways to specify which layers are shown:
|
157
|
+
#
|
158
|
+
# * show: Only the layers specified in this list will be exported.
|
159
|
+
# * hide: All layers except those specified in this list will be exported.
|
160
|
+
# * include: In addition to the layers exported by default, the layers specified in this list will be exported.
|
161
|
+
# * exclude: The layers exported by default excluding those specified in this list will be exported.
|
162
|
+
#
|
163
|
+
# # Syntax: [show | hide | include | exclude]:layerId1,layerId2
|
164
|
+
# # where layerId1, layerId2are the layer ids returned by the map service resource
|
165
|
+
# # Examples:
|
166
|
+
# :layers => "show:2,4,7"
|
167
|
+
# :layers => { :show => [2,4,7] }
|
168
|
+
#
|
169
|
+
# @option params [true, false] transparent (false) If true, the image will be exported
|
170
|
+
# with the background color of the map set as its transparent color. The default
|
171
|
+
# is false. Only the png and gif formats support transparency. Internet
|
172
|
+
# Explorer 6 does not display transparency correctly for png24 image formats.
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# # create a map service
|
176
|
+
# map_service = MapServer.new("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer")
|
177
|
+
#
|
178
|
+
# # Export a map
|
179
|
+
# map_service.export(:bbox => "-127.8,15.4,-63.5,60.5")
|
180
|
+
#
|
181
|
+
# # Export a map and change imageSR to 102004 (USA_Contiguous_Lambert_Conformal_Conic projection)
|
182
|
+
# map_service.export(:bbox => "-127.8,15.4,-63.5,60.5", :imageSR => 102004, :f => "html")
|
183
|
+
#
|
184
|
+
# # Export a map, change imageSR to 102004 (USA_Contiguous_Lambert_Conformal_Conic projection),
|
185
|
+
# # set image size to a width and height of 800x600, format to gif, and transparent to true.
|
186
|
+
# map_service.export(:bbox => "-115.8,30.4,-85.5,50.5", :size => "800,600", :imageSR => 102004, :format => "gif", :transparent => false, :f => "html")
|
187
|
+
#
|
188
|
+
# # Export the same map as above but change the output format to pretty json (f=pjson).
|
189
|
+
# map_service.export(:bbox => "-115.8,30.4,-85.5,50.5", :size => "800,600", :imageSR => 102004, :format => "gif", :transparent => false, :f => "pjson")
|
190
|
+
#
|
191
|
+
# @example
|
192
|
+
# JSON Response Syntax:
|
193
|
+
# {
|
194
|
+
# "href" : "<href>",
|
195
|
+
# "width" : <width>,
|
196
|
+
# "height" : <height>,
|
197
|
+
# "extent" : {<envelope>},
|
198
|
+
# "scale" : <scale>
|
199
|
+
# }
|
200
|
+
#
|
201
|
+
# JSON Response Example:
|
202
|
+
# {
|
203
|
+
# "href" : "http://atlantic/arcgisoutput/_ags_map42ef5eae899942a9b564138e184a55c9.png",
|
204
|
+
# "width" : 400,
|
205
|
+
# "height" : 400,
|
206
|
+
# "extent" : {
|
207
|
+
# "xmin" : -109.55,
|
208
|
+
# "ymin" : 25.76,
|
209
|
+
# "xmax" : -86.39,
|
210
|
+
# "ymax" : 49.94,
|
211
|
+
# "spatialReference" : { "wkid" : 4326 }
|
212
|
+
# },
|
213
|
+
# "scale" : 2.53E7
|
214
|
+
# }
|
215
|
+
#
|
216
|
+
# @return [HTTParty::Response] the HTTP response
|
217
|
+
def export(params = {})
|
218
|
+
params = {
|
219
|
+
:bbox => params[:bbox],
|
220
|
+
:f => params[:f] || :image,
|
221
|
+
:format => params[:format] || :png24,
|
222
|
+
:transparent => params[:transparent] || true,
|
223
|
+
:size => params[:size],
|
224
|
+
:dpi => params[:dpi]
|
225
|
+
}
|
226
|
+
HTTParty.get("#{url}/export", :query => params)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|