test_v_clip.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """
  2. Name: v.clip test
  3. Purpose: Tests v.clip input parsing.
  4. Uses NC Basic data set.
  5. Author: Luca Delucchi
  6. Copyright: (C) 2017 by Luca Delucchi and the GRASS Development Team
  7. Licence: This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. """
  11. import os
  12. from grass.gunittest.case import TestCase
  13. from grass.gunittest.main import test
  14. class TestClipling(TestCase):
  15. inpclip = "zipcodes"
  16. inpoint = "hospitals"
  17. inlines = "roadsmajor"
  18. inpoly = "geology"
  19. outreg = "hospreg"
  20. outclip = "hospzip"
  21. outline = "roadsgarner"
  22. outpoly = "geogarner"
  23. outdiss = "geodiss"
  24. garner = "garner"
  25. @classmethod
  26. def setUpClass(cls):
  27. """Ensures expected computational region and generated data"""
  28. cls.use_temp_region()
  29. cls.runModule("g.region", vector=cls.inpclip)
  30. cls.runModule(
  31. "v.extract",
  32. input=cls.inpclip,
  33. output=cls.garner,
  34. where="ZIPNAME = '{na}'".format(na=cls.garner.upper()),
  35. )
  36. @classmethod
  37. def tearDownClass(cls):
  38. """Remove the temporary region and generated data"""
  39. cls.runModule(
  40. "g.remove",
  41. flags="f",
  42. type="vector",
  43. name=(
  44. cls.outclip,
  45. cls.outreg,
  46. cls.garner,
  47. cls.outline,
  48. cls.outpoly,
  49. cls.outdiss,
  50. ),
  51. )
  52. cls.del_temp_region()
  53. def test_points(self):
  54. """Test clipping points"""
  55. self.assertModule(
  56. "v.clip", input=self.inpoint, clip=self.inpclip, output=self.outclip
  57. )
  58. self.assertVectorExists(self.outclip)
  59. topology = dict(points=8)
  60. self.assertVectorFitsTopoInfo(self.outclip, topology)
  61. def test_region(self):
  62. """Test clipping point by region"""
  63. self.assertModule(
  64. "v.clip",
  65. input=self.inpoint,
  66. clip=self.inpclip,
  67. output=self.outreg,
  68. flags="r",
  69. )
  70. self.assertVectorExists(self.outreg)
  71. topology = dict(points=13)
  72. self.assertVectorFitsTopoInfo(self.outreg, topology)
  73. def test_lines(self):
  74. """Test clipping lines"""
  75. self.assertModule(
  76. "v.clip", input=self.inlines, clip=self.garner, output=self.outline
  77. )
  78. self.assertVectorExists(self.outline)
  79. topology = dict(lines=13, nodes=16)
  80. self.assertVectorFitsTopoInfo(self.outline, topology)
  81. def test_poly(self):
  82. """Test clipping polygon without dissolve"""
  83. self.assertModule(
  84. "v.clip", input=self.inpoly, clip=self.inpclip, output=self.outpoly
  85. )
  86. self.assertVectorExists(self.outpoly)
  87. topology = dict(areas=275)
  88. self.assertVectorFitsTopoInfo(self.outpoly, topology)
  89. def test_poly_diss(self):
  90. """Test clipping polygon without dissolve"""
  91. self.assertModule(
  92. "v.clip",
  93. input=self.inpoly,
  94. clip=self.inpclip,
  95. output=self.outdiss,
  96. flags="d",
  97. )
  98. self.assertVectorExists(self.outdiss)
  99. topology = dict(areas=276)
  100. self.assertVectorFitsTopoInfo(self.outdiss, topology)
  101. if __name__ == "__main__":
  102. test()