mapknitter-exporter 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mapknitterExporter.rb +45 -38
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6396f65106739795c21f41cdbf09f5b83f304ba
4
- data.tar.gz: 5e376ff010e5e8de275f189ede66ec06fcbadd1e
3
+ metadata.gz: aa13d61605063309fe16c87a83a364af8f036b34
4
+ data.tar.gz: 20ba485d6b3905fb2a8ad2049832dd6305be092a
5
5
  SHA512:
6
- metadata.gz: d68a28de27755f50174dd36584a2d3a4e6f20f2b79bbd2ac4e788a36157ea6ba7f1d2d0161fa7fad26ec8848af2dfe275e7340047de788e2dd214c2b80ce9e15
7
- data.tar.gz: 0c5c5172b613dae3e347aa47b6644d6bfe0fe133ec839dccf97cab71fcbec97ab6bfe69fed0daebc6858d21c003671e0e4c0f72f05052a095ddb064f4409d01b
6
+ metadata.gz: fbba64c47fa9c10a2ad7287f2a44e8b6f113b59af985991ce294503b253c97f08be02a3e360e97b3c8829daa704acdad5b33744b57a6026e03a6b54e34d26e7c
7
+ data.tar.gz: d2d0a2295f3020c727166edc6e6df7f2f7d4d30b67b7934114fd93617e187e4f9e643ceb44f7b11b81af2689c67761189cdd9ced6ea92c1359d6cc1dd5e172c9
@@ -29,7 +29,7 @@ class MapKnitterExporter
29
29
  # pixels per meter = pxperm
30
30
  def self.generate_perspectival_distort(pxperm, id, nodes_array, image_file_name, img_url, height, width, root = "https://mapknitter.org")
31
31
  require 'net/http'
32
-
32
+
33
33
  # everything in -working/ can be deleted;
34
34
  # this is just so we can use the files locally outside of s3
35
35
  working_directory = get_working_directory(id)
@@ -50,32 +50,28 @@ class MapKnitterExporter
50
50
  # everything -geo WITH AN ID could be deleted, but there is a feature request to preserve these
51
51
  warped_geotiff_location = directory+id.to_s+'-geo.tif'
52
52
 
53
- northmost = nodes_array.first[:lat]
54
- southmost = nodes_array.first[:lat]
55
- westmost = nodes_array.first[:lon]
56
- eastmost = nodes_array.first[:lon]
53
+ northmost = nodes_array.first['lat'].to_f
54
+ southmost = nodes_array.first['lat'].to_f
55
+ westmost = nodes_array.first['lon'].to_f
56
+ eastmost = nodes_array.first['lon'].to_f
57
57
 
58
58
  nodes_array.each do |node|
59
- northmost = node[:lat] if node[:lat] > northmost
60
- southmost = node[:lat] if node[:lat] < southmost
61
- westmost = node[:lon] if node[:lon] < westmost
62
- eastmost = node[:lon] if node[:lon] > eastmost
59
+ northmost = node['lat'].to_f if node['lat'].to_f > northmost
60
+ southmost = node['lat'].to_f if node['lat'].to_f < southmost
61
+ westmost = node['lon'].to_f if node['lon'].to_f < westmost
62
+ eastmost = node['lon'].to_f if node['lon'].to_f > eastmost
63
63
  end
64
-
65
- # puts northmost.to_s+','+southmost.to_s+','+westmost.to_s+','+eastmost.to_s
66
64
 
67
65
  scale = 20037508.34
68
- y1 = pxperm*Cartagen.spherical_mercator_lat_to_y(northmost,scale)
69
- x1 = pxperm*Cartagen.spherical_mercator_lon_to_x(westmost,scale)
70
- y2 = pxperm*Cartagen.spherical_mercator_lat_to_y(southmost,scale)
71
- x2 = pxperm*Cartagen.spherical_mercator_lon_to_x(eastmost,scale)
72
- # puts x1.to_s+','+y1.to_s+','+x2.to_s+','+y2.to_s
66
+ y1 = pxperm.to_f * Cartagen.spherical_mercator_lat_to_y(northmost,scale)
67
+ x1 = pxperm.to_f * Cartagen.spherical_mercator_lon_to_x(westmost,scale)
68
+ y2 = pxperm.to_f * Cartagen.spherical_mercator_lat_to_y(southmost,scale)
69
+ x2 = pxperm.to_f * Cartagen.spherical_mercator_lon_to_x(eastmost,scale)
73
70
 
74
71
  # should determine if it's stored in s3 or locally:
75
72
  if (img_url.slice(0,4) == 'http')
76
73
  Net::HTTP.start('s3.amazonaws.com') { |http|
77
74
  #Net::HTTP.start('localhost') { |http|
78
- puts (img_url)
79
75
  resp = http.get(img_url)
80
76
  open(local_location, "wb") { |file|
81
77
  file.write(resp.body)
@@ -126,8 +122,8 @@ class MapKnitterExporter
126
122
  corner = source_corners.shift
127
123
  nx1 = corner[0]
128
124
  ny1 = corner[1]
129
- nx2 = -x1+(pxperm*Cartagen.spherical_mercator_lon_to_x(node[:lon],scale))
130
- ny2 = y1-(pxperm*Cartagen.spherical_mercator_lat_to_y(node[:lat],scale))
125
+ nx2 = -x1 + (pxperm.to_f * Cartagen.spherical_mercator_lon_to_x(node['lon'].to_f, scale.to_f))
126
+ ny2 = y1 - (pxperm.to_f * Cartagen.spherical_mercator_lat_to_y(node['lat'].to_f, scale.to_f))
131
127
 
132
128
  points = points + ' ' unless first
133
129
  maskpoints = maskpoints + ' ' unless first
@@ -135,7 +131,7 @@ class MapKnitterExporter
135
131
  maskpoints = maskpoints + nx2.to_i.to_s + ',' + ny2.to_i.to_s
136
132
  first = false
137
133
  # we need to find an origin; find northwestern-most point
138
- coordinates = coordinates+' -gcp '+nx2.to_s+', '+ny2.to_s+', '+node[:lon].to_s + ', ' + node[:lat].to_s
134
+ coordinates = coordinates+' -gcp '+nx2.to_s+', '+ny2.to_s+', '+node['lon'].to_s + ', ' + node['lat'].to_s
139
135
 
140
136
  # identify largest dimension to set canvas size for ImageMagick:
141
137
  maxdimension = nx1.to_i if maxdimension < nx1.to_i
@@ -146,8 +142,8 @@ class MapKnitterExporter
146
142
 
147
143
  # close mask polygon:
148
144
  maskpoints = maskpoints + ' '
149
- nx2 = -x1+(pxperm*Cartagen.spherical_mercator_lon_to_x(nodes_array.first[:lon], scale))
150
- ny2 = y1-(pxperm*Cartagen.spherical_mercator_lat_to_y(nodes_array.first[:lat], scale))
145
+ nx2 = -x1 + (pxperm.to_f * Cartagen.spherical_mercator_lon_to_x(nodes_array.first['lon'].to_f, scale.to_f))
146
+ ny2 = y1 - (pxperm.to_f * Cartagen.spherical_mercator_lat_to_y(nodes_array.first['lat'].to_f, scale.to_f))
151
147
  maskpoints = maskpoints + nx2.to_i.to_s + ',' + ny2.to_i.to_s
152
148
 
153
149
  height = (y1-y2).to_i.to_s
@@ -235,11 +231,11 @@ class MapKnitterExporter
235
231
  img_coords = generate_perspectival_distort(
236
232
  scale,
237
233
  id,
238
- image[:nodes_array],
239
- image[:filename],
240
- image[:url],
241
- image[:height],
242
- image[:width]
234
+ image['nodes'],
235
+ image['image_file_name'],
236
+ image['src'],
237
+ image['height'].to_i,
238
+ image['width'].to_i
243
239
  )
244
240
  puts '- '+img_coords.to_s
245
241
  all_coords << img_coords
@@ -259,20 +255,20 @@ class MapKnitterExporter
259
255
  maxlat = nil
260
256
  maxlon = nil
261
257
  placed_warpables.each do |warpable|
262
- warpable[:nodes_array].each do |n|
263
- minlat = n[:lat] if minlat == nil || n[:lat] < minlat
264
- minlon = n[:lon] if minlon == nil || n[:lon] < minlon
265
- maxlat = n[:lat] if maxlat == nil || n[:lat] > maxlat
266
- maxlon = n[:lon] if maxlon == nil || n[:lon] > maxlon
258
+ warpable['nodes'].each do |n|
259
+ minlat = n['lat'] if minlat == nil || n['lat'] < minlat
260
+ minlon = n['lon'] if minlon == nil || n['lon'] < minlon
261
+ maxlat = n['lat'] if maxlat == nil || n['lat'] > maxlat
262
+ maxlon = n['lon'] if maxlon == nil || n['lon'] > maxlon
267
263
  end
268
264
  end
269
265
  first = true
270
- if ordered != true
266
+ if ordered != true && placed_warpables.first.keys.include?('poly_area')
271
267
  # sort by area; this would be overridden by a provided order
272
- warpables = placed_warpables.sort{|a,b|b.poly_area <=> a.poly_area}
268
+ warpables = placed_warpables.sort{ |a,b| b['poly_area'] <=> a['poly_area'] }
273
269
  end
274
270
  warpables.each do |warpable|
275
- wid = warpable[:id].to_s
271
+ wid = warpable['id'].to_s
276
272
  geotiffs += ' '+directory+wid+'-geo.tif'
277
273
  if first
278
274
  gdalwarp = "gdalwarp -s_srs EPSG:3857 -te #{minlon} #{minlat} #{maxlon} #{maxlat} #{directory}#{wid}-geo.tif #{directory}#{id}-geo.tif"
@@ -312,7 +308,7 @@ class MapKnitterExporter
312
308
 
313
309
  # runs the above map functions while maintaining a record of state in an Export model;
314
310
  # we'll be replacing the export model state with a flat status file
315
- def self.run_export(user_id, resolution, export, id, root, placed_warpables, key)
311
+ def self.run_export(user_id, resolution, export, id, root, warpables, key, ordered = false)
316
312
  export.user_id = user_id if user_id
317
313
  export.status = 'starting'
318
314
  export.tms = false
@@ -321,6 +317,11 @@ class MapKnitterExporter
321
317
  export.jpg = false
322
318
  export.save
323
319
 
320
+ # filter out those that have no corner coordinates
321
+ placed_warpables = warpables.keep_if do |w|
322
+ w['nodes'] && w['nodes'].length > 0
323
+ end
324
+
324
325
  directory = "#{root}/public/warps/#{id}/"
325
326
  stdin, stdout, stderr = Open3.popen3('rm -r '+directory.to_s)
326
327
  puts stdout.readlines
@@ -330,7 +331,7 @@ class MapKnitterExporter
330
331
  puts stderr.readlines
331
332
 
332
333
  puts '> averaging scales; resolution: ' + resolution.to_s
333
- pxperm = 100/(resolution).to_f # pixels per meter
334
+ pxperm = 100/(resolution.to_f) # pixels per meter
334
335
  puts '> scale: ' + pxperm.to_s + 'pxperm'
335
336
 
336
337
  puts '> distorting warpables'
@@ -342,7 +343,13 @@ class MapKnitterExporter
342
343
  export.save
343
344
 
344
345
  puts '> generating composite tiff'
345
- composite_location = self.generate_composite_tiff(warpable_coords,origin,placed_warpables,id,false) # no ordering yet
346
+ composite_location = self.generate_composite_tiff(
347
+ warpable_coords,
348
+ origin,
349
+ placed_warpables,
350
+ id,
351
+ ordered
352
+ )
346
353
 
347
354
  info = (`identify -quiet -format '%b,%w,%h' #{composite_location}`).split(',')
348
355
  puts info
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapknitter-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Warren