本文整理匯總了Java中com.vividsolutions.jts.geom.GeometryFactory.createPolygon方法的典型用法代碼示例。如果您正苦於以下問題:Java GeometryFactory.createPolygon方法的具體用法?Java GeometryFactory.createPolygon怎麽用?Java GeometryFactory.createPolygon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.GeometryFactory
的用法示例。
在下文中一共展示了GeometryFactory.createPolygon方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getShape
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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: checkIfTileIsOnLand
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* check if the tile is on land
*
* @param top
* @param left
* @param bottom
* @param right
* @return
*/
public boolean checkIfTileIsOnLand(double top,double left,double bottom,double right){
boolean isOnLand=false;
if(land!=null){
GeometryFactory fact = new GeometryFactory();
Coordinate[] cs=new Coordinate[5];
cs[0]=new Coordinate(top, left);
cs[1]=new Coordinate(bottom, left);
cs[2]=new Coordinate(top,right);
cs[3]=new Coordinate(bottom,right);
cs[4]=new Coordinate(top,left);
Polygon tile=fact.createPolygon(cs);
for (Geometry p : land) {
if (p.contains(tile)) {
isOnLand=true;
break;
}
}
}
return isOnLand;
}
示例3: rasterize
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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;
}
示例4: rasterize
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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;
}
示例5: main
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner();
Coordinate footprint1 = new Coordinate(-2.0,0.5);
Coordinate footprint2 = new Coordinate(2.0,0.5);
Coordinate footprint3 = new Coordinate(2.0,-0.5);
Coordinate footprint4 = new Coordinate(-2.0,-0.5);
rsp.setRadius(0.5);
rsp.setFootprint(footprint1,footprint2,footprint3,footprint4);
JTSDrawingPanel panel = JTSDrawingPanel.makeEmpty("debug");
GeometryFactory gf = new GeometryFactory();
Polygon footprint = gf.createPolygon(new Coordinate[] {footprint1,footprint2,footprint3,footprint4,footprint1});
Polygon smoothedFootprint = gf.createPolygon(rsp.getCollisionCircleCenters());
System.out.println("Smoothing went from " + footprint.getCoordinates().length + " to " + smoothedFootprint.getCoordinates().length + " points");
panel.addGeometry("orig", footprint, true, true, true, "#00FF00");
panel.addGeometry("smooth", smoothedFootprint, false, false, true, "#FF0000");
for (int i = 0; i < smoothedFootprint.getCoordinates().length; i++) {
double delta = 0.1;
Coordinate p1 = new Coordinate(smoothedFootprint.getCoordinates()[i].x,smoothedFootprint.getCoordinates()[i].y);
Coordinate p2 = new Coordinate(smoothedFootprint.getCoordinates()[i].x+delta,smoothedFootprint.getCoordinates()[i].y+delta);
Coordinate p3 = new Coordinate(smoothedFootprint.getCoordinates()[i].x-delta,smoothedFootprint.getCoordinates()[i].y+delta);
panel.addGeometry("_cp"+i, gf.createPolygon(new Coordinate[] {p1,p2,p3,p1}), false, false, false, "#000000");
}
}
示例6: makeObstacle
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
private Geometry makeObstacle(Pose p) {
GeometryFactory gf = new GeometryFactory();
Geometry geom = null;
if (obstacleFootprint == null) {
geom = gf.createPolygon(new Coordinate[] { new Coordinate(0.0,0.0), new Coordinate(0.0,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,0.0), new Coordinate(0.0,0.0) });
}
else {
geom = gf.createPolygon(obstacleFootprint);
}
AffineTransformation at = new AffineTransformation();
at.rotate(p.getTheta());
at.translate(p.getX(), p.getY());
Geometry transGeom = at.transform(geom);
Pose center = new Pose(p.getX(), p.getY(), p.getTheta());
obstacles.add(transGeom);
obstacleCenters.add(center);
return transGeom;
}
示例7: homothetie
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
public static Polygon homothetie(Polygon geom, double x0, double y0,
double scale) {
GeometryFactory gf = new GeometryFactory();
// le contour externe
Coordinate[] coord = geom.getExteriorRing().getCoordinates();
Coordinate[] coord_ = new Coordinate[coord.length];
for (int i = 0; i < coord.length; i++) {
coord_[i] = new Coordinate(x0 + scale * (coord[i].x - x0),
y0 + scale * (coord[i].y - y0));
}
LinearRing lr = gf.createLinearRing(new CoordinateArraySequence(coord_));
// les trous
LinearRing[] trous = new LinearRing[geom.getNumInteriorRing()];
for (int j = 0; j < geom.getNumInteriorRing(); j++) {
Coordinate[] hole_coord = geom.getInteriorRingN(j).getCoordinates();
Coordinate[] hole_coord_ = new Coordinate[hole_coord.length];
for (int i = 0; i < hole_coord.length; i++) {
hole_coord_[i] = new Coordinate(x0 + scale * (hole_coord[i].x - x0),
y0 + scale * (hole_coord[i].y - y0));
}
trous[j] = gf.createLinearRing(new CoordinateArraySequence(hole_coord_));
}
return gf.createPolygon(lr, trous);
}
示例8: fermeture
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* Calcul de la fermeture d'un polygone.
* @param polygon polygone de départ
* @param distance distance utilisée pour le buffer positif puis pour le buffer négatif
* @param distanceTolerance distance utilisée pour la simplification par l'algorithme de Douglas-Peucker
* @param quadrantSegments nombre de segments utilisés pour la simplification par l'algorithme de Douglas-Peucker
* @param endCapStyle type d'approximation utilisée pour la simplification par l'algorithme de Douglas-Peucker
* @param factory factory pour la géométrie
* @return la fermeture du polygone passé en paramètre
*/
public static Polygon fermeture(Polygon polygon,double distance,double distanceTolerance,int quadrantSegments,int endCapStyle,GeometryFactory factory) {
LinearRing exterior = (LinearRing) polygon.getExteriorRing();
Geometry boundary = factory.createPolygon(exterior, null);
Polygon result = null;
try{
boundary = boundary.buffer(distance,quadrantSegments,endCapStyle);
boundary = boundary.buffer(-distance,quadrantSegments,endCapStyle);
if (boundary.isEmpty()) return polygon;
result = (Polygon)JtsAlgorithms.filtreDouglasPeucker(boundary,distanceTolerance);
} catch (Exception e) {
logger.error(polygon.toText());
logger.error(boundary.toText());
e.printStackTrace();
}
return result;
}
示例9: translation
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* Translate une géométrie.
* Translate a geometry.
*
* @param geom une géométrie, a geometry
* @param dx translation suivant l'axe des x, translation along the X axis
* @param dy translation suivant l'axe des Y, translation along the Y axis
* @return polygone résultant de la translation, resulting polygon.
*/
public static Polygon translation(Polygon geom, double dx, double dy){
GeometryFactory gf=new GeometryFactory();
//le contour externe
Coordinate[] coord=geom.getExteriorRing().getCoordinates();
Coordinate[] coord_=new Coordinate[coord.length];
for(int i=0;i<coord.length;i++) coord_[i]=new Coordinate(coord[i].x+dx, coord[i].y+dy);
LinearRing lr=gf.createLinearRing(coord_);
//les trous
LinearRing[] trous=new LinearRing[geom.getNumInteriorRing()];
for(int j=0;j<geom.getNumInteriorRing();j++){
Coordinate[] hole_coord=geom.getInteriorRingN(j).getCoordinates();
Coordinate[] hole_coord_=new Coordinate[hole_coord.length];
for(int i=0;i<hole_coord.length;i++) hole_coord_[i]=new Coordinate(hole_coord[i].x+dx, hole_coord[i].y+dy);
trous[j]=gf.createLinearRing(hole_coord_);
}
return gf.createPolygon(lr,trous);
}
示例10: rasterizeJTS
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
*/
public BufferedImage rasterizeJTS(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));
for (Geometry p : maskGeometries) {
if (p.intersects(geom)) {
Geometry pg=p.intersection(geom).buffer(0);
//Coordinate[] coordsInter=gg.getCoordinates();
//Polygon pg=gf.createPolygon(coordsInter);
for(int x=0;x<rect.width;x++){
for(int y=0;y<rect.height;y++){
Point point=gf.createPoint(new Coordinate(rect.x+x,rect.y+y));
if(pg.contains(point)){
try{
image.setRGB(x,y, Color.WHITE.getRGB());
}catch(Exception e){
logger.error(e.getMessage()+" x:"+x+" y:"+y);
}
}
}
}
}
}
return image;
}
示例11: createPolygon
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
*
* @param vx
* @param vy
* @param width
* @param height
* @return
*/
public static Polygon createPolygon(double vx,double vy,double width,double height){
GeometryFactory gf=new GeometryFactory();
Coordinate[] vertex=new Coordinate[5];
vertex[0]=new Coordinate(vx,vy);
vertex[1]=new Coordinate(vx+width,vy);
vertex[2]=new Coordinate(vx+height,vy+width);
vertex[3]=new Coordinate(vx,vy+height);
vertex[4]=new Coordinate(vx,vy);
return gf.createPolygon(vertex);
}
示例12: getShape
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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;
}
示例13: toPolygon
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
protected Polygon toPolygon(GeometryFactory factory) {
final LinearRing shell = linearRing(factory, this.shell.coordinates);
final LinearRing[] holes = new LinearRing[this.holes.size()];
Iterator<LineStringBuilder> iterator = this.holes.iterator();
for (int i = 0; iterator.hasNext(); i++) {
holes[i] = linearRing(factory, iterator.next().coordinates);
}
return factory.createPolygon(shell, holes);
}
示例14: smoothLineString
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
private static Geometry smoothLineString(GeometryFactory factory, GeometrySmoother smoother,
Geometry geom, double fit) {
if (geom instanceof LinearRing) {
// Treat as a Polygon
Polygon poly = factory.createPolygon((LinearRing) geom, null);
Polygon smoothed = smoother.smooth(poly, fit);
return smoothed.getExteriorRing();
} else {
return smoother.smooth((LineString) geom, fit);
}
}
示例15: removeCollinearVertices
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* Removes collinear vertices from the provided {@link Polygon}.
*
* @param polygon the instance of a {@link Polygon} to remove collinear vertices from.
* @return a new instance of the provided {@link Polygon} without collinear vertices.
*/
static Polygon removeCollinearVertices(final Polygon polygon) {
if (polygon == null) {
throw new NullPointerException("The provided Polygon is null");
}
// reuse existing factory
final GeometryFactory gf = polygon.getFactory();
// work on the exterior ring
LineString exterior = polygon.getExteriorRing();
LineString shell = removeCollinearVertices(exterior);
if ((shell == null) || shell.isEmpty()) {
return null;
}
// work on the holes
List<LineString> holes = new ArrayList<LineString>();
final int size = polygon.getNumInteriorRing();
for (int i = 0; i < size; i++) {
LineString hole = polygon.getInteriorRingN(i);
hole = removeCollinearVertices(hole);
if ((hole != null) && !hole.isEmpty()) {
holes.add(hole);
}
}
return gf.createPolygon((LinearRing) shell, holes.toArray(new LinearRing[holes.size()]));
}