factory.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # i18N
  14. import gettext
  15. from .core import get_tgis_message_interface
  16. from .space_time_datasets import SpaceTimeRaster3DDataset, SpaceTimeRasterDataset, \
  17. SpaceTimeVectorDataset, Raster3DDataset, RasterDataset, VectorDataset
  18. ###############################################################################
  19. def dataset_factory(type, id):
  20. """A factory functions to create space time or map datasets
  21. :param type: the dataset type: rast or raster; rast3d, raster3d or raster_3d;
  22. vect or vector; strds; str3ds; stvds
  23. :param id: The id of the dataset ("name@mapset")
  24. """
  25. if type == "strds":
  26. sp = SpaceTimeRasterDataset(id)
  27. elif type == "str3ds":
  28. sp = SpaceTimeRaster3DDataset(id)
  29. elif type == "stvds":
  30. sp = SpaceTimeVectorDataset(id)
  31. elif type == "rast" or type == "raster":
  32. sp = RasterDataset(id)
  33. elif type == "raster_3d" or type == "rast3d" or type == "raster3d":
  34. sp = Raster3DDataset(id)
  35. elif type == "vect" or type == "vector":
  36. sp = VectorDataset(id)
  37. else:
  38. msgr = get_tgis_message_interface()
  39. msgr.error(_("Unknown dataset type: %s") % type)
  40. return None
  41. return sp