30
31
32
33
34
35
36
37
38
39
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
|
# File 'lib/nswtopo/gis/arcgis/layer/query.rb', line 30
def pages(per_page)
objectids = get_json("#{@id}/query", **base_query, returnIdsOnly: true)["objectIds"] || []
@count = objectids.count
return [GeoJSON::Collection.new(projection: projection, name: @name)].each if @count.zero?
@fields ||= @layer["fields"].select do |field|
Layer::FIELD_TYPES === field["type"]
end.map do |field|
field["name"]
end
Enumerator.new do |yielder|
out_fields = [*@fields, *].join ?,
while objectids.any?
begin
get_json "#{@id}/query", outFields: out_fields, objectIds: objectids.take(per_page).join(?,)
rescue Connection::Error
(per_page /= 2) > 0 ? retry : raise
end.fetch("features", []).filter_map do |feature|
next unless geometry = feature["geometry"]
properties = feature.fetch("attributes", {})
case @geometry_type
when "esriGeometryPoint"
point = geometry.values_at "x", "y"
next unless point.all?
next GeoJSON::Point[point, properties]
when "esriGeometryMultipoint"
points = geometry["points"]
next unless points&.any?
next GeoJSON::MultiPoint[points.transpose.take(2).transpose, properties]
when "esriGeometryPolyline"
raise "ArcGIS curve geometries not supported" if geometry.key? "curvePaths"
paths = geometry["paths"]
next unless paths&.any?
next GeoJSON::LineString[paths[0], properties] if @mixed && paths.one?
next GeoJSON::MultiLineString[paths, properties]
when "esriGeometryPolygon"
raise "ArcGIS curve geometries not supported" if geometry.key? "curveRings"
rings = geometry["rings"]
next unless rings&.any?
polys = GeoJSON::MultiLineString[rings.map(&:reverse), properties].to_multipolygon
next @mixed && polys.one? ? polys.first : polys
else
raise "unsupported ArcGIS geometry type: #{@geometry_type}"
end
end.tap do |features|
yielder << GeoJSON::Collection.new(projection: projection, features: features, name: @name)
end
objectids.shift per_page
end
end
end
|