nswtopo 3.1 → 3.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c90485c22ed73dd281bbb6abb7dafd9ec919edda7065dd7106b0acd12485acf3
4
- data.tar.gz: fc3bae27f7d28243a3e9e27e56c28c8c0a724ea92237c018e4b161c9ad1ee74a
3
+ metadata.gz: be473c574c562b474c1d4ef9b3a1dfc2c697993b1034990375f1405ebfabf1cb
4
+ data.tar.gz: 7b230fbd3f2e5164bb6452c10a15cd38424dbeea29c42947f6e36150a5784570
5
5
  SHA512:
6
- metadata.gz: 70779d0482c7d5350f65af71faa1503f3f290125e38bbe16e9017c10332da375e763ac4583907f43e741b612f928563379c32b7ec38652b22ffe2d2d34827519
7
- data.tar.gz: d67a0b8e445cfec80c7ccae5d3df98983ec82b5533188e07e232f8dc41f825d70cc98026b5bb566127256eb22d4721e0aa1f697cccd80f98a85ee6cea8fdb006
6
+ metadata.gz: a925a874ddb9802d539712371e6dd06e28cb4a3fbdcd22d6b96a274131ae3a89244180d926d9f10a785db14ca98e0fdac4842a9766dad24475f3ff9c878e3c68
7
+ data.tar.gz: 145391125d1035c7bc5dc3b127389acc846277435624e971dcc82033089d784f5f84c0617ff7cc2af35884d750858b13d433185c73acb0fdd0eb363af9077393
data/bin/nswtopo CHANGED
@@ -220,6 +220,7 @@ begin
220
220
  parser.on "-b", "--bounds <bounds.kml>", Pathname, "bounds for map as KML or GPX file"
221
221
  parser.on "-c", "--coords <x1,y1,...>", CoordList, "bounds for map as one or more WGS84",
222
222
  "longitude/latitude pairs"
223
+ parser.on "-n", "--neatline <neatline.kml>", Pathname, "neatline for map as KML file"
223
224
  parser.on "-d", "--dimensions <width,height>", Dimensions, "map dimensions in mm"
224
225
  parser.on "-r", "--rotation <rotation>", Rotation, "map rotation angle in clockwise",
225
226
  "degrees, 'auto' or 'magnetic'"
@@ -17,14 +17,6 @@ module NSWTopo
17
17
  end
18
18
 
19
19
  module Formats
20
- def neatline_path_data
21
- @neatline.coordinates.map do |ring|
22
- ring.map do |point|
23
- point.join(" ")
24
- end.join(" L ").prepend("M ").concat(" Z")
25
- end.join(" ")
26
- end
27
-
28
20
  def render_svg(svg_path, background:, **options)
29
21
  if uptodate?("map.svg", "map.yml")
30
22
  log_update "nswtopo: reading existing map SVG"
@@ -63,7 +55,7 @@ module NSWTopo
63
55
  # add defs for map filters and masks
64
56
  defs = svg.add_element("defs", "id" => "map.defs")
65
57
  defs.add_element("rect", "id" => "map.rect", "width" => width, "height" => height)
66
- defs.add_element("path", "id" => "map.neatline", "d" => neatline_path_data)
58
+ defs.add_element("path", "id" => "map.neatline", "d" => @neatline.svg_path_data)
67
59
  defs.add_element("clipPath", "id" => "map.clip").add_element("use", "href" => "#map.neatline")
68
60
 
69
61
  # add a filter converting alpha channel to cutout mask
@@ -78,8 +78,8 @@ module NSWTopo
78
78
  raster_info = "%i×%i (%.1fMpx) map raster at %s" % [*raster_size, megapixels, ppi_info]
79
79
  log_update "chrome: creating #{raster_info}"
80
80
 
81
- REXML::Document.new(svg_path.read).elements["svg/@viewBox"].value.split.map(&:to_f).last(2).map do |mm|
82
- (0...(mm / mm_per_px).ceil).step(TILE).map do |px|
81
+ raster_size.map do |px|
82
+ (0...px).step(TILE).map do |px|
83
83
  [px, px * mm_per_px]
84
84
  end
85
85
  end.inject(&:product).map(&:transpose).map do |raster_offset, viewport_offset|
@@ -67,7 +67,7 @@ module NSWTopo
67
67
  end
68
68
 
69
69
  extend Forwardable
70
- delegate %i[coordinates properties wkt area] => :first
70
+ delegate %i[coordinates properties wkt area svg_path_data] => :first
71
71
  delegate %i[length] => :@features
72
72
 
73
73
  def to_json(**extras)
@@ -26,17 +26,15 @@ module NSWTopo
26
26
  end || lods.last
27
27
  tile_level, tile_resolution = lod.values_at "level", "resolution"
28
28
 
29
- target_bbox.coordinates.first.map do |corner|
30
- corner - origin
31
- end.transpose.map(&:minmax).zip(tile_sizes).map do |bound, tile_size|
32
- bound / tile_resolution / tile_size
29
+ target_bbox.bounds.zip(origin, tile_sizes).map do |(min, max), origin, tile_size|
30
+ [(min - origin) / tile_resolution / tile_size, (max - origin) / tile_resolution / tile_size]
33
31
  end.map do |min, max|
34
32
  (min.floor..max.ceil).each_cons(2).to_a
35
33
  end.inject(&:product).inject(GeoJSON::Collection.new(projection: service.projection)) do |tiles, (cols, rows)|
36
34
  [cols, rows].zip(tile_sizes).map do |indices, tile_size|
37
35
  indices.map { |index| index * tile_size * tile_resolution }
38
36
  end.transpose.map do |corner|
39
- corner + origin
37
+ corner.zip(origin).map(&:sum)
40
38
  end.transpose.then do |bounds|
41
39
  ring = bounds.inject(&:product).values_at(0,2,3,1,0)
42
40
  ullr = bounds.inject(&:product).values_at(1,2).flatten
data/lib/nswtopo/map.rb CHANGED
@@ -16,12 +16,18 @@ module NSWTopo
16
16
  extend Forwardable
17
17
  delegate %i[write mtime read uptodate?] => :@archive
18
18
 
19
- def self.init(archive, scale: 25000, rotation: 0.0, bounds: nil, coords: nil, dimensions: nil, margins: nil, **neatline_options)
19
+ def self.init(archive, scale: 25000, rotation: 0.0, bounds: nil, coords: nil, neatline: nil, dimensions: nil, margins: nil, **neatline_options)
20
20
  points = case
21
21
  when dimensions && margins
22
22
  raise "can't specify both margins and map dimensions"
23
+ when dimensions && neatline
24
+ raise "can't specify both neatline and map dimensions"
25
+ when bounds && neatline
26
+ raise "can't specify both bounds and neatline"
27
+ when coords && neatline
28
+ raise "can't specify both neatline and map coordinates"
23
29
  when coords && bounds
24
- raise "can't specify both bounds file and map coordinates"
30
+ raise "can't specify both bounds and map coordinates"
25
31
  when coords
26
32
  GeoJSON.multipoint(coords)
27
33
  when bounds
@@ -29,6 +35,10 @@ module NSWTopo
29
35
  margins ||= [15, 15] unless dimensions || gps.polygons.any?
30
36
  raise "no features found in %s" % bounds if gps.none?
31
37
  end
38
+ when neatline
39
+ neatline = GPS.load(neatline)
40
+ raise "neatline must be a single polygon" unless neatline.polygon?
41
+ neatline
32
42
  else
33
43
  raise "no bounds file or map coordinates specified"
34
44
  end.dissolve_points
@@ -73,8 +83,12 @@ module NSWTopo
73
83
  raise "not enough information to calculate map size – check bounds file, or specify map dimensions or margins"
74
84
  end
75
85
 
76
- ring = [0, 0].zip(dimensions).inject(&:product).values_at(0,2,3,1,0)
77
- neatline = GeoJSON.polygon [ring], projection: projection, name: "neatline"
86
+ if neatline
87
+ neatline = neatline.reproject_to projection
88
+ else
89
+ ring = [0, 0].zip(dimensions).inject(&:product).values_at(0,2,3,1,0)
90
+ neatline = GeoJSON.polygon [ring], projection: projection, name: "neatline"
91
+ end
78
92
 
79
93
  neatline_options.each do |key, value|
80
94
  case key
@@ -24,6 +24,6 @@ module NSWTopo
24
24
  end
25
25
  end
26
26
 
27
- VERSION = Version["nswtopo 3.1"]
27
+ VERSION = Version["nswtopo 3.1.1"]
28
28
  MIN_VERSION = Version["nswtopo 3.0"]
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nswtopo
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.1'
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Hollingworth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: