本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.intersects方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.intersects方法的具體用法?Java Geometry.intersects怎麽用?Java Geometry.intersects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.intersects方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: mergePolygons
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
* @param polygons
* @return
*/
public static List<Geometry> mergePolygons(List<Geometry> polygons) {
boolean done;
do {
done = true;
for (int i = 0; i < polygons.size(); i++) {
Geometry a = polygons.get(i);
for (int j = i + 1; j < polygons.size();) {
final Geometry b = polygons.get(j);
if (a.intersects(b)) {
polygons.set(i, (Polygon) a.union(b));
a = polygons.get(i);
polygons.remove(j);
done = false;
}
else {
j++;
}
}
}
} while (!done);
return polygons;
}
示例5: symDifference
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
* @param polygons
* @return
*/
public static List<Geometry> symDifference(List<Geometry> polygons) {
boolean done;
do {
done = true;
for (int i = 0; i < polygons.size(); i++) {
Geometry a = polygons.get(i);
for (int j = i + 1; j < polygons.size();) {
final Geometry b = polygons.get(j);
if (a.intersects(b)) {
polygons.set(i, (Polygon) a.symDifference(b));
a = polygons.get(i);
polygons.remove(j);
done = false;
}
else {
j++;
}
}
}
} while (!done);
return polygons;
}
示例6: getSegments
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private List<Geometry> getSegments(Geometry sourceLines,
List<Geometry> lines) {
List<Geometry> segments = new ArrayList<Geometry>();
for (Geometry line : lines) {
if (sourceLines.intersects(line) && !line.crosses(sourceLines)) {
segments.add(line);
}
}
return segments;
}
示例7: rasterizeJTS
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 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;
}
示例8: 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;
}
示例9: getBackBlockingObstacle
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Get the last placement along the {@link Trajectory} of a {@link TrajectoryEnvelope} that does
* not overlap with the final pose of the robot.
* @param te The trajectory envelope to search on
* @return The last placement along the {@link Trajectory} of a {@link TrajectoryEnvelope} that does
* not overlap with the final pose of the robot.
*/
public static Geometry getBackBlockingObstacle(TrajectoryEnvelope te) {
Trajectory traj = te.getTrajectory();
PoseSteering[] path = traj.getPoseSteering();
Geometry placementLast = te.makeFootprint(path[path.length-1]);
for (int i = path.length-2; i >= 0; i--) {
Geometry placement = te.makeFootprint(path[i]);
if (!placement.intersects(placementLast)) return placement;
}
return null;
}
示例10: getCriticalPoint
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Get the path index beyond which a robot should not navigate, given the {@link TrajectoryEnvelope} of another robot.
* @param te1 The {@link TrajectoryEnvelope} of the leading robot.
* @param te2 The {@link TrajectoryEnvelope} of the yielding robot.
* @param currentPIR1 The current path index of the leading robot.
* @param te1Start The path index
* @param te1End
* @param te2Start
* @return
*/
public int getCriticalPoint(int yieldingRobotID, CriticalSection cs, int leadingRobotCurrentPathIndex) {
//Number of additional path points robot 2 should stay behind robot 1
int TRAILING_PATH_POINTS = 3;
int leadingRobotStart = -1;
int yieldingRobotStart = -1;
int leadingRobotEnd = -1;
int yieldingRobotEnd = -1;
if (cs.getTe1().getRobotID() == yieldingRobotID) {
leadingRobotStart = cs.getTe2Start();
yieldingRobotStart = cs.getTe1Start();
leadingRobotEnd = cs.getTe2End();
yieldingRobotEnd = cs.getTe1End();
}
else {
leadingRobotStart = cs.getTe1Start();
yieldingRobotStart = cs.getTe2Start();
leadingRobotEnd = cs.getTe1End();
yieldingRobotEnd = cs.getTe2End();
}
TrajectoryEnvelope leadingRobotTE = null;
TrajectoryEnvelope yieldingRobotTE = null;
if (cs.getTe1().getRobotID() == yieldingRobotID) {
leadingRobotTE = cs.getTe2();
yieldingRobotTE = cs.getTe1();
}
else {
leadingRobotTE = cs.getTe1();
yieldingRobotTE = cs.getTe2();
}
if (leadingRobotCurrentPathIndex <= leadingRobotStart) {
return Math.max(0, yieldingRobotStart-TRAILING_PATH_POINTS);
}
//Compute sweep of robot 1's footprint from current position to LOOKAHEAD
Pose leadingRobotPose = leadingRobotTE.getTrajectory().getPose()[leadingRobotCurrentPathIndex];
Geometry leadingRobotInPose = TrajectoryEnvelope.getFootprint(leadingRobotTE.getFootprint(), leadingRobotPose.getX(), leadingRobotPose.getY(), leadingRobotPose.getTheta());
for (int i = leadingRobotCurrentPathIndex+1; i <= leadingRobotEnd; i++) {
Pose leadingRobotNextPose = leadingRobotTE.getTrajectory().getPose()[i];
leadingRobotInPose = leadingRobotInPose.union(TrajectoryEnvelope.getFootprint(leadingRobotTE.getFootprint(), leadingRobotNextPose.getX(), leadingRobotNextPose.getY(), leadingRobotNextPose.getTheta()));
}
//Return pose at which yielding robot should stop given driving robot's projected sweep
for (int i = yieldingRobotStart; i < yieldingRobotEnd; i++) {
Pose yieldingRobotPose = yieldingRobotTE.getTrajectory().getPose()[i];
Geometry yieldingRobotInPose = TrajectoryEnvelope.getFootprint(yieldingRobotTE.getFootprint(), yieldingRobotPose.getX(), yieldingRobotPose.getY(), yieldingRobotPose.getTheta());
if (leadingRobotInPose.intersects(yieldingRobotInPose)) {
return Math.max(0, i-TRAILING_PATH_POINTS);
}
}
//The only situation where the above has not returned is when robot 2 should
//stay "parked", therefore wait at index 0
return Math.max(0, yieldingRobotStart-TRAILING_PATH_POINTS);
}