use of org.geotoolkit.gml.xml.v311.TimePeriodType in project arctic-sea by 52North.
the class GmlEncoderv321 method createTimePeriodType.
private TimePeriodType createTimePeriodType(TimePeriod timePeriod) throws EncodingException {
TimePeriodType timePeriodType = TimePeriodType.Factory.newInstance(getXmlOptions());
createTimePeriodType(timePeriod, timePeriodType);
return timePeriodType;
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project geotoolkit by Geomatys.
the class ObservationXMLBindingTest method UnmarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws java.lang.Exception
*/
@Test
public void UnmarshalingTest() throws Exception {
/*
* Test Unmarshalling observation
*/
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Observation xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod>" + '\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=\"urn:sampling:sampledFeature\"/>" + '\n' + " <sampling:position gml:id=\"point-ID\">" + '\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\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\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";
StringReader sr = new StringReader(xml);
JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
ObservationType result = (ObservationType) jb.getValue();
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("urn:sampling:sampledFeature"), location);
PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
TimePeriodType samplingTime = new TimePeriodType(null, "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 expResult = new ObservationType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
assertEquals(expResult.getFeatureOfInterest(), result.getFeatureOfInterest());
assertEquals(expResult.getDefinition(), result.getDefinition());
assertEquals(expResult.getName(), result.getName());
assertEquals(expResult.getObservationMetadata(), result.getObservationMetadata());
assertEquals(expResult.getObservedProperty(), result.getObservedProperty());
assertEquals(expResult.getProcedure(), result.getProcedure());
assertEquals(expResult.getProcedureParameter(), result.getProcedureParameter());
assertEquals(expResult.getProcedureTime(), result.getProcedureTime());
assertEquals(expResult.getPropertyFeatureOfInterest(), result.getPropertyFeatureOfInterest());
assertEquals(expResult.getPropertyObservedProperty(), result.getPropertyObservedProperty());
assertEquals(expResult.getQuality(), result.getQuality());
assertEquals(expResult.getResult(), result.getResult());
assertEquals(expResult.getSamplingTime(), result.getSamplingTime());
assertEquals(expResult, result);
/*
* Test Unmarshalling measurement
*/
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Measurement xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\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=\"urn:sampling:sampledFeature\"/>" + '\n' + " <sampling:position gml:id=\"point-ID\">" + '\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";
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
MeasurementType result2 = (MeasurementType) jb.getValue();
UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", null, null, "meters");
MeasureType meas = new MeasureType(uom, 7);
MeasurementType expResult2 = new MeasurementType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", meas, samplingTime);
assertEquals(expResult2.getFeatureOfInterest(), result2.getFeatureOfInterest());
assertEquals(expResult2.getDefinition(), result2.getDefinition());
assertEquals(expResult2.getName(), result2.getName());
assertEquals(expResult2.getObservationMetadata(), result2.getObservationMetadata());
assertEquals(expResult2.getObservedProperty(), result2.getObservedProperty());
assertEquals(expResult2.getProcedure(), result2.getProcedure());
assertEquals(expResult2.getProcedureParameter(), result2.getProcedureParameter());
assertEquals(expResult2.getProcedureTime(), result2.getProcedureTime());
assertEquals(expResult2.getPropertyFeatureOfInterest(), result2.getPropertyFeatureOfInterest());
assertEquals(expResult2.getPropertyObservedProperty(), result2.getPropertyObservedProperty());
assertEquals(expResult2.getQuality(), result2.getQuality());
assertEquals(expResult2.getResult(), result2.getResult());
assertEquals(expResult2.getSamplingTime(), result2.getSamplingTime());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:ObservationCollection xmlns:swe=\"http://www.opengis.net/swe/1.0.1\" 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\">" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Envelope srsName=\"urn:ogc:crs:espg:4326\">" + '\n' + " <gml:lowerCorner>-180.0 -90.0</gml:lowerCorner>" + '\n' + " <gml:upperCorner>180.0 90.0</gml:upperCorner>" + '\n' + " </gml:Envelope>" + '\n' + " </gml:boundedBy>" + '\n' + " <om:member>" + '\n' + " <om:Measurement>" + '\n' + " <gml:name>urn:ogc:object:observationTemplate:SunSpot:0014.4F01.0000.2626-12</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod>" + '\n' + " <gml:beginPosition>2009-08-03 11:18:06</gml:beginPosition>" + '\n' + " <gml:endPosition indeterminatePosition=\"now\"></gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:ogc:object:sensor:SunSpot:0014.4F01.0000.2626\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"temperature\">" + '\n' + " <gml:name>urn:phenomenon:temperature</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"sampling-point-001\">" + '\n' + " <gml:name>sampling-point-001</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature>sampling-point-001</sampling:sampledFeature>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsDimension=\"0\">0.0 0.0</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"om:Measure\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <om:name>mesure-027</om:name>" + '\n' + " <om:value>0.0</om:value>" + '\n' + " </om:result>" + '\n' + " </om:Measurement>" + '\n' + " </om:member>" + '\n' + "</om:ObservationCollection>" + '\n';
sr = new StringReader(xml);
ObservationCollectionType result3 = (ObservationCollectionType) unmarshaller.unmarshal(sr);
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
EnvelopeType env = new EnvelopeType("bound-1", lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
StringWriter sw = new StringWriter();
marshaller.marshal(FACTORY.createEnvelope(env), sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<gml:Envelope xmlns:gml=\"" + GML + '"' + " srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\">" + '\n' + " <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + " <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
TimePeriodType tp = new TimePeriodType(d1);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
TimePositionType tpos = new TimePositionType("2002-08-15");
tp = new TimePeriodType(tpos);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
// System.out.println(sw.toString());
LineStringSegmentType ls = new LineStringSegmentType();
DirectPositionListType posList = new DirectPositionListType();
posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
ls.setPosList(posList);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"" + GML + "\">\n" + " <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
ls = new LineStringSegmentType();
DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
ls.getPos().add(pos1);
ls.getPos().add(pos2);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"" + GML + "\">\n" + " <gml:pos>1.1 1.2</gml:pos>" + '\n' + " <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project geotoolkit by Geomatys.
the class TimePeriodTypeTest method getTime2Test.
@Test
public void getTime2Test() throws Exception {
TimePositionType tn = null;
TimePositionType tb = new TimePositionType("2008-11-01T02:00:00");
TimePositionType te = new TimePositionType("2008-11-01T02:01:00");
TimePeriodType tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
assertEquals(60000, tp.getTime());
tb = new TimePositionType("2008-11-01T01:00:00");
te = new TimePositionType("2008-11-01T02:00:00");
tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
assertEquals(3600000, tp.getTime());
tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(tn));
assertEquals(-1, tp.getTime());
tb = null;
tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
assertEquals(-1, tp.getTime());
tb = null;
te = null;
tp = new TimePeriodType(new TimeInstantType(tb), new TimeInstantType(te));
assertEquals(-1, tp.getTime());
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project geotoolkit by Geomatys.
the class TimePeriodTypeTest method getTimeTest.
@Test
public void getTimeTest() throws Exception {
final String id = "id-1";
TimePeriodType tp = new TimePeriodType(id, "2008-11-01T02:00:00", "2008-11-01T02:01:00");
assertEquals(60000, tp.getTime());
tp = new TimePeriodType(id, "2008-11-01T01:00:00", "2008-11-01T02:00:00");
assertEquals(3600000, tp.getTime());
tp = new TimePeriodType(id, "2008-11-01T01:00:00", null);
assertEquals(-1, tp.getTime());
tp = new TimePeriodType(id, null, "2008-11-01T02:00:00");
assertEquals(-1, tp.getTime());
String s1 = null;
tp = new TimePeriodType(id, s1, null);
assertEquals(-1, tp.getTime());
}
Aggregations