use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class TestXmlInputTransformer method testNormalTransform.
/*
Tests a base XmlInputTransformer, CONTENT_TYPE is null because it is not in the base xmlToMetacard mapping
*/
@Test
public void testNormalTransform() throws FileNotFoundException, CatalogTransformerException {
inputStream = new FileInputStream("src/test/resources/metacard2.xml");
saxEventHandlerFactory = new XmlSaxEventHandlerFactoryImpl();
saxEventHandler = saxEventHandlerFactory.getNewSaxEventHandler();
assertThat(saxEventHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
GMLHandler gh = new GMLHandler(new GeometryFactory(), (ErrorHandler) null);
gmlHandler = new GmlHandler(gh, gml3ToWkt);
assertThat(gmlHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
saxEventHandlerDelegate = new SaxEventHandlerDelegate(Arrays.asList(saxEventHandler, gmlHandler));
Metacard metacard = saxEventHandlerDelegate.read(inputStream).getMetacard(null);
assertThat(metacard.getAttribute(Metacard.TITLE).getValues().size(), is(1));
assertThat(metacard.getAttribute(Metacard.TITLE).getValues().get(0), is("Title!"));
assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().size(), is(1));
assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().get(0), is("Description!"));
assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().size(), is(1));
assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().get(0), is("POC!"));
assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().size(), is(1));
assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().get(0), is("foobar"));
assertThat(metacard.getAttribute(Metacard.CONTENT_TYPE), is(nullValue()));
assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().size(), is(1));
assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().get(0), is("POINT (100 200)"));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326EpsgMatch.
@Test
public void testTransformEpsg4326EpsgMatch() throws FactoryException, TransformException, GeoFormatException {
double lon = 33.45;
double lat = 25.22;
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate coordinate = new Coordinate(lon, lat);
Point utmPoint = geometryFactory.createPoint(coordinate);
Envelope envelope = JTS.toEnvelope(utmPoint);
Geometry utmGeometry = JTS.toGeometry(envelope);
Geometry lonLatGeom = GeospatialUtil.transformToEPSG4326LonLatFormat(utmGeometry, sourceCRS);
assertThat(lonLatGeom.getCoordinates()[0].x, closeTo(lon, .00001));
assertThat(lonLatGeom.getCoordinates()[0].y, closeTo(lat, .00001));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326LonLat.
@Test
public void testTransformEpsg4326LonLat() throws GeoFormatException {
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate(25.22, 33.45);
Point point = gf.createPoint(coord);
Geometry convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(point, GeospatialUtil.EPSG_4326);
assertThat(convertedGeometry.getCoordinates()[0].x, is(33.45));
assertThat(convertedGeometry.getCoordinates()[0].y, is(25.22));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class CswMarshallHelper method writeBoundingBox.
static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
List<Geometry> geometries = new LinkedList<>();
for (AttributeDescriptor ad : attrDescs) {
if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
Attribute attr = metacard.getAttribute(ad.getName());
if (attr != null) {
if (ad.isMultiValued()) {
for (Serializable value : attr.getValues()) {
geometries.add(XmlNode.readGeometry((String) value));
}
} else {
geometries.add(XmlNode.readGeometry((String) attr.getValue()));
}
}
}
}
Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
Envelope bounds = allGeometry.getEnvelopeInternal();
if (!bounds.isNull()) {
String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
writer.startNode(bbox);
writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
writer.startNode(lower);
writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
writer.endNode();
writer.startNode(upper);
writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
writer.endNode();
writer.endNode();
}
}
use of com.vividsolutions.jts.geom.GeometryFactory in project graphhopper by graphhopper.
the class Utils method toWKT.
public static String toWKT(PointList list) {
int n = list.size();
GeometryFactory factory = new GeometryFactory();
Coordinate[] coords = new Coordinate[n];
for (int i = 0; i < coords.length; i++) {
coords[i] = new Coordinate(list.getLon(i), list.getLat(i));
}
return factory.createLineString(coords).toText();
}
Aggregations