1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 """
32 This module contains the definition of coverage and dataset series
33 interfaces. These provide a harmonized interface to coverage data that
34 can be stored in different formats and has different types.
35 """
36
37 from datetime import datetime
38
39 from django.contrib.gis.geos import GEOSGeometry
40
41 from eoxserver.core.interfaces import *
42 from eoxserver.core.registry import RegisteredInterface
43 from eoxserver.core.records import RecordWrapperInterface
44 from eoxserver.core.resources import ResourceInterface
45 from eoxserver.resources.coverages.rangetype import RangeType
46
47
48
49
50
52 """
53 This interface shall be implemented by Data Sources. They represent
54 locations where information about a collection of Data Packages
55 can be retrieved.
56
57 .. method:: detect
58
59 This method shall return a list of Data Packages, i.e. objects
60 implementing :class:`DataPackageInterface`, related to the
61 Data Source.
62
63 .. method:: contains
64
65 This method shall return ``True`` if a data source references
66 a dataset, ``False`` otherwise.
67
68 """
69
70 REGISTRY_CONF = {
71 "name": "Data Source Interface",
72 "intf_id": "backends.interfaces.DataSource",
73 "binding_method": "factory"
74 }
75
76 detect = Method(
77 returns = ListArg("@return")
78 )
79
80 contains = Method(
81 ObjectArg("wrapper"),
82 returns = BoolArg("@return")
83 )
84
86 """
87 This is the common base interface for coverage data.
88
89 ..
90
91 .. method:: getDataStructureType
92
93 This method shall return a string denoting the data structure
94 type of the data.
95 """
96
97 REGISTRY_CONF = {
98 "name": "Coverage Data Interface",
99 "intf_id": "resources.coverages.interfaces.CoverageData",
100 "binding_method": "factory"
101 }
102
103 getDataStructureType = Method(
104 returns = StringArg("@return")
105 )
106
108 """
109 This interface shall be implemented by Data Packages. Data Packages
110 provide an abstraction layer for various kinds of file-based or
111 database-based datasets. Internally, data packages store information
112 about the location of the original data and (for remote backends) the
113 location of a locally accessible copy.
114
115 Methods for high-level data access:
116
117 .. method:: open
118
119 This method shall open the data package. It shall return an
120 object representing the underlying dataset in the engine
121 defined by the data format of the data package.
122
123 .. method:: getLocation
124
125 Returns the location of the data, i.e. an object that implements
126 :class:`~.LocationInterface`. Note that this location is not necessarily
127 directly accessible from the local file system or operating system, but
128 may be remote. For fetching an accessible location, see
129 :meth:`prepareAccess` and :meth:`getAccessibleLocation`.
130
131 .. method:: getMetadataLocation
132
133 Returns the location of the metadata, i.e. an object that implements
134 :class:`~.LocationInterface`.
135
136 .. method:: readGeospatialMetadata(default_srid=None)
137
138 This method shall return an object containing the geospatial
139 metadata stored with the data package. It accepts an optional
140 ``default_srid`` parameter which indicates the SRID to use if it cannot
141 be read from the data package.
142
143 .. method:: readEOMetadata
144
145 This method shall return an object containing the EO metadata
146 required by EOxServer and stored with the data package.
147
148 Methods for low-level data access; use these with care:
149
150 .. method:: prepareAccess
151
152 This method has to be called before any attempt to actually
153 access the data. It shall prepare access, e.g. by retrieving
154 remote data or unpacking complex packages, so that subsequent
155 calls to :meth:`getAccessibleLocation` and
156 :meth:`getAccessiblePath` can return meaningful results. It
157 shall raise :exc:`~.DataAccessError` in case of an error.
158
159 .. method:: getAccessibleLocation
160
161 This method shall return a location, i.e. an object implementing
162 :class:`LocationInterface`. An :exc:`InternalError` shall be
163 raised if the data package is not accessible (e.g. because
164 :meth:`prepareAccess` has not been called or the call failed)
165
166 .. method:: getGDALDatasetIdentifier
167
168 This method shall return a string to be used to open the data package
169 in GDAL. It shall raise :exc:`~.InternalError` if the data package
170 cannot be opened in GDAL.
171
172 """
173 REGISTRY_CONF = {
174 "name": "Data Package Interface",
175 "intf_id": "resources.coverages.interfaces.DataPackage",
176 "binding_method": "factory"
177 }
178
179 getType = Method(
180 returns = StringArg("@return")
181 )
182
183 open = Method(
184 returns = ObjectArg("@return")
185 )
186
187 getLocation = Method(
188 returns = ObjectArg("@return")
189 )
190
191 getMetadataLocation = Method(
192 returns = ObjectArg("@return")
193 )
194
195 getCoverages = Method(
196 returns = ListArg("@return")
197 )
198
199 readGeospatialMetadata = Method(
200 IntArg("default_srid", default=None),
201 returns = ObjectArg("@return")
202 )
203
204 readEOMetadata = Method(
205 returns = ObjectArg("@return")
206 )
207
208 prepareAccess = Method()
209
210 getAccessibleLocation = Method(
211 returns = ObjectArg("@return")
212 )
213
214 getGDALDatasetIdentifier = Method(
215 returns = StringArg("@return")
216 )
217
218
220 """
221 This interface provides the methods necessary to access tile index
222 information for coverages.
223
224 :Interface ID: resources.coverages.interfaces.TileIndex
225
226 .. method:: getShapeFilePath
227
228 This method shall return the path to the shape file that holds
229 information about the tiles the coverage is split up into.
230 """
231 REGISTRY_CONF = {
232 "name": "Tile Index Interface",
233 "intf_id": "resources.coverages.interfaces.TileIndex",
234 "binding_method": "factory"
235 }
236
237 getShapeFilePath = Method(
238 returns=StringArg("@return")
239 )
240
241
242
243
244
292
318
365
419
429
468
469
470
471
472
474 """
475 The parent class of all coverage interfaces. It defines methods for
476 access to coverage data. It inherits from
477 :class:`~.ResourceInterface`.
478
479 :Interface ID: resources.coverages.interfaces.Coverage
480
481 .. method:: getCoverageId
482
483 This method shall return the coverage id of the coverage resource
484 wrapped by the implementation
485
486 .. method:: getCoverageSubtype
487
488 This method shall return the GML coverage subtype of the coverage
489 resource wrapped by the implementation
490
491 .. method:: getType
492
493 This method shall return the EOxServer coverage type of the
494 coverage wrapped by the implementation. Current choices are:
495
496 * ``file``
497 * ``eo.rect_dataset``
498 * ``eo.ref_dataset``
499 * ``eo.rect_stitched_mosaic``
500
501 .. method:: getSize
502
503 This method shall return the size of the coverage wrapped by the
504 implementation. The return value is expected to be a 2-tuple
505 of integers ``(xsize, ysize)``.
506
507 .. method:: getRangeType
508
509 This method shall return a :class:`~.RangeType` instance
510 containing the data type and band structure of the coverage
511 wrapped by the implementation
512
513 .. method:: getDataStructureType
514
515 This method shall return the type of the data structure that contains the
516 coverage's data. See :meth:`CoverageDataInterface.getDataStructureType`.
517 Note that this does not define the implementation of the coverage data
518 object returned with :meth:`getData`.
519
520 .. method:: getData
521
522 This method shall return an object that provides access to the coverage
523 data, i.e. an implementation of :class:`CoverageDataInterface`.
524
525 .. method:: getLayerMetadata
526
527 This method shall return a list containing 2-tuples of MapServer
528 metadata key-value-pairs that will be tagged on the MapServer
529 layer representing this coverage.
530 """
531
532 REGISTRY_CONF = {
533 "name": "Coverage Interface",
534 "intf_id": "resources.coverages.interfaces.Coverage"
535 }
536
537
538 getCoverageId = Method(
539 returns=StringArg("@return")
540 )
541
542 getCoverageSubtype = Method(
543 returns=StringArg("@return")
544 )
545
546 getType = Method(
547 returns=StringArg("@return")
548 )
549
550 getSize = Method(
551 returns=ObjectArg("@return", arg_class=tuple)
552 )
553
554 getRangeType = Method(
555 returns=ObjectArg("@return", arg_class=RangeType)
556 )
557
558 getDataStructureType = Method(
559 returns=StringArg("@return")
560 )
561
562 getData = Method(
563 returns=ObjectArg("@return")
564 )
565
566 getLayerMetadata = Method(
567 returns=ListArg("@return", arg_class=tuple)
568 )
569
570 matches = Method(
571 ListArg("filter_exprs"),
572 returns=BoolArg("@return")
573 )
574
576 """
577 This interface defines methods to access rectified grid information,
578 namely the coordinate reference system ID and the geographical
579 extent of the coverage. It is intended to be used as mix-in for
580 coverage interfaces.
581
582 :Interface ID: resources.coverages.interfaces.RectifiedGrid
583
584 .. method:: getSRID
585
586 This method shall return the EPSG SRID of the coverage's
587 coordinate reference system (CRS)
588
589 .. method:: getExtent
590
591 This method shall return the extent of the coverage wrapped by
592 the implementation. The return value is expected to be a 4-tuple
593 of floating point coordinates (minx, miny, maxx, maxy) expressed
594 in the CRS described by the SRID returned with :meth:`getSRID`.
595 """
596
597 REGISTRY_CONF = {
598 "name": "Rectified Grid Interface (mix-in for coverages)",
599 "intf_id": "resources.coverages.interfaces.RectifiedGrid"
600 }
601
602 getSRID = Method(
603 returns=IntArg("@return")
604 )
605
606 getExtent = Method(
607 returns=ObjectArg("@return", arg_class=tuple)
608 )
609
610 getResolution = Method(
611 returns=ObjectArg("@return", arg_class=tuple)
612 )
613
615 """
616 This interface defines methods for access to referenceable grid
617 information.
618
619 :Interface ID: resources.coverages.interfaces.ReferenceableGrid
620
621 .. method:: getSRID
622
623 This method shall return the EPSG SRID of the coordinate reference
624 system (CRS) of the coverages tie-points.
625
626 .. method:: getExtent
627
628 This method shall return the extent of the coverage wrapped by
629 the implementation. The return value is expected to be a 4-tuple
630 of floating point coordinates (minx, miny, maxx, maxy) expressed
631 in the CRS described by the SRID returned with :meth:`getSRID`.
632 """
633
634 REGISTRY_CONF = {
635 "name": "Referenceable Grid Interface (mix-in for coverages)",
636 "intf_id": "resources.coverages.interfaces.ReferenceableGrid"
637 }
638
639 getSRID = Method(
640 returns=IntArg("@return")
641 )
642
643 getExtent = Method(
644 returns=ObjectArg("@return", arg_class=tuple)
645 )
646
647
649 """
650 This is the interface for EO Coverage subtypes as defined by the
651 Earth Observation Application Profile for WCS 2.0. It inherits from
652 :class:`EOMetadataInterface`. It should not be implemented directly; you'd
653 rather use its descendants.
654
655 .. method:: getWGS84Extent
656
657 This method shall return the WGS 84 extent of the EO coverage
658 wrapped by the implementation. The return value shall be a 4-tuple
659 of floating point coordinates (minlon, minlat, maxlon, maxlat)
660 given in the WGS 84 coordinate system (EPSG:4326).
661
662 .. method:: getEOGML
663
664 This method shall return the EO GML (EO O&M) conformant metadata
665 stored with the EO coverage. If no EO O&M metadata is available,
666 the empty string will be returned
667
668 """
669
670 REGISTRY_CONF = {
671 "name": "Interface for EO-WCS Objects",
672 "intf_id": "resources.coverages.interfaces.EOWCSObject"
673 }
674
675 getWGS84Extent = Method(
676 returns=ObjectArg("@return", arg_class=tuple)
677 )
678
679 getEOGML = Method(
680 returns=StringArg("@return")
681 )
682
684 """
685 This interface is the base interface for implementations of EO
686 Coverages according to the WCS 2.0 EO-AP (EO-WCS). It inherits from
687 :class:`CoverageInterface` and class:`EOWCSObjectInterface`. It is not
688 intended to be implemented directly; rather one of its descendants shall
689 be used.
690
691 :Interface ID: resources.coverages.interfaces.EOCoverage
692
693 .. method:: getEOCoverageSubtype
694
695 This method shall return the EO coverage subtype of the coverage
696 wrapped by the implementation
697
698 .. method:: getDatasets(filter_exprs=None)
699
700 This method shall return a list of dataset wrappers for the
701 datasets contained in the coverage wrapped by the implemention.
702 The optional ``filter_exprs`` argument is expected to be a list
703 of filter expressions to be applied to the datasets or ``None``.
704 In case no contained dataset matches the filter expressions an
705 empty list shall be returned.
706
707 In case of atomic coverages which do not contain any datasets
708 (e.g. RectifiedDatasets themselves) a list containing the
709 coverage wrapper itself shall be returned. In case filter
710 expressions are provided with the call these shall be applied;
711 if the coverage does not match them an empty list shall be
712 returned.
713
714 .. method:: getLineage
715
716 This method shall return the content of the lineage object stored
717 with the EO coverage wrapped by the implementation. Note that this
718 element is not yet specified in detail in the specification at
719 the moment (2011-05-26). If no lineage is available, None shall
720 be returned.
721
722 .. method:: getContainers
723
724 This method shall return a list of container wrappers (Stitched
725 Mosaic or Dataset Series wrappers) the coverage is contained in.
726 The empty list shall be returned if the coverage is not related
727 to any container object.
728
729 .. method:: getContainerCount
730
731 This method shall return the number of container objects the
732 EO Coverage is contained in.
733
734 .. method:: containedIn(res_id)
735
736 This method shall return ``True`` if the EO coverage is
737 contained in the container object (Stitched Mosaic or Dataset
738 Series) specified by the ``wrapper``, ``False`` otherwise.
739
740 .. method:: contains(res_id)
741
742 This method shall return ``True`` if the EO coverage is a
743 container object and contains the coverage with resource
744 specified by the ``wrapper``, ``False`` otherwise.
745 """
746 REGISTRY_CONF = {
747 "name": "EO Coverage Interface",
748 "intf_id": "resources.coverages.interfaces.EOCoverage"
749 }
750
751
752 getEOCoverageSubtype = Method(
753 returns=StringArg("@return")
754 )
755
756 getDatasets = Method(
757 ListArg("filter_exprs", default=None),
758 returns=ListArg("@return")
759 )
760
761 getLineage = Method(
762 returns=ObjectArg("@return")
763 )
764
765 getContainers = Method(
766 returns=ListArg("@return")
767 )
768
769 getContainerCount = Method(
770 returns=IntArg("@return")
771 )
772
773 containedIn = Method(
774 ObjectArg("wrapper"),
775 returns=BoolArg("@return")
776 )
777
778 contains = Method(
779 ObjectArg("wrapper"),
780 returns=BoolArg("@return")
781 )
782
784 """
785 This class is intended for implementations of RectifiedDataset
786 objects according to the WCS 2.0 EO-AP (EO-WCS). It inherits from
787 :class:`~.EODatasetInterface` and :class:`~.RectifiedGridInterface`.
788
789 :Interface ID: resources.coverages.interfaces.RectifiedDataset
790 """
791 REGISTRY_CONF = {
792 "name": "Rectified Dataset Interface",
793 "intf_id": "resources.coverages.interfaces.RectifiedDataset"
794 }
795
797 """
798 This class is intended for implementations of RectifiedDataset
799 objects according to the WCS 2.0 EO-AP (EO-WCS). It inherits from
800 :class:`~.EODatasetInterface` and
801 :class:`ReferenceableGridInterface`.
802
803 .. note:: the design of this interface is still TBD
804
805 :Interface ID: resources.coverages.interfaces.ReferenceableDataset
806
807 """
808 REGISTRY_CONF = {
809 "name": "Referenceable Dataset Interface",
810 "intf_id": "resources.coverages.interfaces.ReferenceableDataset"
811 }
812
814 """
815 This is the common interface for coverages and series containing
816 EO Coverages.
817
818 .. method:: contains(wrapper)
819
820 Returns a boolean value describing if the container contains the resource
821 specified by the given ``wrapper``.
822
823 .. method:: addCoverage(wrapper)
824
825 Add resource specified by the given ``wrapper``.
826
827 .. method:: removeCoverage(wrapper)
828
829 Remove resource specified by the given ``wrapper``.
830
831 .. method:: getDataSources
832
833 This method shall return a list of data sources, i.e. objects
834 implementing :class:`DataSourceInterface` for the given container.
835 It is intended for use in
836 :mod:`eoxserver.resources.coverages.synchronize`.
837 """
838
839 REGISTRY_CONF = {
840 "name": "Container Interface",
841 "intf_id": "resources.coverages.interfaces.Container"
842 }
843
844 contains = Method(
845 ObjectArg("wrapper"),
846 returns=BoolArg("@return")
847 )
848
849 addCoverage = Method(
850 ObjectArg("wrapper")
851 )
852
853 removeCoverage = Method(
854 ObjectArg("wrapper")
855 )
856
857 getDataSources = Method(
858 returns=ListArg("@return")
859 )
860
862 """
863 This class is intended for implementations of Rectified Stitched
864 Mosaic objects according to WCS 2.0 EO-AP (EO-WCS). It inherits from
865 :class:`~.EOCoverageInterface`, :class:`~.RectifiedGridInterface`
866 and :class:`~.TileIndexInterface`.
867
868 :Interface ID: resources.coverages.interfaces.RectifiedStitchedMosaic
869
870 .. method:: getDataDirs:
871
872 This method shall return a list of directories which hold the
873 stitched mosaic data.
874
875 .. method:: getImagePattern
876
877 This method shall return the filename pattern for image files
878 to be included in the stitched mosaic.
879 """
880 REGISTRY_CONF = {
881 "name": "Rectified Stitched Mosaic Interface",
882 "intf_id": "resources.coverages.interfaces.RectifiedStitchedMosaic"
883 }
884
886 """
887 This interface is intended for implementations of Dataset Series
888 according to the WCS 2.0 EO-AP (EO-WCS). It inherits from
889 :class:`~.ResourceInterface` and :class:`~.EOWCSObjectInterface`.
890
891 :Interface ID: resources.coverages.interfaces.DatasetSeries
892
893 .. method:: getType
894
895 Shall return ``"eo.dataset_series"``.
896
897 .. method:: getEOCoverages(filter_exprs=None)
898
899 This method shall return a list of EOCoverage wrappers for the
900 datasets and stitched mosaics contained in the dataset series
901 wrapped by the implementation. The optional ``filter_exprs``
902 argument is expected to be a list of filter expressions to be
903 applied to the datasets or ``None``. In case no contained dataset
904 matches the filter expressions an empty list shall be returned.
905
906 .. method:: getDatasets(filter_exprs=None)
907
908 This method shall return a list of RectifiedDataset and
909 ReferenceableDataset wrappers contained in the dataset series. The
910 optional ``filter_exprs`` argument is expected to be a list of filter
911 expressions to be applied to the datasets or ``None``. In case no
912 contained dataset matches the filter expressions an empty list shall be
913 returned.
914
915 .. method:: contains(wrapper)
916
917 This method shall return ``True`` if the EO Coverage specified by
918 ``wrapper`` is contained in the Dataset Series, ``False`` otherwise.
919
920 """
921 REGISTRY_CONF = {
922 "name": "Dataset Series Interface",
923 "intf_id": "resources.coverages.interfaces.DatasetSeries"
924 }
925
926 getType = Method(
927 returns=StringArg("@return")
928 )
929
930 getEOCoverages = Method(
931 ListArg("filter_exprs", default=None),
932 returns=ListArg("@return")
933 )
934
935 getDatasets = Method(
936 ListArg("filter_exprs", default=None),
937 returns=ListArg("@return")
938 )
939
940 contains = Method(
941 ObjectArg("wrapper"),
942 returns=BoolArg("@return")
943 )
944
946 """
947 This is an interface for coverage and dataset series managers. These
948 managers shall facilitate registration of data in the database providing an
949 easy-to-use interface for application programmers.
950
951 Managers are bound to a certain resource type, e.g. a DatasetSeries or a
952 RectifiedStitchedMosaic. It suffices to have one manager per resource type
953 as it can be invoked for many objects of this type.
954
955 .. method:: acquireID(obj_id=None, fail=False)
956
957 This method shall acquire a valid and unique object ID and return it.
958 The caller can provide a suggestion ``obj_id``. In this case, the
959 method shall try to acquire this object ID. The optional ``fail``
960 argument determines what the method shall do in case it cannot acquire
961 the given ``obj_id``. If it is set to ``True``, the method shall raise
962 an exception, otherwise it shall degrade gracefully returning a newly
963 generated object ID.
964
965 The implementation should be able to guarantee that the acquired ID
966 cannot be used by other threads of execution unless it is released
967 and left unused. If it cannot assure this, the deviation shall be
968 documented with a warning.
969
970 .. method:: releaseID(obj_id)
971
972 This method shall release an object ID ``obj_id`` that has been
973 acquired with :meth:`acquireID` beforehand. In case the object ID has
974 been left unused, it shall be free to be acquired again.
975
976 .. method:: create(obj_id=None, **kwargs)
977
978 This method shall create and return a coverage or dataset series wrapper
979 from the attributes given in ``kwargs``. The actual range of keyword
980 arguments accepted may depend on the resource type and the
981 implementation.
982
983 If the ``obj_id`` argument is omitted a new object ID shall be generated
984 using the same mechanism as :meth:`acquireID`. If the provided object ID
985 is invalid or already in use, appropriate exceptions shall be raised.
986
987 .. method:: update(obj_id, **kwargs)
988
989 This method shall update the coverage or dataset series with ID
990 ``obj_id`` with new parameters provided as keyword arguments. The actual
991 range of keyword arguments accepted may depend on the resource type and
992 the implementation and should correlate with the arguments accepted by
993 :meth:`create` as far as possible.
994
995 The method shall return the updated coverage or dataset series wrapper.
996
997 It shall raise :exc:`~.NoSuchCoverage` if there is no coverage or
998 dataset series with ID ``obj_id``.
999
1000 .. method:: delete(obj_id)
1001
1002 This method shall delete the coverage or dataset with ID ``obj_id``.
1003
1004 It shall raise :exc:`~.NoSuchCoverage` if there is no coverage or
1005 dataset series with ID ``obj_id``.
1006 """
1007 REGISTRY_CONF = {
1008 "name": "Manager Interface for EO Objects",
1009 "intf_id": "resources.coverages.interfaces.Manager",
1010 "binding_method": "kvp",
1011 "registry_keys": (
1012 "resources.coverages.interfaces.res_type",
1013 )
1014 }
1015
1016 create = Method(
1017 StringArg("obj_id", default=None),
1018 StringArg("request_id", default=None),
1019 KwArgs("kwargs"),
1020 returns = ObjectArg("@return")
1021 )
1022
1023 update = Method(
1024 StringArg("obj_id"),
1025 DictArg("link"),
1026 DictArg("unlink"),
1027 DictArg("set"),
1028 returns = ObjectArg("@return")
1029 )
1030
1031 delete = Method(
1032 StringArg("obj_id")
1033 )
1034
1035 synchronize = Method(
1036 StringArg("obj_id")
1037 )
1038