Search in sources :

Example 1 with FeaturePropertyType

use of org.geotoolkit.gml.xml.v311.FeaturePropertyType in project arctic-sea by 52North.

the class GmlEncoderv321 method createFeature.

private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
    FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
    if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
        return featurePropertyType;
    } else {
        AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
        if (samplingFeature.isSetGmlID() && samplingFeature.isEncoded()) {
            featurePropertyType.setHref("#" + samplingFeature.getGmlId());
            return featurePropertyType;
        } else {
            if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
                featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (!samplingFeature.isSetGeometry()) {
                featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (samplingFeature.isSetUrl()) {
                featurePropertyType.setHref(samplingFeature.getUrl());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            } else {
                String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> samplingFeature.isSetDefaultElementEncoding() ? samplingFeature.getDefaultElementEncoding() : OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
                XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
                if (encodedXmlObject != null) {
                    return encodedXmlObject;
                } else {
                    if (feature.isSetXml()) {
                        try {
                            // XmlDescription? <-- XmlCursor
                            return XmlObject.Factory.parse(feature.getXml());
                        } catch (XmlException xmle) {
                            throw new EncodingException("Error while encoding featurePropertyType!", xmle);
                        }
                    } else {
                        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                        if (samplingFeature.isSetName()) {
                            featurePropertyType.setTitle(feature.getFirstName().getValue());
                        }
                        return featurePropertyType;
                    }
                }
            }
        }
    }
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 2 with FeaturePropertyType

use of org.geotoolkit.gml.xml.v311.FeaturePropertyType in project arctic-sea by 52North.

the class GmlEncoderv321 method createFeatureCollection.

private XmlObject createFeatureCollection(FeatureCollection element, EncodingContext ctx) throws EncodingException {
    FeatureCollectionDocument featureCollectionDoc = FeatureCollectionDocument.Factory.newInstance(getXmlOptions());
    FeatureCollectionType featureCollection = featureCollectionDoc.addNewFeatureCollection();
    featureCollection.setId(element.getGmlId());
    EncodingContext context = ctx.with(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.DOCUMENT);
    if (element.isSetMembers()) {
        for (AbstractFeature abstractFeature : element.getMembers().values()) {
            featureCollection.addNewFeatureMember().set(createFeaturePropertyType(abstractFeature, context));
        }
    }
    if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
        return featureCollectionDoc;
    }
    FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
    featurePropertyType.addNewAbstractFeature().set(featureCollection);
    return XmlHelper.substituteElement(featurePropertyType.getAbstractFeature(), featurePropertyType);
// return featureCollection;
}
Also used : FeatureCollectionType(net.opengis.gml.x32.FeatureCollectionType) FeatureCollectionDocument(net.opengis.gml.x32.FeatureCollectionDocument) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 3 with FeaturePropertyType

use of org.geotoolkit.gml.xml.v311.FeaturePropertyType in project arctic-sea by 52North.

the class OmEncoderv20 method addFeature.

private void addFeature(OMObservationType xbObservationTemplate, Nillable<AbstractFeature> featureOfInterest) throws EncodingException {
    FeaturePropertyType xbFeatureOfInterest = xbObservationTemplate.addNewFeatureOfInterest();
    if (featureOfInterest.isNil() || featureOfInterest.isAbsent()) {
        xbFeatureOfInterest.setNilReason(NIL_REASON_TEMPLATE);
    } else {
        XmlObject xbEncodedFeature = encodeObjectToXmlPropertyType(featureOfInterest.get().getDefaultElementEncoding(), featureOfInterest.get(), EncodingContext.empty());
        xbFeatureOfInterest.set(xbEncodedFeature);
    }
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 4 with FeaturePropertyType

use of org.geotoolkit.gml.xml.v311.FeaturePropertyType in project geotoolkit by Geomatys.

the class ObservationXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void marshallingTest() throws Exception {
    DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
    PointType location = new PointType("point-ID", pos);
    SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
    PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
    TimePeriodType samplingTime = new TimePeriodType("t1", "2007-01-01", "2008-09-09");
    TextBlockType encoding = new TextBlockType("encoding-001", ",", "@@", ".");
    List<AnyScalarPropertyType> fields = new ArrayList<>();
    AnyScalarPropertyType field = new AnyScalarPropertyType("text-field-001", new Text("urn:something", "some value"));
    fields.add(field);
    SimpleDataRecordType record = new SimpleDataRecordType(fields);
    DataArrayType array = new DataArrayType("array-001", 1, "array-001", record, encoding, "somevalue", null);
    DataArrayPropertyType arrayProp = new DataArrayPropertyType(array);
    ObservationType obs = new ObservationType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
    StringWriter sw = new StringWriter();
    marshaller.marshal(obs, sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    String expResult = "<om:Observation xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + "    <gml:name>urn:Observation-007</gml:name>" + '\n' + "    <om:samplingTime>" + '\n' + "        <gml:TimePeriod gml:id=\"t1\">" + '\n' + "            <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + "            <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + "        </gml:TimePeriod>" + '\n' + "    </om:samplingTime>" + '\n' + "    <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + "    <om:observedProperty>" + '\n' + "        <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + "            <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + "        </swe:Phenomenon>" + '\n' + "    </om:observedProperty>" + '\n' + "    <om:featureOfInterest>" + '\n' + "        <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + "            <gml:description>a sampling Test</gml:description>" + '\n' + "            <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "            <gml:boundedBy>" + '\n' + "                <gml:Null>not_bounded</gml:Null>" + '\n' + "            </gml:boundedBy>" + '\n' + "            <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "            <sampling:position>" + '\n' + "                <gml:Point gml:id=\"point-ID\">" + '\n' + "                    <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "                </gml:Point>" + '\n' + "            </sampling:position>" + '\n' + "        </sampling:SamplingPoint>" + '\n' + "    </om:featureOfInterest>" + '\n' + "    <om:result xsi:type=\"swe:DataArrayPropertyType\" >" + '\n' + "        <swe:DataArray gml:id=\"array-001\">" + '\n' + "            <swe:elementCount>" + '\n' + "                <swe:Count>" + '\n' + "                    <swe:value>1</swe:value>" + '\n' + "                </swe:Count>" + '\n' + "            </swe:elementCount>" + '\n' + "            <swe:elementType name=\"array-001\">" + '\n' + "                <swe:SimpleDataRecord>" + '\n' + "                    <swe:field name=\"text-field-001\">" + '\n' + "                        <swe:Text definition=\"urn:something\">" + '\n' + "                            <swe:value>some value</swe:value>" + '\n' + "                        </swe:Text>" + '\n' + "                    </swe:field>" + '\n' + "                </swe:SimpleDataRecord>" + '\n' + "            </swe:elementType>" + '\n' + "            <swe:encoding>" + '\n' + "                <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-001\"/>" + '\n' + "            </swe:encoding>" + '\n' + "            <swe:values>somevalue</swe:values>" + '\n' + "        </swe:DataArray>" + '\n' + "    </om:result>" + '\n' + "</om:Observation>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", "meters", "distance", "meters");
    MeasureType meas = new MeasureType(uom, 7);
    MeasurementType measmt = new MeasurementType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", meas, samplingTime);
    sw = new StringWriter();
    marshaller.marshal(measmt, sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<om:Measurement xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + "    <gml:name>urn:Observation-007</gml:name>" + '\n' + "    <om:samplingTime>" + '\n' + "        <gml:TimePeriod gml:id=\"t1\">" + '\n' + "            <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + "            <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + "        </gml:TimePeriod>" + '\n' + "    </om:samplingTime>" + '\n' + "    <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + "    <om:observedProperty>" + '\n' + "        <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + "            <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + "        </swe:Phenomenon>" + '\n' + "    </om:observedProperty>" + '\n' + "    <om:featureOfInterest>" + '\n' + "        <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + "            <gml:description>a sampling Test</gml:description>" + '\n' + "            <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "            <gml:boundedBy>" + '\n' + "                <gml:Null>not_bounded</gml:Null>" + '\n' + "            </gml:boundedBy>" + '\n' + "            <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "            <sampling:position>" + '\n' + "                <gml:Point gml:id=\"point-ID\">" + '\n' + "                    <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "                </gml:Point>" + '\n' + "            </sampling:position>" + '\n' + "        </sampling:SamplingPoint>" + '\n' + "    </om:featureOfInterest>" + '\n' + "    <om:result xsi:type=\"om:MeasureType\" uom=\"meters\">7.0</om:result>" + '\n' + "</om:Measurement>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    ObservationCollectionType collection = new ObservationCollectionType();
    collection.add(measmt);
    sw = new StringWriter();
    marshaller.marshal(collection, sw);
    result = sw.toString();
    // System.out.println(result);
    collection = new ObservationCollectionType();
    collection.add(obs.getTemporaryTemplate("temporaryName", samplingTime));
    sw = new StringWriter();
    marshaller.marshal(collection, sw);
    result = sw.toString();
}
Also used : ObservationType(org.geotoolkit.observation.xml.v100.ObservationType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) AnyScalarPropertyType(org.geotoolkit.swe.xml.v101.AnyScalarPropertyType) ArrayList(java.util.ArrayList) MeasureType(org.geotoolkit.observation.xml.v100.MeasureType) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) Text(org.geotoolkit.swe.xml.v101.Text) DataArrayPropertyType(org.geotoolkit.swe.xml.v101.DataArrayPropertyType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) StringWriter(java.io.StringWriter) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) MeasurementType(org.geotoolkit.observation.xml.v100.MeasurementType) TextBlockType(org.geotoolkit.swe.xml.v101.TextBlockType) UnitOfMeasureEntry(org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry) PointType(org.geotoolkit.gml.xml.v311.PointType) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) FeaturePropertyType(org.geotoolkit.gml.xml.v311.FeaturePropertyType) SimpleDataRecordType(org.geotoolkit.swe.xml.v101.SimpleDataRecordType) DataArrayType(org.geotoolkit.swe.xml.v101.DataArrayType)

Example 5 with FeaturePropertyType

use of org.geotoolkit.gml.xml.v311.FeaturePropertyType in project geotoolkit by Geomatys.

the class SamplingXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void marshallingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    final DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
    final PointType location = new PointType("point-ID", pos);
    final SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
    StringWriter sw = new StringWriter();
    marshaller.marshal(sp, sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    String expResult = "<sampling:SamplingPoint gml:id=\"samplingID-007\"" + " xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "    <gml:description>a sampling Test</gml:description>" + '\n' + "    <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "    <gml:boundedBy>" + '\n' + "        <gml:Null>not_bounded</gml:Null>" + '\n' + "    </gml:boundedBy>" + '\n' + "    <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "    <sampling:position>" + '\n' + "        <gml:Point gml:id=\"point-ID\">" + '\n' + "            <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "        </gml:Point>" + '\n' + "    </sampling:position>" + '\n' + "</sampling:SamplingPoint>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
    final ObjectFactory facto = new ObjectFactory();
    FeatureCollectionType collection = new FeatureCollectionType();
    List<FeaturePropertyType> featProps = new ArrayList<FeaturePropertyType>();
    featProps.add(new FeaturePropertyType(facto.createSamplingPoint(sp)));
    collection.getFeatureMember().addAll(featProps);
    sw = new StringWriter();
    marshaller.marshal(collection, sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<gml:FeatureCollection" + " xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "    <gml:featureMember>" + '\n' + "        <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + "            <gml:description>a sampling Test</gml:description>" + '\n' + "            <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "            <gml:boundedBy>" + '\n' + "                <gml:Null>not_bounded</gml:Null>" + '\n' + "            </gml:boundedBy>" + '\n' + "            <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "            <sampling:position>" + '\n' + "                <gml:Point gml:id=\"point-ID\">" + '\n' + "                    <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "                </gml:Point>" + '\n' + "            </sampling:position>" + '\n' + "        </sampling:SamplingPoint>" + '\n' + "    </gml:featureMember>" + '\n' + "</gml:FeatureCollection>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : FeatureCollectionType(org.geotoolkit.gml.xml.v311.FeatureCollectionType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) StringWriter(java.io.StringWriter) ObjectFactory(org.geotoolkit.sampling.xml.v100.ObjectFactory) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) ArrayList(java.util.ArrayList) PointType(org.geotoolkit.gml.xml.v311.PointType) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) FeaturePropertyType(org.geotoolkit.gml.xml.v311.FeaturePropertyType)

Aggregations

FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)6 ArrayList (java.util.ArrayList)5 XmlObject (org.apache.xmlbeans.XmlObject)5 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)4 FeaturePropertyType (org.geotoolkit.gml.xml.v311.FeaturePropertyType)4 PointType (org.geotoolkit.gml.xml.v311.PointType)4 SamplingPointType (org.geotoolkit.sampling.xml.v100.SamplingPointType)4 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 JAXBElement (javax.xml.bind.JAXBElement)2 FeatureCollectionType (org.geotoolkit.gml.xml.v311.FeatureCollectionType)2 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)2 UnitOfMeasureEntry (org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry)2 MeasureType (org.geotoolkit.observation.xml.v100.MeasureType)2 MeasurementType (org.geotoolkit.observation.xml.v100.MeasurementType)2 ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)2 ObservationType (org.geotoolkit.observation.xml.v100.ObservationType)2 ObjectFactory (org.geotoolkit.sampling.xml.v100.ObjectFactory)2 AnyScalarPropertyType (org.geotoolkit.swe.xml.v101.AnyScalarPropertyType)2 DataArrayPropertyType (org.geotoolkit.swe.xml.v101.DataArrayPropertyType)2