use of org.geotoolkit.gml.xml.v321.DirectPositionType in project geotoolkit by Geomatys.
the class VectorType method getGeometry.
@Override
public AbstractGeometry getGeometry(final URI crs) {
final CoordinateType lat = getLatitude();
final CoordinateType lon = getLongitude();
if (isComplete(lat) && isComplete(lon)) {
final DirectPositionType dp = new DirectPositionType(lat.getQuantity().getValue(), lon.getQuantity().getValue());
final PointType pt = new PointType(dp);
if (crs != null) {
pt.setSrsName(crs.toString());
}
return pt;
}
return null;
}
use of org.geotoolkit.gml.xml.v321.DirectPositionType in project geotoolkit by Geomatys.
the class OwcXmlIO method write.
private static FeedType write(final MapLayers context) throws FactoryException {
final FeedType feed = ATOM_FACTORY.createFeedType();
final LinkType link = ATOM_FACTORY.createLinkType();
link.setRel("profile");
link.setHref("http://www.opengis.net/spec/owc-atom/1.0/req/core");
link.setTitle(context.getIdentifier() == null ? "" : context.getIdentifier());
feed.getAuthorOrCategoryOrContributor().add(ATOM_FACTORY.createFeedTypeLink(link));
final TextType title = ATOM_FACTORY.createTextType();
title.getContent().add(context.getIdentifier() == null ? "" : context.getIdentifier());
feed.getAuthorOrCategoryOrContributor().add(ATOM_FACTORY.createFeedTypeTitle(title));
final Envelope aoi = context.getAreaOfInterest();
if (aoi != null) {
final String ogc = IdentifiedObjects.lookupURN(aoi.getCoordinateReferenceSystem(), null);
final WhereType where = GEORSS_FACTORY.createWhereType();
final DirectPositionType lowerCorner = new DirectPositionType(aoi.getLowerCorner());
final DirectPositionType upperCorner = new DirectPositionType(aoi.getUpperCorner());
final EnvelopeType envelopeType = new EnvelopeType(null, lowerCorner, upperCorner, ogc);
envelopeType.setSrsDimension(2);
where.setEnvelope(envelopeType);
feed.getAuthorOrCategoryOrContributor().add(GEORSS_FACTORY.createWhere(where));
}
for (final MapItem mapItem : context.getComponents()) {
toEntry(null, mapItem, feed.getAuthorOrCategoryOrContributor());
}
return feed;
}
use of org.geotoolkit.gml.xml.v321.DirectPositionType in project geotoolkit by Geomatys.
the class OWCTest method owcMarshallTest.
@Test
public void owcMarshallTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
final FeedType feed = new FeedType();
final List<Object> entriesToSet = feed.getAuthorOrCategoryOrContributor();
final IdType idFeed = new IdType();
idFeed.setValue("Test id");
entriesToSet.add(OBJ_ATOM_FACT.createEntryTypeId(idFeed));
final TextType title = new TextType();
title.getContent().add("Test");
entriesToSet.add(OBJ_ATOM_FACT.createEntryTypeTitle(title));
final String layerName = "testlayer";
final String url = "http://myhost.com/constellation/WS/wms/test";
final DirectPositionType lowerCorner = new DirectPositionType(-180.0, -90.0);
final DirectPositionType upperCorner = new DirectPositionType(180.0, 90.0);
final EnvelopeType envelope = new EnvelopeType(null, lowerCorner, upperCorner, "CRS:84");
final WhereType where = new WhereType();
where.setEnvelope(envelope);
entriesToSet.add(OBJ_GEORSS_FACT.createWhere(where));
final EntryType newEntry = new EntryType();
final List<Object> entryThings = newEntry.getAuthorOrCategoryOrContent();
final IdType idNewEntry = new IdType();
idNewEntry.setValue("Web Map Service Layer");
entryThings.add(OBJ_ATOM_FACT.createEntryTypeId(idNewEntry));
final TextType titleNewEntry = new TextType();
titleNewEntry.getContent().add(layerName);
entryThings.add(OBJ_ATOM_FACT.createEntryTypeTitle(title));
final org.w3._2005.atom.ContentType content = new org.w3._2005.atom.ContentType();
content.setType("html");
entryThings.add(OBJ_ATOM_FACT.createEntryTypeContent(content));
final CategoryType category = new CategoryType();
category.setScheme("http://www.opengis.net/spec/owc/active");
category.setTerm("true");
entryThings.add(OBJ_ATOM_FACT.createEntryTypeCategory(category));
final OfferingType offering = new OfferingType();
offering.setCode("http://www.opengis.net/spec/owc-atom/1.0/req/wms");
final OperationType opCaps = new OperationType();
opCaps.setCode("GetCapabilities");
opCaps.setMethod(MethodCodeType.GET);
final StringBuilder capsUrl = new StringBuilder();
capsUrl.append(url).append("?REQUEST=GetCapabilities&SERVICE=WMS");
opCaps.setHref(capsUrl.toString());
offering.getOperationOrContentOrStyleSet().add(OBJ_OWC_FACT.createOfferingTypeOperation(opCaps));
final OperationType opGetMap = new OperationType();
opGetMap.setCode("GetMap");
opGetMap.setMethod(MethodCodeType.GET);
final String defStyle = "default";
final StringBuilder getMapUrl = new StringBuilder();
getMapUrl.append(url).append("?REQUEST=GetMap&SERVICE=WMS&FORMAT=image/png&TRANSPARENT=true&WIDTH=1024&HEIGHT=768&CRS=CRS:84&BBOX=").append("-5,40,15,60").append("&LAYERS=").append(layerName).append("&STYLES=").append(defStyle);
opGetMap.setHref(getMapUrl.toString());
offering.getOperationOrContentOrStyleSet().add(OBJ_OWC_FACT.createOfferingTypeOperation(opGetMap));
entryThings.add(OBJ_OWC_FACT.createOffering(offering));
entriesToSet.add(OBJ_ATOM_FACT.createEntry(newEntry));
final Marshaller marsh = OwcMarshallerPool.getPool().acquireMarshaller();
final StringWriter sw = new StringWriter();
marsh.marshal(feed, sw);
OwcMarshallerPool.getPool().recycle(marsh);
assertXmlEquals(EXP_RESULT, sw.toString(), "xmlns:*");
}
use of org.geotoolkit.gml.xml.v321.DirectPositionType in project geotoolkit by Geomatys.
the class PropertyTypeTest method setValueGeometryNewTest.
/**
* Test simple Record Marshalling.
*
* @throws javax.xml.bind.JAXBException
*/
@Test
public void setValueGeometryNewTest() throws JAXBException {
TransactionType transac = new TransactionType();
PointType pt = new PointType(null, new DirectPositionType(2.1, 12.6));
pt.setSrsName("urn:ogc:def:crs:epsg:7.4:4326");
PropertyType prop = new PropertyType(new QName("something"), new ValueType(pt));
transac.getInsertOrUpdateOrDelete().add(new UpdateElementType(null, Arrays.asList(prop), null, null, null));
StringWriter sw = new StringWriter();
// marshaller.marshal(transac, System.out);
marshaller.marshal(transac, sw);
Object result = unmarshaller.unmarshal(new StringReader(sw.toString()));
assertEquals(transac, result);
transac = new TransactionType();
prop = new PropertyType(new QName("something"), new ValueType("jane"));
transac.getInsertOrUpdateOrDelete().add(new UpdateElementType(null, Arrays.asList(prop), null, null, null));
sw = new StringWriter();
// marshaller.marshal(transac, System.out);
marshaller.marshal(transac, sw);
result = unmarshaller.unmarshal(new StringReader(sw.toString()));
assertEquals(transac, result);
}
use of org.geotoolkit.gml.xml.v321.DirectPositionType 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();
}
Aggregations