本文整理汇总了Java中com.vividsolutions.jts.geom.util.AffineTransformation类的典型用法代码示例。如果您正苦于以下问题:Java AffineTransformation类的具体用法?Java AffineTransformation怎么用?Java AffineTransformation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AffineTransformation类属于com.vividsolutions.jts.geom.util包,在下文中一共展示了AffineTransformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addObstacles
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public void addObstacles(Geometry ... geom) {
if (this.mapFilename == null) throw new Error("Please set a map file first!");
BufferedImage img = null;
try {
img = ImageIO.read(new File(mapFilename));
System.out.println("IMGTYPE: " + img.getType());
Graphics2D g2 = img.createGraphics();
ShapeWriter writer = new ShapeWriter();
g2.setPaint(Color.black);
for (Geometry g : geom) {
AffineTransformation at = new AffineTransformation();
at.scale(1.0/mapResolution, -1.0/mapResolution);
at.translate(0, img.getHeight());
Geometry scaledGeom = at.transform(g);
Shape shape = writer.toShape(scaledGeom);
System.out.println("Shape: " + shape.getBounds2D());
g2.fill(shape);
}
File outputfile = new File(TEMP_MAP_DIR + File.separator + "tempMap" + (numObstacles++) + ".png");
ImageIO.write(img, "png", outputfile);
this.mapFilename = outputfile.getAbsolutePath();
}
catch (IOException e) { e.printStackTrace(); }
}
示例2: makeObstacle
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的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;
}
示例3: testInPlaceUpdate
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
/**
* If the user mutate the geometry of the object, the object cache must not
* be updated.
*/
private void testInPlaceUpdate() throws SQLException {
Connection conn = getConnection(url);
try {
ResultSet rs = conn.createStatement().executeQuery(
"SELECT 'POINT(1 1)'::geometry");
assertTrue(rs.next());
// Mutate the geometry
((Geometry) rs.getObject(1)).apply(new AffineTransformation(1, 0,
1, 1, 0, 1));
rs.close();
rs = conn.createStatement().executeQuery(
"SELECT 'POINT(1 1)'::geometry");
assertTrue(rs.next());
// Check if the geometry is the one requested
assertEquals(1, ((Point) rs.getObject(1)).getX());
assertEquals(1, ((Point) rs.getObject(1)).getY());
rs.close();
} finally {
conn.close();
}
}
示例4: createArrow
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
private Geometry createArrow(Pose pose1, Pose pose2) {
GeometryFactory gf = new GeometryFactory();
double aux = 1.8;
double distance = (1.6/targetArrowHeadWidth)*Math.sqrt(Math.pow((pose2.getX()-pose1.getX()),2)+Math.pow((pose2.getY()-pose1.getY()),2));
double theta = Math.atan2(pose2.getY() - pose1.getY(), pose2.getX() - pose1.getX());
Coordinate[] coords = new Coordinate[8];
coords[0] = new Coordinate(0.0,-0.3);
coords[1] = new Coordinate(distance-aux,-0.3);
coords[2] = new Coordinate(distance-aux,-0.8);
coords[3] = new Coordinate(distance,0.0);
coords[4] = new Coordinate(distance-aux,0.8);
coords[5] = new Coordinate(distance-aux,0.3);
coords[6] = new Coordinate(0.0,0.3);
coords[7] = new Coordinate(0.0,-0.3);
Polygon arrow = gf.createPolygon(coords);
AffineTransformation at = new AffineTransformation();
at.scale(targetArrowHeadWidth/1.6, targetArrowHeadWidth/1.6);
at.rotate(theta);
at.translate(pose1.getX(), pose1.getY());
Geometry ret = at.transform(arrow);
return ret;
}
示例5: getNearestIntersected
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public AsteroidsSprite getNearestIntersected(Point loc, double rot, GameState world) {
// Create worldTransform to transform to the local-space shape to world-space:
AffineTransformation trans = new AffineTransformation();
trans.rotate(-rot);
trans.translate(loc.getX(), loc.getY());
worldShape = new PolyWrapper((Polygon)trans.transform(localShape));
// List of AsteroidsSprites that intersect with a circle described by
// <loc, distanceToNearest>
List<AsteroidsSprite> intersected = world.intersects(worldShape);
// Nearest AsteroidsSprite:
AsteroidsSprite nearest = AsteroidsSprite.nearest(loc, intersected);
return nearest;
}
示例6: getWorldToRectangle
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public static AffineTransformation getWorldToRectangle( Envelope worldEnvelope, Rectangle pixelRectangle ) {
int cols = (int) pixelRectangle.getWidth();
int rows = (int) pixelRectangle.getHeight();
double worldWidth = worldEnvelope.getWidth();
double worldHeight = worldEnvelope.getHeight();
double x = -worldEnvelope.getMinX();
double y = -worldEnvelope.getMinY();
AffineTransformation translate = AffineTransformation.translationInstance(x, y);
double xScale = cols / worldWidth;
double yScale = rows / worldHeight;
AffineTransformation scale = AffineTransformation.scaleInstance(xScale, yScale);
int m00 = 1;
int m10 = 0;
int m01 = 0;
int m11 = -1;
int m02 = 0;
int m12 = rows;
AffineTransformation mirror_y = new AffineTransformation(m00, m01, m02, m10, m11, m12);
AffineTransformation world2pixel = new AffineTransformation(translate);
world2pixel.compose(scale);
world2pixel.compose(mirror_y);
return world2pixel;
}
示例7: testTransformationUtils2
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public void testTransformationUtils2() throws Exception {
Envelope env = new Envelope(100, 200, 1000, 5000);
Rectangle rect = new Rectangle(0, 0, 100, 4000);
AffineTransformation worldToPixel = TransformationUtils.getWorldToRectangle(env, rect);
Coordinate srcPt = new Coordinate(150.0, 3000.0);
Coordinate transformed = worldToPixel.transform(srcPt, new Coordinate());
assertEquals(50, (int) transformed.x);
assertEquals(2000, (int) transformed.y);
srcPt = new Coordinate(100.0, 1000.0);
transformed = worldToPixel.transform(srcPt, new Coordinate());
assertEquals(0, (int) transformed.x);
assertEquals(4000, (int) transformed.y);
}
示例8: rotate
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
protected Geometry rotate(Geometry geom) {
if (this.rotationAngle != 0.0) {
AffineTransformation trans = AffineTransformation.rotationInstance(this.rotationAngle,
this.dim.getCentre().x, this.dim.getCentre().y);
geom.apply(trans);
}
return geom;
}
示例9: transformTest
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public static void transformTest() {
/*
* 37.5116785 127.1021436
*
* 37.5119898 127.1025482
*
* 37.5134122 127.1025103
*/
/*
*
*/
Coordinate coord1 = new Coordinate(0.14195979899497488, 0.056451612903225756);
Coordinate coord2 = new Coordinate(0.44597989949748745, 0.1088709677419355);
Coordinate coord3 = new Coordinate(0.9849246231155779, 0.9905913978494624);
Coordinate coord4 = new Coordinate(37.5116785, 127.1021436);
Coordinate coord5 = new Coordinate(37.5119898, 127.1025482);
Coordinate coord6 = new Coordinate(37.5134122, 127.1025103);
Coordinate test = new Coordinate(0.9510050251256281, 0.728494623655914);
Point p = JTSFactoryFinder.getGeometryFactory().createPoint(test);
AffineTransformation affine = new AffineTransformationBuilder(coord1, coord2, coord3,
coord4, coord5, coord6).getTransformation();
Geometry geom = affine.transform(p);
System.out.println(geom.toText());
}
示例10: makeFootprint
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
/**
* Returns a {@link Geometry} representing the footprint of the robot in a given pose.
* @param x The x coordinate of the pose used to create the footprint.
* @param y The y coordinate of the pose used to create the footprint.
* @param theta The orientation of the pose used to create the footprint.
* @return A {@link Geometry} representing the footprint of the robot in a given pose.
*/
public Geometry makeFootprint(double x, double y, double theta) {
AffineTransformation at = new AffineTransformation();
at.rotate(theta);
at.translate(x,y);
Geometry rect = at.transform(footprint);
return rect;
}
示例11: makeInnerFootprint
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
/**
* Returns a {@link Geometry} representing the inner footprint of the robot in a given pose.
* @param x The x coordinate of the pose used to create the inner footprint.
* @param y The y coordinate of the pose used to create the inner footprint.
* @param theta The orientation of the pose used to create the inner footprint.
* @return A {@link Geometry} representing the footprint of the inner robot in a given pose.
*/
public Geometry makeInnerFootprint(double x, double y, double theta) {
AffineTransformation at = new AffineTransformation();
at.rotate(theta);
at.translate(x,y);
Geometry rect = at.transform(innerFootprint);
return rect;
}
示例12: listToroidalGeometries
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
@Override
public List<Geometry> listToroidalGeometries(final Geometry geom) {
final Geometry copy = (Geometry) geom.clone();
final List<Geometry> geoms = new ArrayList<Geometry>();
final AffineTransformation at = new AffineTransformation();
geoms.add(copy);
for (int cnt = 0; cnt < 8; cnt++) {
at.setToTranslation(adjustedXVector[cnt], adjustedYVector[cnt]);
geoms.add(at.transform(copy));
}
return geoms;
}
示例13: returnToroidalGeom
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
public Geometry returnToroidalGeom(final GamaPoint loc) {
final List<Geometry> geoms = new ArrayList<Geometry>();
final Point pt = GeometryUtils.GEOMETRY_FACTORY.createPoint(loc);
final AffineTransformation at = new AffineTransformation();
geoms.add(pt);
for (int cnt = 0; cnt < 8; cnt++) {
at.setToTranslation(adjustedXVector[cnt], adjustedYVector[cnt]);
geoms.add(at.transform(pt));
}
return GeometryUtils.GEOMETRY_FACTORY.buildGeometry(geoms);
}
示例14: rotate
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
protected Geometry rotate(Geometry geom) {
if (rotationAngle != 0.0) {
AffineTransformation trans = AffineTransformation.rotationInstance(rotationAngle,
dim.getCentre().x, dim.getCentre().y);
geom.apply(trans);
}
return geom;
}
示例15: doVectorize
import com.vividsolutions.jts.geom.util.AffineTransformation; //导入依赖的package包/类
/**
* Helper function to run the Vectorize operation with given parameters and
* retrieve the vectors.
*
* @param src the source {@link GridCoverage2D}.
* @param args a {@code Map} of parameter names and values or <code>null</code>.
*
* @return the generated vectors as JTS Polygons
*/
@SuppressWarnings("unchecked")
public static Collection<Polygon> doVectorize( GridCoverage2D src, Map<String, Object> args ) {
if (args == null) {
args = new HashMap<String, Object>();
}
ParameterBlockJAI pb = new ParameterBlockJAI("Vectorize");
pb.setSource("source0", src.getRenderedImage());
// Set any parameters that were passed in
for( Entry<String, Object> e : args.entrySet() ) {
pb.setParameter(e.getKey(), e.getValue());
}
// Get the desintation image: this is the unmodified source image data
// plus a property for the generated vectors
RenderedOp dest = JAI.create("Vectorize", pb);
// Get the vectors
Collection<Polygon> polygons = (Collection<Polygon>) dest.getProperty(VectorizeDescriptor.VECTOR_PROPERTY_NAME);
RegionMap regionParams = CoverageUtilities.getRegionParamsFromGridCoverage(src);
double xRes = regionParams.getXres();
double yRes = regionParams.getYres();
final AffineTransform mt2D = (AffineTransform) src.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER);
final AffineTransformation jtsTransformation = new AffineTransformation(mt2D.getScaleX(), mt2D.getShearX(),
mt2D.getTranslateX() - xRes / 2.0, mt2D.getShearY(), mt2D.getScaleY(), mt2D.getTranslateY() + yRes / 2.0);
for( Polygon polygon : polygons ) {
polygon.apply(jtsTransformation);
}
return polygons;
}