mapchete 0.25__tar.gz → 0.26__tar.gz

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 (126) hide show
  1. home/ungarj/virtualenvs/p3/bin/mapchete +12 -0
  2. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/__init__.py +1 -1
  3. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/__init__.cpython-35.pyc +0 -0
  4. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/_core.cpython-35.pyc +0 -0
  5. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/config.cpython-35.pyc +0 -0
  6. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/errors.cpython-35.pyc +0 -0
  7. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/index.cpython-35.pyc +0 -0
  8. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/log.cpython-35.pyc +0 -0
  9. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/__pycache__/tile.cpython-35.pyc +0 -0
  10. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/_core.py +7 -8
  11. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/__init__.cpython-35.pyc +0 -0
  12. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/create.cpython-35.pyc +0 -0
  13. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/execute.cpython-35.pyc +0 -0
  14. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/formats.cpython-35.pyc +0 -0
  15. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/index.cpython-35.pyc +0 -0
  16. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/main.cpython-35.pyc +0 -0
  17. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/pyramid.cpython-35.pyc +0 -0
  18. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/serve.cpython-35.pyc +0 -0
  19. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/tilify.cpython-35.pyc +0 -0
  20. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/__pycache__/utils.cpython-35.pyc +0 -0
  21. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/create.py +88 -0
  22. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/__init__.cpython-35.pyc +0 -0
  23. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/create.cpython-35.pyc +0 -0
  24. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/execute.cpython-35.pyc +0 -0
  25. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/formats.cpython-35.pyc +0 -0
  26. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/index.cpython-35.pyc +0 -0
  27. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/processes.cpython-35.pyc +0 -0
  28. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/pyramid.cpython-35.pyc +0 -0
  29. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/__pycache__/serve.cpython-35.pyc +0 -0
  30. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/execute.py +171 -0
  31. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/default/index.py +143 -0
  32. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/pyramid.py +0 -1
  33. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/serve.py +2 -3
  34. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/execute.py +115 -0
  35. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/formats.py +21 -0
  36. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/index.py +97 -0
  37. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/main.py +2 -3
  38. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/pyramid.py +127 -0
  39. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/serve.py +131 -0
  40. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/cli/tilify.py +46 -0
  41. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/utils.py +6 -2
  42. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/commons/__pycache__/__init__.cpython-35.pyc +0 -0
  43. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/commons/__pycache__/clip.cpython-35.pyc +0 -0
  44. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/commons/__pycache__/contours.cpython-35.pyc +0 -0
  45. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/commons/__pycache__/hillshade.cpython-35.pyc +0 -0
  46. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/config.py +12 -14
  47. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/__pycache__/__init__.cpython-35.pyc +0 -0
  48. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/__pycache__/base.cpython-35.pyc +0 -0
  49. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/__pycache__/drivers.cpython-35.pyc +0 -0
  50. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/__init__.cpython-35.pyc +0 -0
  51. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/geojson.cpython-35.pyc +0 -0
  52. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/gtiff.cpython-35.pyc +0 -0
  53. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/mapchete_input.cpython-35.pyc +0 -0
  54. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/png.cpython-35.pyc +0 -0
  55. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/png_hillshade.cpython-35.pyc +0 -0
  56. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/raster_file.cpython-35.pyc +0 -0
  57. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/tile_directory.cpython-35.pyc +0 -0
  58. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/formats/default/__pycache__/vector_file.cpython-35.pyc +0 -0
  59. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/geojson.py +5 -15
  60. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/gtiff.py +4 -9
  61. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/png.py +3 -8
  62. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/png_hillshade.py +3 -8
  63. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/tile_directory.py +4 -5
  64. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/index.py +503 -0
  65. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/io/__init__.py +68 -14
  66. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/io/__pycache__/__init__.cpython-35.pyc +0 -0
  67. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/io/__pycache__/raster.cpython-35.pyc +0 -0
  68. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/io/__pycache__/vector.cpython-35.pyc +0 -0
  69. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/io/raster.py +83 -33
  70. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/io/vector.py +1 -2
  71. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/static/__pycache__/__init__.cpython-35.pyc +0 -0
  72. home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete/static/__pycache__/process_template.cpython-35.pyc +0 -0
  73. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/tile.py +58 -16
  74. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/PKG-INFO +21 -2
  75. {mapchete-0.25/mapchete.egg-info → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/SOURCES.txt +1 -0
  76. {mapchete-0.25/mapchete.egg-info → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/entry_points.txt +2 -1
  77. {mapchete-0.25/mapchete.egg-info → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/requires.txt +5 -1
  78. mapchete-0.25/README.rst +0 -164
  79. mapchete-0.25/mapchete/cli/default/execute.py +0 -123
  80. mapchete-0.25/mapchete/cli/default/index.py +0 -133
  81. mapchete-0.25/mapchete/index.py +0 -286
  82. mapchete-0.25/mapchete.egg-info/PKG-INFO +0 -183
  83. mapchete-0.25/setup.cfg +0 -10
  84. mapchete-0.25/setup.py +0 -96
  85. mapchete-0.25/test/test_cli.py +0 -529
  86. mapchete-0.25/test/test_commons.py +0 -85
  87. mapchete-0.25/test/test_config.py +0 -245
  88. mapchete-0.25/test/test_deprecated.py +0 -31
  89. mapchete-0.25/test/test_errors.py +0 -256
  90. mapchete-0.25/test/test_formats.py +0 -150
  91. mapchete-0.25/test/test_formats_geojson.py +0 -120
  92. mapchete-0.25/test/test_formats_geotiff.py +0 -175
  93. mapchete-0.25/test/test_formats_png.py +0 -107
  94. mapchete-0.25/test/test_formats_png_hillshade.py +0 -124
  95. mapchete-0.25/test/test_formats_tiledir_input.py +0 -148
  96. mapchete-0.25/test/test_io.py +0 -686
  97. mapchete-0.25/test/test_log.py +0 -17
  98. mapchete-0.25/test/test_mapchete.py +0 -424
  99. mapchete-0.25/test/test_processes.py +0 -85
  100. mapchete-0.25/test/test_timer.py +0 -24
  101. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/__init__.py +0 -0
  102. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/__init__.py +0 -0
  103. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/create.py +0 -0
  104. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/formats.py +0 -0
  105. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/cli/default/processes.py +0 -0
  106. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/commons/__init__.py +0 -0
  107. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/commons/clip.py +0 -0
  108. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/commons/contours.py +0 -0
  109. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/commons/hillshade.py +0 -0
  110. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/errors.py +0 -0
  111. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/__init__.py +0 -0
  112. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/base.py +0 -0
  113. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/__init__.py +0 -0
  114. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/mapchete_input.py +0 -0
  115. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/raster_file.py +0 -0
  116. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/default/vector_file.py +0 -0
  117. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/formats/drivers.py +0 -0
  118. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/log.py +0 -0
  119. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/__init__.py +0 -0
  120. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/__init__.pyc +0 -0
  121. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/index.html +0 -0
  122. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/mapchete_template.mapchete +0 -0
  123. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/process_template.py +0 -0
  124. {mapchete-0.25 → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages}/mapchete/static/process_template.pyc +0 -0
  125. {mapchete-0.25/mapchete.egg-info → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/dependency_links.txt +0 -0
  126. {mapchete-0.25/mapchete.egg-info → home/ungarj/virtualenvs/p3/lib/python3.5/site-packages/mapchete-0.26-py3.5.egg-info}/top_level.txt +0 -0
@@ -0,0 +1,12 @@
1
+ #!/home/ungarj/virtualenvs/p3/bin/python
2
+ # EASY-INSTALL-ENTRY-SCRIPT: 'mapchete==0.26','console_scripts','mapchete'
3
+ __requires__ = 'mapchete==0.26'
4
+ import re
5
+ import sys
6
+ from pkg_resources import load_entry_point
7
+
8
+ if __name__ == '__main__':
9
+ sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
10
+ sys.exit(
11
+ load_entry_point('mapchete==0.26', 'console_scripts', 'mapchete')()
12
+ )
@@ -14,4 +14,4 @@ logging.getLogger("rasterio").setLevel(logging.ERROR)
14
14
  logging.getLogger("fiona").setLevel(logging.ERROR)
15
15
 
16
16
 
17
- __version__ = "0.25"
17
+ __version__ = "0.26"
@@ -10,7 +10,6 @@ from multiprocessing import cpu_count, current_process
10
10
  import numpy as np
11
11
  import numpy.ma as ma
12
12
  from shapely.geometry import shape
13
- import six
14
13
  import threading
15
14
  from tilematrix import TilePyramid
16
15
  import time
@@ -424,11 +423,11 @@ class Mapchete(object):
424
423
 
425
424
  def _read_existing_output(self, tile, output_tiles):
426
425
  if self.config.output.METADATA["data_type"] == "raster":
427
- mosaic, affine = raster.create_mosaic([
426
+ mosaic = raster.create_mosaic([
428
427
  (output_tile, self.read(output_tile))
429
428
  for output_tile in output_tiles
430
429
  ])
431
- return raster.extract_from_array(mosaic, affine, tile)
430
+ return raster.extract_from_array(mosaic.data, mosaic.affine, tile)
432
431
  elif self.config.output.METADATA["data_type"] == "vector":
433
432
  return list(chain.from_iterable([
434
433
  self.read(output_tile) for output_tile in output_tiles
@@ -526,7 +525,7 @@ class Mapchete(object):
526
525
  return self.config.output.empty(process_tile)
527
526
 
528
527
  def _streamline_output(self, process_data):
529
- if isinstance(process_data, six.string_types) and (
528
+ if isinstance(process_data, str) and (
530
529
  process_data == "empty"
531
530
  ):
532
531
  raise MapcheteNodataTile
@@ -562,7 +561,7 @@ class Mapchete(object):
562
561
  )
563
562
  # resample from children tiles
564
563
  elif baselevel == "lower":
565
- mosaic, mosaic_affine = raster.create_mosaic([
564
+ mosaic = raster.create_mosaic([
566
565
  (
567
566
  child_tile,
568
567
  self.get_raw_output(child_tile, _baselevel_readonly=True)
@@ -572,8 +571,8 @@ class Mapchete(object):
572
571
  ).get_children()
573
572
  ])
574
573
  process_data = raster.resample_from_array(
575
- in_raster=mosaic,
576
- in_affine=mosaic_affine,
574
+ in_raster=mosaic.data,
575
+ in_affine=mosaic.affine,
577
576
  out_tile=tile,
578
577
  resampling=self.config.baselevels["lower"],
579
578
  nodataval=self.config.output.nodata
@@ -691,7 +690,7 @@ class MapcheteProcess(object):
691
690
  tiled input data : InputTile
692
691
  reprojected input data within tile
693
692
  """
694
- if not isinstance(input_id, six.string_types):
693
+ if not isinstance(input_id, str):
695
694
  return input_id.open(self.tile, **kwargs)
696
695
  if input_id not in self.params["input"]:
697
696
  raise ValueError("%s not found in config as input file" % input_id)
@@ -0,0 +1,88 @@
1
+ """Create dummy Mapchete and python process files."""
2
+
3
+ import os
4
+ from string import Template
5
+ from shutil import copyfile
6
+ from yaml import dump
7
+ import pkg_resources
8
+
9
+ FORMAT_MANDATORY = {
10
+ "GTiff": {
11
+ "bands": None,
12
+ "dtype": None
13
+ },
14
+ "PNG": {
15
+ "bands": None,
16
+ "dtype": None
17
+ },
18
+ "PNG_hillshade": {
19
+ "bands": 4,
20
+ "dtype": "uint8"
21
+ },
22
+ "GeoJSON": {
23
+ "schema": {}
24
+ },
25
+ "PostGIS": {
26
+ "schema": {},
27
+ "db_params": {
28
+ "host": None,
29
+ "port": None,
30
+ "db": None,
31
+ "user": None,
32
+ "password": None,
33
+ "table": None
34
+ }
35
+ }
36
+ }
37
+
38
+
39
+ def create_empty_process(args):
40
+ """
41
+ Create an empty Mapchete and process file in a given directory.
42
+
43
+ ``Namespace`` object should have the following attributes:
44
+ * process_file : name of the python file
45
+ * mapchete_file : name of the mapchete process configuration file
46
+ * out_format : optional output format
47
+ * out_path : optional output path
48
+ * pyramid_type : optional output type
49
+ * force : if True, it will replace already existing files
50
+
51
+ Parameters
52
+ ----------
53
+ args : argparse.Namespace
54
+ """
55
+ if os.path.isfile(args.process_file) or os.path.isfile(args.mapchete_file):
56
+ if not args.force:
57
+ raise IOError("file(s) already exists")
58
+
59
+ out_path = args.out_path if args.out_path else os.path.join(
60
+ os.getcwd(), "output")
61
+
62
+ # copy process file template to target directory
63
+ process_template = pkg_resources.resource_filename(
64
+ "mapchete.static", "process_template.py")
65
+ process_file = os.path.join(os.getcwd(), args.process_file)
66
+ copyfile(process_template, process_file)
67
+
68
+ # modify and copy mapchete file template to target directory
69
+ mapchete_template = pkg_resources.resource_filename(
70
+ "mapchete.static", "mapchete_template.mapchete")
71
+
72
+ output_options = {
73
+ 'format': args.out_format,
74
+ 'path': out_path}
75
+ output_options.update(FORMAT_MANDATORY[args.out_format])
76
+
77
+ pyramid_options = {'grid': args.pyramid_type}
78
+
79
+ substitute_elements = {
80
+ 'process_file': process_file,
81
+ 'output': dump({'output': output_options}, default_flow_style=False),
82
+ 'pyramid': dump({'pyramid': pyramid_options}, default_flow_style=False)
83
+ }
84
+ with open(mapchete_template, 'r') as config_template:
85
+ config = Template(config_template.read())
86
+ customized_config = config.substitute(substitute_elements)
87
+ with open(args.mapchete_file, 'w') as target_config:
88
+ target_config.write(customized_config)
@@ -0,0 +1,171 @@
1
+ """Command line utility to execute a Mapchete process."""
2
+
3
+ import click
4
+ import click_spinner
5
+ import logging
6
+ from multiprocessing import cpu_count
7
+ import os
8
+ from shapely import wkt
9
+ import sys
10
+ import tqdm
11
+ import yaml
12
+
13
+ import mapchete
14
+ from mapchete.cli import utils
15
+ from mapchete.config import get_zoom_levels, _map_to_new_config
16
+ from mapchete.index import zoom_index_gen
17
+ from mapchete.tile import BufferedTilePyramid
18
+
19
+
20
+ # workaround for https://github.com/tqdm/tqdm/issues/481
21
+ tqdm.monitor_interval = 0
22
+
23
+ logger = logging.getLogger(__name__)
24
+
25
+
26
+ @click.command(help="Execute a process.")
27
+ @utils.arg_mapchete_files
28
+ @utils.opt_zoom
29
+ @utils.opt_bounds
30
+ @utils.opt_point
31
+ @utils.opt_wkt_geometry
32
+ @utils.opt_tile
33
+ @utils.opt_overwrite
34
+ @utils.opt_multi
35
+ @utils.opt_input_file
36
+ @utils.opt_logfile
37
+ @utils.opt_verbose
38
+ @utils.opt_no_pbar
39
+ @utils.opt_debug
40
+ @utils.opt_max_chunksize
41
+ @utils.opt_vrt
42
+ @utils.opt_idx_out_dir
43
+ def execute(
44
+ mapchete_files,
45
+ zoom=None,
46
+ bounds=None,
47
+ point=None,
48
+ wkt_geometry=None,
49
+ tile=None,
50
+ overwrite=False,
51
+ multi=None,
52
+ input_file=None,
53
+ logfile=None,
54
+ verbose=False,
55
+ no_pbar=False,
56
+ debug=False,
57
+ max_chunksize=None,
58
+ vrt=False,
59
+ idx_out_dir=None
60
+ ):
61
+ """Execute a Mapchete process."""
62
+ multi = multi if multi else cpu_count()
63
+ mode = "overwrite" if overwrite else "continue"
64
+ # send verbose output to /dev/null if not activated
65
+ if debug or not verbose:
66
+ verbose_dst = open(os.devnull, 'w')
67
+ else:
68
+ verbose_dst = sys.stdout
69
+
70
+ for mapchete_file in mapchete_files:
71
+
72
+ tqdm.tqdm.write("preparing to process %s" % mapchete_file, file=verbose_dst)
73
+
74
+ with click_spinner.spinner(disable=debug) as spinner:
75
+
76
+ def _raw_conf():
77
+ return _map_to_new_config(
78
+ yaml.load(open(mapchete_file, "r").read())
79
+ )
80
+
81
+ def _tp():
82
+ return BufferedTilePyramid(
83
+ _raw_conf()["pyramid"]["grid"],
84
+ metatiling=_raw_conf()["pyramid"].get("metatiling", 1),
85
+ pixelbuffer=_raw_conf()["pyramid"].get("pixelbuffer", 0)
86
+ )
87
+
88
+ # process single tile
89
+ if tile:
90
+ tile = _tp().tile(*tile)
91
+ with mapchete.open(
92
+ mapchete_file, mode=mode, bounds=tile.bounds,
93
+ zoom=tile.zoom, single_input_file=input_file
94
+ ) as mp:
95
+ spinner.stop()
96
+ tqdm.tqdm.write("processing 1 tile")
97
+ for result in mp.batch_processor(tile=tile):
98
+ utils.write_verbose_msg(result, dst=verbose_dst)
99
+
100
+ if vrt:
101
+ tqdm.tqdm.write("creating VRT")
102
+ for tile in tqdm.tqdm(
103
+ zoom_index_gen(
104
+ mp=mp,
105
+ zoom=tile.zoom,
106
+ out_dir=(
107
+ idx_out_dir if idx_out_dir else mp.config.output.path
108
+ ),
109
+ vrt=vrt,
110
+ ),
111
+ total=mp.count_tiles(tile.zoom, tile.zoom),
112
+ unit="tile",
113
+ disable=debug
114
+ ):
115
+ logger.debug(tile)
116
+
117
+ # initialize and run process
118
+ else:
119
+ if wkt_geometry:
120
+ bounds = wkt.loads(wkt_geometry).bounds
121
+ elif point:
122
+ x, y = point
123
+ zoom_levels = get_zoom_levels(
124
+ process_zoom_levels=_raw_conf()["zoom_levels"],
125
+ init_zoom_levels=zoom
126
+ )
127
+ bounds = _tp().tile_from_xy(x, y, max(zoom_levels)).bounds
128
+ else:
129
+ bounds = bounds
130
+ with mapchete.open(
131
+ mapchete_file, bounds=bounds, zoom=zoom,
132
+ mode=mode, single_input_file=input_file
133
+ ) as mp:
134
+ spinner.stop()
135
+ tiles_count = mp.count_tiles(
136
+ min(mp.config.init_zoom_levels),
137
+ max(mp.config.init_zoom_levels))
138
+ tqdm.tqdm.write(
139
+ "processing %s tile(s) on %s worker(s)" % (tiles_count, multi)
140
+ )
141
+ for process_info in tqdm.tqdm(
142
+ mp.batch_processor(
143
+ multi=multi, zoom=zoom,
144
+ max_chunksize=max_chunksize),
145
+ total=tiles_count,
146
+ unit="tile",
147
+ disable=debug or no_pbar
148
+ ):
149
+ utils.write_verbose_msg(process_info, dst=verbose_dst)
150
+
151
+ if vrt:
152
+ tqdm.tqdm.write("creating VRT(s)")
153
+ for z in mp.config.init_zoom_levels:
154
+ logger.debug("zoom %s", z)
155
+ for tile in tqdm.tqdm(
156
+ zoom_index_gen(
157
+ mp=mp,
158
+ zoom=z,
159
+ out_dir=(
160
+ idx_out_dir if idx_out_dir
161
+ else mp.config.output.path
162
+ ),
163
+ vrt=vrt
164
+ ),
165
+ total=mp.count_tiles(z, z),
166
+ unit="tile",
167
+ disable=debug
168
+ ):
169
+ logger.debug(tile)
170
+
171
+ tqdm.tqdm.write("process finished", file=verbose_dst)
@@ -0,0 +1,143 @@
1
+ """Create index for process output."""
2
+
3
+ import click
4
+ import click_spinner
5
+ import logging
6
+ import os
7
+ from shapely import wkt
8
+ import sys
9
+ import tqdm
10
+ import yaml
11
+
12
+ import mapchete
13
+ from mapchete.cli import utils
14
+ from mapchete.config import _map_to_new_config
15
+ from mapchete.index import zoom_index_gen
16
+ from mapchete.tile import BufferedTilePyramid
17
+
18
+
19
+ # workaround for https://github.com/tqdm/tqdm/issues/481
20
+ tqdm.monitor_interval = 0
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ @click.command(help="Create index of output tiles.")
26
+ @utils.arg_mapchete_files
27
+ @utils.opt_idx_out_dir
28
+ @utils.opt_geojson
29
+ @utils.opt_gpkg
30
+ @utils.opt_shp
31
+ @utils.opt_vrt
32
+ @utils.opt_txt
33
+ @utils.opt_fieldname
34
+ @utils.opt_basepath
35
+ @utils.opt_for_gdal
36
+ @utils.opt_zoom
37
+ @utils.opt_bounds
38
+ @utils.opt_wkt_geometry
39
+ @utils.opt_tile
40
+ @utils.opt_verbose
41
+ @utils.opt_debug
42
+ @utils.opt_logfile
43
+ def index(
44
+ mapchete_files,
45
+ idx_out_dir=None,
46
+ geojson=False,
47
+ gpkg=False,
48
+ shp=False,
49
+ vrt=False,
50
+ txt=False,
51
+ fieldname=None,
52
+ basepath=None,
53
+ for_gdal=False,
54
+ zoom=None,
55
+ bounds=None,
56
+ wkt_geometry=None,
57
+ tile=None,
58
+ verbose=False,
59
+ debug=False,
60
+ logfile=None
61
+ ):
62
+ if not any([geojson, gpkg, shp, txt, vrt]):
63
+ raise click.MissingParameter(
64
+ """At least one of '--geojson', '--gpkg', '--shp', '--vrt' or '--txt'"""
65
+ """must be provided.""",
66
+ param_type="option"
67
+ )
68
+
69
+ # send verbose output to /dev/null if not activated
70
+ verbose_dst = open(os.devnull, 'w') if debug or not verbose else sys.stdout
71
+
72
+ for mapchete_file in mapchete_files:
73
+ tqdm.tqdm.write("create index for %s" % mapchete_file, file=verbose_dst)
74
+ with click_spinner.spinner(disable=debug) as spinner:
75
+ # process single tile
76
+ if tile:
77
+ conf = _map_to_new_config(
78
+ yaml.load(open(mapchete_file, "r").read()))
79
+ tile = BufferedTilePyramid(
80
+ conf["pyramid"]["grid"],
81
+ metatiling=conf["pyramid"].get("metatiling", 1),
82
+ pixelbuffer=conf["pyramid"].get("pixelbuffer", 0)
83
+ ).tile(*tile)
84
+ with mapchete.open(
85
+ mapchete_file, mode="readonly", bounds=tile.bounds,
86
+ zoom=tile.zoom
87
+ ) as mp:
88
+ spinner.stop()
89
+ for tile in tqdm.tqdm(
90
+ zoom_index_gen(
91
+ mp=mp,
92
+ zoom=tile.zoom,
93
+ out_dir=idx_out_dir if idx_out_dir else mp.config.output.path,
94
+ geojson=geojson,
95
+ gpkg=gpkg,
96
+ shapefile=shp,
97
+ vrt=vrt,
98
+ txt=txt,
99
+ fieldname=fieldname,
100
+ basepath=basepath,
101
+ for_gdal=for_gdal
102
+ ),
103
+ total=mp.count_tiles(tile.zoom, tile.zoom),
104
+ unit="tile",
105
+ disable=debug
106
+ ):
107
+ logger.debug(tile)
108
+
109
+ else:
110
+ with mapchete.open(
111
+ mapchete_file,
112
+ mode="readonly",
113
+ zoom=zoom,
114
+ bounds=wkt.loads(wkt_geometry).bounds if wkt_geometry else bounds
115
+ ) as mp:
116
+ spinner.stop()
117
+ logger.debug("process bounds: %s", mp.config.init_bounds)
118
+ logger.debug("process zooms: %s", mp.config.init_zoom_levels)
119
+ logger.debug("fieldname: %s", fieldname)
120
+ for z in mp.config.init_zoom_levels:
121
+ logger.debug("zoom %s", z)
122
+ for tile in tqdm.tqdm(
123
+ zoom_index_gen(
124
+ mp=mp,
125
+ zoom=z,
126
+ out_dir=(
127
+ idx_out_dir if idx_out_dir else mp.config.output.path
128
+ ),
129
+ geojson=geojson,
130
+ gpkg=gpkg,
131
+ shapefile=shp,
132
+ vrt=vrt,
133
+ txt=txt,
134
+ fieldname=fieldname,
135
+ basepath=basepath,
136
+ for_gdal=for_gdal),
137
+ total=mp.count_tiles(z, z),
138
+ unit="tile",
139
+ disable=debug
140
+ ):
141
+ logger.debug(tile)
142
+
143
+ tqdm.tqdm.write("index creation finished", file=verbose_dst)
@@ -147,4 +147,3 @@ def _get_zoom(zoom, input_raster, pyramid_type):
147
147
  minzoom = zoom[1]
148
148
  maxzoom = zoom[0]
149
149
  return minzoom, maxzoom
150
-
@@ -7,7 +7,6 @@ import logging.config
7
7
  import os
8
8
  import pkgutil
9
9
  from rasterio.io import MemoryFile
10
- import six
11
10
 
12
11
  import mapchete
13
12
  from mapchete.cli import utils
@@ -76,7 +75,7 @@ def create_app(
76
75
  for mapchete_file in mapchete_files
77
76
  }
78
77
 
79
- mp = next(six.iteritems(mapchete_processes))[1]
78
+ mp = next(iter(mapchete_processes.values()))
80
79
  pyramid_type = mp.config.process_pyramid.grid
81
80
  pyramid_srid = mp.config.process_pyramid.srid
82
81
  process_bounds = ",".join([str(i) for i in mp.config.bounds_at_zoom()])
@@ -92,7 +91,7 @@ def create_app(
92
91
  srid=pyramid_srid,
93
92
  process_bounds=process_bounds,
94
93
  is_mercator=(pyramid_srid == 3857),
95
- process_names=six.iterkeys(mapchete_processes)
94
+ process_names=mapchete_processes.keys()
96
95
  )
97
96
 
98
97
  @app.route(