<?xml version="1.0" encoding="UTF-8"?>
<schema
    targetNamespace="http://xml.fmi.fi/namespace/meteorology/conceptual-model/meteorological-objects/2009/11/09"
    xmlns:metobj="http://xml.fmi.fi/namespace/meteorology/conceptual-model/meteorological-objects/2009/11/09"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sch="http://www.ascc.net/xml/schematron" elementFormDefault="qualified" version="1.0">

    <annotation>
        <appinfo>
            <sch:title>Schematron validation</sch:title>
            <sch:ns prefix="gml" uri="http://www.opengis.net/gml" />
            <sch:ns prefix="xlink" uri="http://www.w3.org/1999/xlink" />
            <sch:pattern name="Check either href or content not both">
                <sch:rule abstract="true" id="hrefOrContent">
                    <sch:report test="@xlink:href and (*|text())"
                        >Property element may not carry both a reference to an object and contain an object.</sch:report>
                    <sch:assert test="@xlink:href | (*|text())"
                        >Property element must either carry a reference to an object or contain an object.</sch:assert>
                </sch:rule>
            </sch:pattern>
        </appinfo>
        <documentation>
            <html:div xmlns="http://www.w3.org/1999/xhtml">
                <p>This document describes the common helper objects and properties used 
                in meteorological Conceptual Model objects schemas.</p>
                
                <p>For detailed info see <a href="http://xml.fmi.fi/namespace/meteorology/conceptual-model/meteorological-objects/2009/11/09">documentation</a></p>
                
                <p>Author: Ilkka Rinne / FMI 2009.</p>
            </html:div>
        </documentation>
    </annotation>

    <import namespace="http://www.opengis.net/gml" schemaLocation="gml311-part.xsd" />

    <import namespace="http://www.w3.org/XML/1998/namespace"
        schemaLocation="http://www.w3.org/2001/03/xml.xsd" />


   
    <!-- ============================================================= -->
    <element name="CubicSplineSurface" type="metobj:CubicSplineSurfaceType"
        substitutionGroup="gml:_Surface" />
    <!-- ============================================================= -->
    <complexType name="CubicSplineSurfaceType">
        <annotation>
            <documentation>
                <html:div xmlns="http://www.w3.org/1999/xhtml">
                    <p />
                </html:div>
            </documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractSurfaceType">
                <sequence>
                    <element name="exterior" type="metobj:CubicSplineRingPropertyType" minOccurs="0" />
                    <element name="interior" type="metobj:CubicSplineRingPropertyType" minOccurs="0"
                        maxOccurs="unbounded" />
                </sequence>
                <attribute name="interpolation" type="gml:SurfaceInterpolationType"
                    fixed="polynomialSpline" />
            </extension>
        </complexContent>
    </complexType>
    <!-- ============================================================================= -->
    <element name="cubicSplineSurfaceProperty" type="metobj:CubicSplineSurfacePropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:cubicSplineSurfaceProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="CubicSplineSurfacePropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:CubicSplineSurface" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />

    </complexType>
    
    <!-- ============================================================= -->
    <element name="LinearRingInterpolationSurface" type="metobj:LinearRingInterpolationSurfaceType"
        substitutionGroup="gml:_Surface" />
    <!-- ============================================================= -->
    <complexType name="LinearRingInterpolationSurfaceType">
        <annotation>
            <documentation>
                <html:div xmlns="http://www.w3.org/1999/xhtml">
                    <p />
                </html:div>
            </documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractSurfaceType">
                <sequence>
                    <element name="exterior" type="gml:LinearRingPropertyType" minOccurs="0" />
                    <element name="interior" type="gml:LinearRingPropertyType" minOccurs="0"
                        maxOccurs="unbounded" />
                </sequence>
                <attribute name="interpolation" type="gml:SurfaceInterpolationType"
                fixed="none" />
                <attribute name="samplingFrequencyValue" type="double" use="required"/>
                <attribute name="samplingFrequencyUOM" type="anyURI" use="required"/>
            </extension>
        </complexContent>
    </complexType>
    <!-- ============================================================================= -->
    <element name="linearRingInterpolationSurfaceProperty" type="metobj:LinearRingInterpolationSurfacePropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:linearRingInterpolationSurfaceProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="LinearRingInterpolationSurfacePropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:LinearRingInterpolationSurface" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />
        
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="cubicSplineRingProperty" type="metobj:CubicSplineRingPropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:cubicSplineRingProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="CubicSplineRingPropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:CubicSplineRing" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />
    </complexType>
    
    <!-- =========================================================== -->
    <element name="CubicSplineRing" type="metobj:CubicSplineRingType" substitutionGroup="gml:_Ring"/>
    <!-- =========================================================== -->
    <complexType name="CubicSplineRingType">
        <annotation>
            <documentation>the first and last coordinates must be coincident.</documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractRingType">
                <sequence>
                    <choice>
                        <annotation>
                            <documentation>GML supports two different ways to specify the control points of a curve segment.
                                1. A sequence of "pos" (DirectPositionType) or "pointProperty" (PointPropertyType) elements. "pos" elements are control points that are only part of this curve segment, "pointProperty" elements contain a point that may be referenced from other geometry elements or reference another point defined outside of this curve segment (reuse of existing points).
                                2. The "posList" element allows for a compact way to specifiy the coordinates of the control points, if all control points are in the same coordinate reference systems and belong to this curve segment only. The number of direct positions in the list must be at least three.</documentation>
                        </annotation>
                        <choice minOccurs="4" maxOccurs="unbounded">
                            <element ref="gml:pos"/>
                            <element ref="gml:pointProperty"/>
                        </choice>
                        <element ref="gml:posList"/>
                    </choice>
                    <element name="vectorAtStart" type="gml:VectorType">
                        <annotation>
                            <documentation>"vectorAtStart" is the unit tangent vector at the start point of the spline.</documentation>
                        </annotation>
                    </element>
                    <element name="vectorAtEnd" type="gml:VectorType">
                        <annotation>
                            <documentation>"vectorAtEnd" is the unit tangent vector at the end point of the spline.</documentation>
                        </annotation>
                    </element>
                </sequence>
                <attribute name="interpolation" type="gml:CurveInterpolationType" fixed="cubicSpline">
                    <annotation>
                        <documentation>The attribute "interpolation" specifies the curve interpolation mechanism used for this segment. This mechanism
                            uses the control points and control parameters to determine the position of this curve segment. For a CubicSpline the interpolation is fixed as "cubicSpline".</documentation>
                    </annotation>
                </attribute>
                <attribute name="degree" type="integer" fixed="3">
                    <annotation>
                        <documentation>The degree for a cubic spline is "3".</documentation>
                    </annotation>
                </attribute>
            </extension>
        </complexContent>
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="linearRingProperty" type="metobj:LinearRingPropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:linearRingProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="LinearRingPropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="gml:LinearRing" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />
    </complexType>
    
    <!-- ============================================================================= -->
    <complexType name="SelfContainedAbstractSurfaceType" abstract="true">
        <complexContent>
            <restriction base="gml:AbstractSurfaceType">
                <attribute name="srsName" type="anyURI" use="required">
                    <annotation>
                        <documentation>In general this reference points to a CRS instance of gml:CoordinateReferenceSystemType 
                            (see coordinateReferenceSystems.xsd). For well known references it is not required that the CRS description exists at the 
                            location the URI points to.</documentation>
                    </annotation>
                </attribute>
                <attribute name="srsDimension" type="positiveInteger" use="required">
                    <annotation>
                        <documentation>The "srsDimension" is the length of coordinate sequence (the number of entries in the list). This dimension is 
                            specified by the coordinate reference system.</documentation>
                    </annotation>
                </attribute>
                <attributeGroup ref="gml:SRSInformationGroup"/>
            </restriction>
        </complexContent>
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="CubicSplineCurve" type="metobj:CubicSplineCurveType"
        substitutionGroup="gml:_Curve" />
    <complexType name="CubicSplineCurveType">
        <annotation>
            <documentation>
                A Simplified version of gml:CurveType with only CubicSpline segments.
            </documentation>
        </annotation>
        <complexContent>
            <extension base="metobj:SelfContainedAbstractCurveType">
                <sequence>
                    <element ref="metobj:cubicSplineSegments">
                        <annotation>
                            <documentation>This element encapsulates the segments of the curve.</documentation>
                        </annotation>
                    </element>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="cubicSplineCurveProperty" type="metobj:CubicSplineCurvePropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:cubicSplineCurveProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="CubicSplineCurvePropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.
            </documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:CubicSplineCurve" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />
    </complexType>

    <!-- ============================================================================= -->
    <element name="cubicSplineSegments" type="metobj:CubicSplineSegmentArrayPropertyType" />
    <!-- ============================================================================= -->
    <complexType name="CubicSplineSegmentArrayPropertyType">
        <sequence>
            <element ref="metobj:SimpleCubicSpline" minOccurs="0" maxOccurs="unbounded" />
        </sequence>
    </complexType>

    <!-- ========================== -->
    <element name="SimpleCubicSpline" type="metobj:SimpleCubicSplineType" substitutionGroup="gml:_CurveSegment"/>
    <!-- =========================================================== -->
    <complexType name="SimpleCubicSplineType">
        <annotation>
            <documentation>Cubic splines are similar to line strings in that they are a sequence of segments each with its own defining function. A cubic spline uses the control points and a set of derivative parameters to define a piecewise 3rd degree polynomial interpolation. Unlike line-strings, the parameterization by arc length is not necessarily still a polynomial. 
                The function describing the curve must be C2, that is, have a continuous 1st and 2nd derivative at all points, and pass through the controlPoints in the order given. Between the control points, the curve segment is defined by a cubic polynomial. At each control point, the polynomial changes in such a manner that the 1st and 2nd derivative vectors are the same from either side. The control parameters record must contain vectorAtStart, and vectorAtEnd which are the unit tangent vectors at controlPoint[1] and controlPoint[n] where n = controlPoint.count. 
                Note: only the direction of the vectors is relevant, not their length.</documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractCurveSegmentType">
                <sequence>
                    <annotation>
                        <documentation>Unlike in gml:CubicSplineType, positions can only be specified in one way: inlined using gml:posList. The number of direct positions in the list must be at least three.</documentation>
                    </annotation>
                    <element ref="gml:posList"/>
                    <element name="vectorAtStart" type="gml:VectorType">
                        <annotation>
                            <documentation>"vectorAtStart" is the unit tangent vector at the start point of the spline.</documentation>
                        </annotation>
                    </element>
                    <element name="vectorAtEnd" type="gml:VectorType">
                        <annotation>
                            <documentation>"vectorAtEnd" is the unit tangent vector at the end point of the spline.</documentation>
                        </annotation>
                    </element>
                </sequence>
                <attribute name="interpolation" type="gml:CurveInterpolationType" fixed="cubicSpline">
                    <annotation>
                        <documentation>The attribute "interpolation" specifies the curve interpolation mechanism used for this segment. This mechanism
                            uses the control points and control parameters to determine the position of this curve segment. For a CubicSpline the interpolation is fixed as "cubicSpline".</documentation>
                    </annotation>
                </attribute>
                <attribute name="degree" type="integer" fixed="3">
                    <annotation>
                        <documentation>The degree for a cubic spline is "3".</documentation>
                    </annotation>
                </attribute>
            </extension>
        </complexContent>
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="LineStringCurve" type="metobj:LineStringCurveType" substitutionGroup="gml:_Curve" />
    <complexType name="LineStringCurveType">
        <annotation>
            <documentation>
                A Simplified version of gml:CurveType with only LineStringSegments.
            </documentation>
        </annotation>
        <complexContent>
            <extension base="metobj:SelfContainedAbstractCurveType">
                <sequence>
                    <element ref="metobj:lineStringSegments">
                        <annotation>
                            <documentation>This element encapsulates the segments of the curve.</documentation>
                        </annotation>
                    </element>
                </sequence>
            </extension>
        </complexContent>
    </complexType>

    <!-- ============================================================================= -->
    <element name="lineStringCurveProperty" type="metobj:LineStringCurvePropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:lineStringCurveProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="LineStringCurvePropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.
            </documentation>
        </annotation>

        <sequence minOccurs="0">
            <element ref="metobj:LineStringCurve" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />

    </complexType>
    
    <!-- ============================================================================= -->
    <complexType name="SelfContainedAbstractCurveType" abstract="true">
        <complexContent>
            <restriction base="gml:AbstractCurveType">
                <attribute name="srsName" type="anyURI" use="required">
                    <annotation>
                        <documentation>In general this reference points to a CRS instance of gml:CoordinateReferenceSystemType 
                            (see coordinateReferenceSystems.xsd). For well known references it is not required that the CRS description exists at the 
                            location the URI points to.</documentation>
                    </annotation>
                </attribute>
                <attribute name="srsDimension" type="positiveInteger" use="required">
                    <annotation>
                        <documentation>The "srsDimension" is the length of coordinate sequence (the number of entries in the list). This dimension is 
                            specified by the coordinate reference system.</documentation>
                    </annotation>
                </attribute>
                <attributeGroup ref="gml:SRSInformationGroup"/>
            </restriction>
        </complexContent>
    </complexType>
    
    <!-- ============================================================================= -->
    <element name="lineStringSegments" type="metobj:LineStringSegmentArrayPropertyType" />
    <!-- ============================================================================= -->
    <complexType name="LineStringSegmentArrayPropertyType">
        <sequence>
            <element ref="metobj:SimpleLineStringSegment" minOccurs="0" maxOccurs="unbounded" />
        </sequence>
    </complexType>

    <!-- ================================================================================================================ -->
    <element name="SimpleLineStringSegment" type="metobj:SimpleLineStringSegmentType" substitutionGroup="gml:_CurveSegment"/>
    <!-- ================================================================================================================ -->
    <complexType name="SimpleLineStringSegmentType">
        <annotation>
            <documentation>A SimpleLineStringSegment is a curve segment that is defined by two or more coordinate tuples, with linear interpolation between them.
                Note: SimpleLineStringSegment implements GM_LineString of ISO 19107, but allows only one way of specifying the direct positions.</documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractCurveSegmentType">
                <sequence>
                  <annotation>
                     <documentation>Unlike in gml:LineStringSegmentType, positions can only be specified in one way: inlined using gml:posList. The number of direct positions in the list must be at least two.</documentation>
                  </annotation>
                  <element ref="gml:posList"/>
                </sequence>
                <attribute name="interpolation" type="gml:CurveInterpolationType" fixed="linear">
                    <annotation>
                        <documentation>The attribute "interpolation" specifies the curve interpolation mechanism used for this segment. This mechanism
                            uses the control points and control parameters to determine the position of this curve segment. For a SimpleLineStringSegment the interpolation is fixed as "linear".</documentation>
                    </annotation>
                </attribute>
            </extension>
        </complexContent>
    </complexType>

    <!-- =================================================== -->
    <element name="LineStringInterpolationCurve" type="metobj:LineStringInterpolationCurveType"
        substitutionGroup="metobj:LineStringCurve" />
    <!-- =================================================== -->
    <complexType name="LineStringInterpolationCurveType">
        <annotation>
            <documentation />
        </annotation>
        <complexContent>
            <extension base="metobj:LineStringCurveType">
                <attribute name="samplingFrequencyValue" type="double" use="required"/>
                <attribute name="samplingFrequencyUOM" type="anyURI" use="required"/>
            </extension>
        </complexContent>
    </complexType>
    
    <!-- ========================================================================= -->
    <element name="lineStringInterpolationCurveProperty" type="metobj:LineStringInterpolationCurvePropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:lineStringInterpolationProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ========================================================================= -->
    <complexType name="LineStringInterpolationCurvePropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:LineStringInterpolationCurve" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />
    </complexType>

    <!-- ============================================================================= -->
    <element name="ConnectionPoint" type="metobj:ConnectionPointType" />
    <!-- ============================================================================= -->
    <complexType name="ConnectionPointType">
        <annotation>
            <documentation>
                <html:div xmlns="http://www.w3.org/1999/xhtml">
                    <p />
                </html:div>
            </documentation>
        </annotation>
        <complexContent>
            <extension base="gml:AbstractGeometricPrimitiveType">
                <sequence>
                    <element ref="gml:pos" />
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <!-- ============================================================================= -->
    <element name="connectionPointProperty" type="metobj:ConnectionPointPropertyType">
        <annotation>
            <appinfo>
                <sch:pattern name="refAndContent co-occurence prohibited">
                    <sch:rule context="metobj:connectionPointProperty">
                        <sch:extends rule="hrefOrContent" />
                    </sch:rule>
                </sch:pattern>
            </appinfo>
        </annotation>
    </element>
    <!-- ============================================================================= -->
    <complexType name="ConnectionPointPropertyType">
        <annotation>
            <documentation>To be used when using this object type as property of n GML object
                type according to the GML object-property-association model (it is not allowed for
                GML Objects to contain other GML Objects as direct children). Enables referencing to
                an existing object using xlink:href attribute.</documentation>
        </annotation>
        <sequence minOccurs="0">
            <element ref="metobj:ConnectionPoint" />
        </sequence>
        <attributeGroup ref="gml:AssociationAttributeGroup" />

    </complexType>

    <!-- ========================================================================= -->
    <element name="connectionPointMembers" type="metobj:ConnectionPointArrayAssociationType" />
    <!-- ========================================================================= -->
    <complexType name="ConnectionPointArrayAssociationType">
        <annotation>
            <documentation>
                <html:div xmlns="http://www.w3.org/1999/xhtml">
                    <p />
                </html:div>
            </documentation>
        </annotation>
        <sequence>
            <element ref="metobj:ConnectionPoint" minOccurs="0" maxOccurs="unbounded" />
        </sequence>
    </complexType>

    <!-- ========================================================================= -->
    <element name="connectionPointReference" type="metobj:ConnectionPointReferenceType" />
    <!-- ========================================================================= -->
    <complexType name="ConnectionPointReferenceType">
        <attributeGroup ref="gml:AssociationAttributeGroup" />
    </complexType>

    
</schema>