use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class WfsFilterDelegate method bufferGeometry.
private String bufferGeometry(String wkt, double distance) {
LOGGER.debug("Buffering WKT {} by distance {} meter(s).", wkt, distance);
String bufferedWkt = null;
try {
Geometry geometry = getGeometryFromWkt(wkt);
double bufferInDegrees = metersToDegrees(distance);
LOGGER.debug("Buffering {} by {} degree(s).", geometry.getClass().getSimpleName(), bufferInDegrees);
Geometry bufferedGeometry = geometry.buffer(bufferInDegrees);
bufferedWkt = new WKTWriter().write(bufferedGeometry);
LOGGER.debug("Buffered WKT: {}.", bufferedWkt);
} catch (ParseException e) {
throw new IllegalArgumentException("Unable to parse WKT String", e);
}
return bufferedWkt;
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class WfsFilterDelegate method getCoordinatesFromWkt.
private Coordinate[] getCoordinatesFromWkt(String wkt) {
Coordinate[] coordinates = null;
try {
Geometry geo = getGeometryFromWkt(wkt);
coordinates = geo.getCoordinates();
} catch (ParseException e) {
throw new IllegalArgumentException("Unable to parse WKT String", e);
}
return coordinates;
}
use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.
the class GeometrySerializer method write.
@Override
public void write(Object obj, final DataOutput out) throws IOException {
final Geometry geom = (Geometry) obj;
final int geometryType = getGeometryType(geom);
final int typeAndMasks = geometryType;
writeUnsignedVarInt(typeAndMasks, out);
geom.apply(new EncodingSequenceFilter(out, true));
}
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 GeoGig by boundlessgeo.
the class MappingRule method hasCompatibleGeometryType.
private boolean hasCompatibleGeometryType(Feature feature) {
getFeatureType();
GeomRestriction restriction = getGeomRestriction();
GeometryAttribute property = feature.getDefaultGeometryProperty();
Geometry geom = (Geometry) property.getValue();
if (geom.getClass().equals(Point.class)) {
return geometryType == Point.class;
} else {
if (geometryType.equals(Point.class)) {
return false;
}
Coordinate[] coords = geom.getCoordinates();
if (geometryType.equals(Polygon.class) && coords.length < 3) {
return false;
}
boolean isClosed = coords[0].equals(coords[coords.length - 1]);
if (isClosed && restriction.equals(GeomRestriction.ONLY_OPEN_LINES)) {
return false;
}
if (!isClosed && restriction.equals(GeomRestriction.ONLY_CLOSED_LINES)) {
return false;
}
return true;
}
}
Aggregations