test_v_clip.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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('v.extract', input=cls.inpclip, output=cls.garner,
  31. where="ZIPNAME = '{na}'".format(na=cls.garner.upper()))
  32. @classmethod
  33. def tearDownClass(cls):
  34. """Remove the temporary region and generated data"""
  35. cls.runModule('g.remove', flags='f', type='vector',
  36. name=(cls.outclip, cls.outreg, cls.garner, cls.outline,
  37. cls.outpoly, cls.outdiss))
  38. cls.del_temp_region()
  39. def test_points(self):
  40. """Test clipping points"""
  41. self.assertModule('v.clip', input=self.inpoint, clip=self.inpclip,
  42. output=self.outclip)
  43. self.assertVectorExists(self.outclip)
  44. topology = dict(points=8)
  45. self.assertVectorFitsTopoInfo(self.outclip, topology)
  46. def test_region(self):
  47. """Test clipping point by region"""
  48. self.assertModule('v.clip', input=self.inpoint, clip=self.inpclip,
  49. output=self.outreg, flags='r')
  50. self.assertVectorExists(self.outreg)
  51. topology = dict(points=13)
  52. self.assertVectorFitsTopoInfo(self.outreg, topology)
  53. def test_lines(self):
  54. """Test clipping lines"""
  55. self.assertModule('v.clip', input=self.inlines, clip=self.garner,
  56. output=self.outline)
  57. self.assertVectorExists(self.outline)
  58. topology = dict(lines=13, nodes=16)
  59. self.assertVectorFitsTopoInfo(self.outline, topology)
  60. def test_poly(self):
  61. """Test clipping polygon without dissolve"""
  62. self.assertModule('v.clip', input=self.inpoly, clip=self.inpclip,
  63. output=self.outpoly)
  64. self.assertVectorExists(self.outpoly)
  65. topology = dict(areas=275)
  66. self.assertVectorFitsTopoInfo(self.outpoly, topology)
  67. def test_poly_diss(self):
  68. """Test clipping polygon without dissolve"""
  69. self.assertModule('v.clip', input=self.inpoly, clip=self.inpclip,
  70. output=self.outdiss, flags='d')
  71. self.assertVectorExists(self.outdiss)
  72. topology = dict(areas=276)
  73. self.assertVectorFitsTopoInfo(self.outdiss, topology)
  74. if __name__ == '__main__':
  75. test()