本文整理汇总了Java中com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier类的典型用法代码示例。如果您正苦于以下问题:Java DouglasPeuckerSimplifier类的具体用法?Java DouglasPeuckerSimplifier怎么用?Java DouglasPeuckerSimplifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DouglasPeuckerSimplifier类属于com.vividsolutions.jts.simplify包,在下文中一共展示了DouglasPeuckerSimplifier类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMergedBuffers
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public Geometry getMergedBuffers() {
if (this.mergedBuffers == null) {
// synchronized (this) {
Collection<Geometry> polygons = new ArrayList<>();
for (Stop stop : this.stops.values()) {
if (getStopTimesForStop(stop.stop_id).isEmpty()) {
continue;
}
if (stop.stop_lat > -1 && stop.stop_lat < 1 || stop.stop_lon > -1 && stop.stop_lon < 1) {
continue;
}
Point stopPoint = gf.createPoint(new Coordinate(stop.stop_lon, stop.stop_lat));
Polygon stopBuffer = (Polygon) stopPoint.buffer(.01);
polygons.add(stopBuffer);
}
Geometry multiGeometry = gf.buildGeometry(polygons);
this.mergedBuffers = multiGeometry.union();
if (polygons.size() > 100) {
this.mergedBuffers = DouglasPeuckerSimplifier.simplify(this.mergedBuffers, .001);
}
// }
}
return this.mergedBuffers;
}
示例2: iterateOverTriangles
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public static void iterateOverTriangles(final Polygon polygon, final Consumer<Geometry> action) {
final double elevation = getContourCoordinates(polygon).averageZ();
final double sizeTol = FastMath.sqrt(polygon.getArea()) / 100.0;
final DelaunayTriangulationBuilder dtb = new DelaunayTriangulationBuilder();
final PreparedGeometry buffered = PREPARED_GEOMETRY_FACTORY.create(polygon.buffer(sizeTol, 5, 0));
final Envelope3D env = Envelope3D.of(buffered.getGeometry());
try {
dtb.setSites(polygon);
dtb.setTolerance(sizeTol);
applyToInnerGeometries(dtb.getTriangles(GEOMETRY_FACTORY), (gg) -> {
final ICoordinates cc = getContourCoordinates(gg);
if (cc.isCoveredBy(env) && buffered.covers(gg)) {
cc.setAllZ(elevation);
gg.geometryChanged();
action.accept(gg);
}
});
} catch (final LocateFailureException | ConstraintEnforcementException e) {
final IScope scope = GAMA.getRuntimeScope();
GamaRuntimeException.warning("Impossible to triangulate: " + new WKTWriter().write(polygon), scope);
iterateOverTriangles((Polygon) DouglasPeuckerSimplifier.simplify(polygon, 0.1), action);
return;
}
}
示例3: operand
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
/**
* Simplification of a geometry (Douglas-Peuker algorithm)
*/
@operator (
value = "simplification",
category = { IOperatorCategory.SPATIAL, IOperatorCategory.SP_TRANSFORMATIONS },
concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_TRANSFORMATION })
@doc (
value = "A geometry corresponding to the simplification of the operand (geometry, agent, point) considering a tolerance distance.",
comment = "The algorithm used for the simplification is Douglas-Peucker",
examples = { @example (
value = "self simplification 0.1",
equals = "the geometry resulting from the application of the Douglas-Peuker algorithm on the geometry of the agent applying the operator with a tolerance distance of 0.1.",
test = false) })
public static IShape simplification(final IScope scope, final IShape g1, final Double distanceTolerance) {
if (g1 == null || g1.getInnerGeometry() == null) { return g1; }
if (g1.isPoint()) { return g1.copy(scope); }
final Geometry geomSimp = DouglasPeuckerSimplifier.simplify(g1.getInnerGeometry(), distanceTolerance);
if (geomSimp != null && !geomSimp.isEmpty() && geomSimp.isSimple()) { return new GamaShape(g1, geomSimp); }
return g1.copy(scope);
}
示例4: combineIntoOneGeometry
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public static Geometry combineIntoOneGeometry(
final Geometry geometry1,
final Geometry geometry2 ) {
if (geometry1 == null) {
return geometry2;
}
else if (geometry2 == null) {
return geometry1;
}
final List<Geometry> geometry = new ArrayList<Geometry>();
geometry.add(geometry1);
geometry.add(geometry2);
return DouglasPeuckerSimplifier.simplify(
combineIntoOneGeometry(geometry),
SIMPLIFICATION_MAX_DEGREES);
}
示例5: check
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
private Geometry check(Geometry geometry) {
if (maxCoordinatesInGeometry > 0) {
int distanceTolerance = 10;
while (geometry.getNumPoints() > maxCoordinatesInGeometry) {
geometry = DouglasPeuckerSimplifier.simplify(geometry, distanceTolerance);
distanceTolerance *= 2;
}
}
if (roundCoordinates) {
final double factor = Math.pow(10, roundNumberOfDecimals);
geometry.apply(new CoordinateFilter() {
@Override
public void filter(Coordinate coord) {
coord.x = Math.round(coord.x * factor) / factor;
coord.y = Math.round(coord.y * factor) / factor;
}
});
}
return geometry;
}
示例6: filtreDouglasPeucker
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
/**
* tente d'appliquer filtre de douglas peucker a une geometrie. en cas
* d'echec, renvoie la geometrie initiale
* @param geom
* @param seuil
* @return the resulting Geometry after the application of the DouglasPeucker
* filter
*/
public static Geometry filtreDouglasPeucker(Geometry geom, double seuil) {
if (seuil == 0.0) {
return (Geometry) geom.clone();
}
if (seuil < 0.0) {
JtsAlgorithms.logger
.warn(I18N
.getString("JtsAlgorithms.DouglasPeuckerWithNegativeThreshold") + seuil); //$NON-NLS-1$
return geom;
}
Geometry g = DouglasPeuckerSimplifier.simplify(geom, seuil);
if ((g == null) || g.isEmpty() || !g.isValid()) {
JtsAlgorithms.logger.warn(I18N
.getString("JtsAlgorithms.DouglasPeuckerError")); //$NON-NLS-1$
JtsAlgorithms.logger.warn(I18N
.getString("JtsAlgorithms.DouglasPeuckerThreshold") + seuil); //$NON-NLS-1$
JtsAlgorithms.logger
.warn(I18N.getString("JtsAlgorithms.Geometry") + geom); //$NON-NLS-1$
JtsAlgorithms.logger.warn(I18N.getString("JtsAlgorithms.Result") + g); //$NON-NLS-1$
return geom;
} else if (g.getGeometryType() != geom.getGeometryType()) {
JtsAlgorithms.logger.warn(I18N
.getString("JtsAlgorithms.DouglasPeuckerWithDifferentTypesError")); //$NON-NLS-1$
JtsAlgorithms.logger.warn(I18N
.getString("JtsAlgorithms.DouglasPeuckerThreshold") + seuil); //$NON-NLS-1$
JtsAlgorithms.logger
.warn(I18N.getString("JtsAlgorithms.Geometry") + geom); //$NON-NLS-1$
JtsAlgorithms.logger.warn(I18N.getString("JtsAlgorithms.Result") + g); //$NON-NLS-1$
return geom;
} else {
return g;
}
}
示例7: prepareROI
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
/**
* Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation.
*
* @param roi a {@link Geometry} in model space.
* @param mt2d an {@link AffineTransform} that maps from raster to model space. This is already referred to the pixel corner.
* @return a {@link ROI} suitable for using with JAI.
* @throws ProcessException in case there are problems with ivnerting the provided {@link AffineTransform}. Very unlikely to happen.
*/
public static ROI prepareROI( Geometry roi, AffineTransform mt2d ) throws Exception {
// transform the geometry to raster space so that we can use it as a ROI source
Geometry rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse()));
// simplify the geometry so that it's as precise as the coverage, excess coordinates
// just make it slower to determine the point in polygon relationship
Geometry simplifiedGeometry = DouglasPeuckerSimplifier.simplify(rasterSpaceGeometry, 1);
// build a shape using a fast point in polygon wrapper
return new ROIShape(new FastLiteShape(simplifiedGeometry));
}
示例8: computeProductGeometry
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
static Geometry computeProductGeometry(Product product) {
final GeneralPath[] paths = ProductUtils.createGeoBoundaryPaths(product);
final com.vividsolutions.jts.geom.Polygon[] polygons = new com.vividsolutions.jts.geom.Polygon[paths.length];
for (int i = 0; i < paths.length; i++) {
polygons[i] = convertAwtPathToJtsPolygon(paths[i]);
}
final DouglasPeuckerSimplifier peuckerSimplifier = new DouglasPeuckerSimplifier(
polygons.length == 1 ? polygons[0] : geometryFactory.createMultiPolygon(polygons));
return peuckerSimplifier.getResultGeometry();
}
示例9: transformFeature
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
private Map<String, Object> transformFeature(SimpleFeature feature) {
Map<String, Object> attributes = new HashMap<String, Object>();
for (Property prop : feature.getProperties()) {
attributes.put(prop.getName().getLocalPart(), prop.getValue());
}
GeometryAttribute geometryProperty = feature
.getDefaultGeometryProperty();
if (geometryProperty != null) {
String wktGeometry = "";
try {
if (feature.getDefaultGeometry() != null) {
Geometry geometry = (Geometry) feature
.getDefaultGeometry();
if (simplifyGeometry > 0) {
DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier(
geometry);
simplifier.setDistanceTolerance(simplifyGeometry);
geometry = simplifier.getResultGeometry();
}
if (transform != null) {
geometry = JTS.transform(geometry, transform);
}
wktGeometry = geometry.toString();
}
} catch (Exception e) {
LOGGER.warn("Could not convert Geometry to WKT String. Geometry will not be indexed!");
}
attributes.put(geometryProperty.getName().getLocalPart(),
wktGeometry);
attributes.put(FID_KEY, feature.getID());
}
return attributes;
}
示例10: makeBuffer
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public static Geometry makeBuffer(Graph graph) {
Geometry geom = geometryCollectionFromVertices(graph).buffer(.04, 6);
DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier(geom);
simplifier.setDistanceTolerance(0.00001);
return simplifier.getResultGeometry();
}
示例11: getFootprint
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public static Geometry getFootprint(
final ReferencedEnvelope projectedReferenceEnvelope,
final GridCoverage gridCoverage ) {
try {
final Envelope sampleEnvelope = gridCoverage.getEnvelope();
final double avgSpan = (projectedReferenceEnvelope.getSpan(0) + projectedReferenceEnvelope.getSpan(1)) / 2;
final MathTransform gridCrsToWorldCrs = CRS.findMathTransform(
gridCoverage.getCoordinateReferenceSystem(),
GeoWaveGTRasterFormat.DEFAULT_CRS,
true);
final Coordinate[] polyCoords = getWorldCoordinates(
sampleEnvelope.getMinimum(0),
sampleEnvelope.getMinimum(1),
sampleEnvelope.getMaximum(0),
sampleEnvelope.getMaximum(1),
gridCrsToWorldCrs.isIdentity() ? 2 : (int) Math.min(
Math.max(
(avgSpan * MIN_SEGMENTS) / SIMPLIFICATION_MAX_DEGREES,
MIN_SEGMENTS),
MAX_SEGMENTS),
gridCrsToWorldCrs);
final Polygon poly = new GeometryFactory().createPolygon(polyCoords);
if (polyCoords.length > MAX_VERTICES_BEFORE_SIMPLIFICATION) {
final Geometry retVal = DouglasPeuckerSimplifier.simplify(
poly,
SIMPLIFICATION_MAX_DEGREES);
if (retVal.isEmpty()) {
return poly;
}
return retVal;
}
else {
return poly;
}
}
catch (MismatchedDimensionException | TransformException | FactoryException e1) {
LOGGER.warn(
"Unable to calculate grid coverage footprint",
e1);
}
return null;
}
示例12: toDto
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Feature toDto(SimpleFeature feature, int maxCoordsPerFeature) throws IllegalArgumentException {
if (feature == null) {
throw new IllegalArgumentException("No feature was passed.");
}
Feature dto = new Feature(feature.getID());
HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>();
GeometryDescriptor geometryDescr = feature.getFeatureType().getGeometryDescriptor();
for (org.opengis.feature.type.AttributeDescriptor desc : feature.getType().getAttributeDescriptors()) {
if (null == geometryDescr || !geometryDescr.getName().getLocalPart().equals(desc.getLocalName())) {
Object obj = feature.getAttribute(desc.getName());
Attribute<?> value = toPrimitive(obj, desc.getType());
attributeMap.put(desc.getLocalName(), value);
}
}
dto.setAttributes(attributeMap);
dto.setId(feature.getID());
dto.setUpdatable(false);
dto.setDeletable(false);
dto.setLabel(feature.getID());
Object defaultGeometry = feature.getDefaultGeometry();
if (defaultGeometry instanceof Geometry) {
Geometry geometry = (Geometry) defaultGeometry;
if (maxCoordsPerFeature > 0) {
// we take the tolerance from the 1st geometry to make sure we don't end up with an empty geometry !
Envelope firstEnvelope = geometry.getGeometryN(0).getEnvelopeInternal();
double distanceTolerance = (firstEnvelope.getWidth() + firstEnvelope.getHeight()) / maxCoordsPerFeature;
while (geometry.getNumPoints() > maxCoordsPerFeature) {
geometry = DouglasPeuckerSimplifier.simplify(geometry, distanceTolerance);
distanceTolerance *= 2;
}
}
try {
dto.setGeometry(GeometryConverterService.fromJts(geometry));
} catch (JtsConversionException e) {
// OK then, no geometry for you...
log.error("Error while parsing geometry from GML: " + e.getMessage());
}
}
return dto;
}
示例13: simplifyDP
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
public static Geometry simplifyDP(Geometry g, double tolerance)
{
return DouglasPeuckerSimplifier.simplify(g, tolerance);
}
示例14: simplifyLineString
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier; //导入依赖的package包/类
/**
* The purpose of this method is to use the
* Douglas-Peuker line simplification algorithm to reduce the
* number of points in the polyline while maintaining route fidelity.
*
* @param polyline - The full set of points from the device.
* @return Simplified Geometry.
*/
public Geometry simplifyLineString(final Coordinate[] polyline) {
final LineString lineString = geometryFactory.createLineString(polyline);
return DouglasPeuckerSimplifier.simplify(lineString, 0.00001);
}