本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.getNumPoints方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.getNumPoints方法的具體用法?Java Geometry.getNumPoints怎麽用?Java Geometry.getNumPoints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.getNumPoints方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getShape
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public Area getShape() {
Area maskArea = new Area();
Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) (c.x);
yPoints[i++] = (int) (c.y);
}
maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
}
}
return maskArea;
}
示例2: rasterize
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
*/
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {
// create the buffered image of the size of the Rectangle
BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
GeometryFactory gf = new GeometryFactory();
// define the clipping region in full scale
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords));
Graphics g2d = image.getGraphics();
g2d.setColor(Color.white);
for (Geometry p : maskGeometries) {
/*if(p instanceof MultiPolygon){
p=p.getBoundary();
}*/
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
i++;
}
g2d.fillPolygon(xPoints, yPoints, i);
}
}
g2d.dispose();
return image;
}
示例3: rasterize
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public BufferedImage rasterize(BufferedImage image, int offsetX, int offsetY, double scalingFactor) {
Rectangle rect = image.getRaster().getBounds();
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
Graphics g2d = image.getGraphics();
g2d.setColor(Color.WHITE);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) ((c.x - offsetX) * scalingFactor);
yPoints[i++] = (int) ((c.y - offsetY) * scalingFactor);
}
g2d.fillPolygon(xPoints, yPoints, p.getNumPoints());
}
}
g2d.dispose();
return image;
}
示例4: simplifyGeometry
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Returns a simplified version of the input geometry with a number of
* points reduced to a maximum provided in parameter.
*
* The simplification algorithm can be outlined as follow:
* <ul>
* <li>returns null if the input geometry is null;</li>
* <li>returns the input geometry if the input one has already a number
* of points lower or equal to the maximum allowed;</li>
* <li></li>
* </ul>
*
* @param input_geometry the geometry to be simplified.
* @param max_output_points the maximum number of points of output
* geometry.
*
* @return the simplified geometry or null if the input is null.
*/
private static Geometry simplifyGeometry(final Geometry input_geometry,
final int max_output_points)
{
Geometry geometry = input_geometry;
double cluster_factor = 0.2;
int current_point_number = -1;
int previous_point_number = -2;
while ((current_point_number != previous_point_number)
&& (geometry.getNumPoints() > max_output_points))
{
previous_point_number = current_point_number;
current_point_number = geometry.getNumPoints();
geometry = simplifyGeometry(geometry, max_output_points,
cluster_factor);
cluster_factor += 0.05;
}
return geometry;
}
示例5: getShape
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public Area getShape(int width, int height) {
Area maskArea = new Area();
Rectangle rect = new Rectangle(0, 0, width,height);//reader.getWidth(), reader.getHeight());
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) (c.x);
yPoints[i++] = (int) (c.y);
}
maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
}
}
return maskArea;
}
示例6: pointStats
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private static FeatureStats pointStats(Geometry geom) {
final FeatureStats featureStats = new FeatureStats();
final HashSet<Point> pointSet = new HashSet<>(geom.getNumPoints());
featureStats.totalPts = geom.getNumPoints();
for (int i = 0; i < geom.getNumGeometries(); ++i) {
final Point p = (Point) geom.getGeometryN(i);
featureStats.repeatedPts += pointSet.add(p) ? 0 : 1;
}
return featureStats;
}
示例7: removeCollinearVertices
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Removes collinear vertices from the provided {@link Geometry} if the number of point exceeds the requested minPoints.
*
* <p>
* For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and {@link MultiPolygon} It will throw an exception if the
* geometry is not one of those types
*
* @param geometry the instance of a {@link Geometry} to remove collinear vertices from.
* @param minPoints perform removal of collinear points if num of vertices exceeds minPoints.
* @return a new instance of the provided {@link Geometry} without collinear vertices.
*/
public static Geometry removeCollinearVertices(final Geometry geometry, int minPoints) {
ensureNonNull("geometry", geometry);
if ((minPoints <= 0) || (geometry.getNumPoints() < minPoints)) {
return geometry;
}
if (geometry instanceof LineString) {
return removeCollinearVertices((LineString) geometry);
} else if (geometry instanceof Polygon) {
return removeCollinearVertices((Polygon) geometry);
} else if (geometry instanceof MultiPolygon) {
MultiPolygon mp = (MultiPolygon) geometry;
Polygon[] parts = new Polygon[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i++) {
Polygon part = (Polygon) mp.getGeometryN(i);
part = removeCollinearVertices(part);
parts[i] = part;
}
return geometry.getFactory().createMultiPolygon(parts);
}
throw new IllegalArgumentException(
"This method can work on LineString, Polygon and Multipolygon: "
+ geometry.getClass());
}