use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.
the class GeometryDiffTest method testConflictEditedSamePoint.
@Test
public void testConflictEditedSamePoint() throws Exception {
Geometry oldGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
Geometry newGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
Geometry newGeom2 = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom2));
assertTrue(diff.conflicts(diff2));
}
use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.
the class ResponseWriter method writeMerged.
/**
* Writes the response for a set of merged features while also supplying the geometry.
*
* @param geogig - a CommandLocator to call commands from
* @param features - a FeatureInfo iterator to build the response from
* @throws XMLStreamException
*/
public void writeMerged(final Context geogig, Iterator<FeatureInfo> features) throws XMLStreamException {
Iterator<GeometryChange> changeIterator = Iterators.transform(features, new Function<FeatureInfo, GeometryChange>() {
@Override
public GeometryChange apply(FeatureInfo input) {
GeometryChange change = null;
RevFeature revFeature = RevFeatureBuilder.build(input.getFeature());
RevFeatureType featureType = input.getFeatureType();
Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
String crsCode = null;
for (PropertyDescriptor attrib : attribs) {
PropertyType attrType = attrib.getType();
if (attrType instanceof GeometryType) {
GeometryType gt = (GeometryType) attrType;
CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
if (crs != null) {
try {
crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
} catch (FactoryException e) {
crsCode = null;
}
if (crsCode != null) {
crsCode = "EPSG:" + crsCode;
}
}
break;
}
}
FeatureBuilder builder = new FeatureBuilder(featureType);
GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(revFeature.getId().toString(), revFeature);
change = new GeometryChange(simpleFeature, ChangeType.MODIFIED, input.getPath(), crsCode);
return change;
}
});
while (changeIterator.hasNext()) {
GeometryChange next = changeIterator.next();
if (next != null) {
GeogigSimpleFeature feature = next.getFeature();
out.writeStartElement("Feature");
writeElement("change", "MERGED");
writeElement("id", next.getPath());
List<Object> attributes = feature.getAttributes();
for (Object attribute : attributes) {
if (attribute instanceof Geometry) {
writeElement("geometry", ((Geometry) attribute).toText());
break;
}
}
if (next.getCRS() != null) {
writeElement("crs", next.getCRS());
}
out.writeEndElement();
}
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeometryCollection method toCompositeGeometry.
public static CompositeGeometry toCompositeGeometry(List geometries) {
Geometry[] allGeometries = new Geometry[geometries.size()];
for (int i = 0; i < allGeometries.length; i++) {
Map jsonGeometry = (Map) geometries.get(i);
allGeometries[i] = getCompositeGeometry(jsonGeometry.get(TYPE_KEY).toString(), jsonGeometry).getGeometry();
}
return new GeometryCollection(GEOMETRY_FACTORY.createGeometryCollection(allGeometries));
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class JTSGeometryWrapperTest method testComputeJTSPeerWithGeometry.
@Test
public void testComputeJTSPeerWithGeometry() {
GeometryFactory fac = new GeometryFactory();
Geometry toWrap = fac.createPoint(new Coordinate(0, 0));
toTest = new JTSGeometryWrapper(toWrap);
assertEquals(toWrap, toTest.computeJTSPeer());
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeospatialEvaluator method buildGeometry.
public static Geometry buildGeometry(String gmlText) throws IOException, SAXException, ParserConfigurationException {
String methodName = "buildGeometry";
LOGGER.debug("ENTERING: {}", methodName);
Geometry geometry = null;
gmlText = supportSRSName(gmlText);
try {
LOGGER.debug("Creating geoTools Configuration ...");
Configuration config = new org.geotools.gml3.GMLConfiguration();
LOGGER.debug("Parsing geoTools configuration");
Parser parser = new Parser(config);
LOGGER.debug("Parsing gmlText");
geometry = (Geometry) (parser.parse(new StringReader(gmlText)));
LOGGER.debug("geometry (before conversion): {}", geometry.toText());
// The metadata schema states that <gml:pos> elements specify points in
// LAT,LON order. But WKT specifies points in LON,LAT order. When the geoTools
// libraries return the geometry data, it's WKT is in LAT,LON order (which is
// incorrect).
// As a workaround here, for Polygons and Points (which are currently the only spatial
// criteria supported) we must swap the x,y of each coordinate so that they are
// specified in LON,LAT order and then use the swapped coordinates to create a new
// Polygon or Point to be returned to the caller.
GeometryFactory geometryFactory = new GeometryFactory();
if (geometry instanceof Polygon) {
// Build new array of coordinates using the swapped coordinates
ArrayList<Coordinate> newCoords = new ArrayList<Coordinate>();
// Swap each coordinate's x,y so that they specify LON,LAT order
for (Coordinate coord : geometry.getCoordinates()) {
newCoords.add(new Coordinate(coord.y, coord.x));
}
// Create a new polygon using the swapped coordinates
Polygon polygon = new Polygon(geometryFactory.createLinearRing(newCoords.toArray(new Coordinate[newCoords.size()])), null, geometryFactory);
// this logs the transformed WKT
LOGGER.debug("Translates to {}", polygon.toText());
// with LON,LAT ordered points
LOGGER.debug("EXITING: {}", methodName);
return polygon;
}
if (geometry instanceof Point) {
// Create a new point using the swapped coordinates that specify LON,LAT order
Point point = geometryFactory.createPoint(new Coordinate(geometry.getCoordinate().y, geometry.getCoordinate().x));
// this logs the transformed WKT
LOGGER.debug("Translates to {}", point.toText());
// with a LON,LAT ordered point
LOGGER.debug("EXITING: {}", methodName);
return point;
}
} catch (Exception e) {
LOGGER.debug("Exception using geotools", e);
}
LOGGER.debug("No translation done for geometry - probably not good ...");
LOGGER.debug("EXITING: {}", methodName);
return geometry;
}
Aggregations