factory.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Object factory
  3. Usage:
  4. .. code-block:: python
  5. import grass.temporal as tgis
  6. tgis.register_maps_in_space_time_dataset(type, name, maps)
  7. (C) 2012-2013 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. :authors: Soeren Gebbert
  12. """
  13. from .core import get_tgis_message_interface
  14. from .space_time_datasets import (
  15. SpaceTimeRaster3DDataset,
  16. SpaceTimeRasterDataset,
  17. SpaceTimeVectorDataset,
  18. Raster3DDataset,
  19. RasterDataset,
  20. VectorDataset,
  21. )
  22. ###############################################################################
  23. def dataset_factory(type, id):
  24. """A factory functions to create space time or map datasets
  25. :param type: the dataset type: rast or raster; rast3d, raster3d or raster_3d;
  26. vect or vector; strds; str3ds; stvds
  27. :param id: The id of the dataset ("name@mapset")
  28. """
  29. if type == "strds":
  30. sp = SpaceTimeRasterDataset(id)
  31. elif type == "str3ds":
  32. sp = SpaceTimeRaster3DDataset(id)
  33. elif type == "stvds":
  34. sp = SpaceTimeVectorDataset(id)
  35. elif type == "rast" or type == "raster":
  36. sp = RasterDataset(id)
  37. elif type == "raster_3d" or type == "rast3d" or type == "raster3d":
  38. sp = Raster3DDataset(id)
  39. elif type == "vect" or type == "vector":
  40. sp = VectorDataset(id)
  41. else:
  42. msgr = get_tgis_message_interface()
  43. msgr.error(_("Unknown dataset type: %s") % type)
  44. return None
  45. return sp