本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.getArea方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.getArea方法的具體用法?Java Geometry.getArea怎麽用?Java Geometry.getArea使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.getArea方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSharedAreaRatio
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
try {
return geom1.intersection(geom2).getArea() / geom1.getArea();
} catch (TopologyException e) {
// HACK: there appears to be a bug in JTS, but I can't
// reproduce it consistently. Why should computing the
// intersection with a MultiPolygon fail when computing
// the intersection with each of its constituent Polygons
// succeeds? I have no idea, but it does happen. This
// seems to fix the problem, though.
double result = 0.0;
if (geom2 instanceof GeometryCollection) {
GeometryCollection gc = (GeometryCollection)geom2;
for (int j = 0; j < gc.getNumGeometries(); j += 1) {
result += geom1.intersection(gc.getGeometryN(j)).getArea();
}
return result / geom1.getArea();
} else {
throw e;
}
}
}
示例2: getArea
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public static double getArea(Geometry geom, Boolean inMeters) throws Exception
{
if (inMeters) {
if (geom instanceof Polygon)
{
Polygon poly = (Polygon) geom;
double area = Math.abs(getSignedArea(poly.getExteriorRing().getCoordinateSequence()));
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LineString hole = poly.getInteriorRingN(i);
area -= Math.abs(getSignedArea(hole.getCoordinateSequence()));
}
return area;
}
else if (geom instanceof LineString)
{
LineString ring = (LineString)geom;
return getSignedArea(ring.getCoordinateSequence());
}
else
{
if (TRANSFORM_WGS84_SPHERICALMERCATOR == null) {
String wkt = "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],AUTHORITY[\"EPSG\",\"3857\"]]";
CoordinateReferenceSystem crs = CRS.parseWKT(wkt);// CRS.decode("EPSG:3857");
TRANSFORM_WGS84_SPHERICALMERCATOR = CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs, true);
}
Geometry transformedGeometry = JTS.transform(geom, TRANSFORM_WGS84_SPHERICALMERCATOR);
return transformedGeometry.getArea();
}
} else {
return geom.getArea();
}
}
示例3: geometry
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
@Override
public void geometry(Geometry arg0) {
if (arg0 == null || arg0.getArea() < 80)
return;
// TODO Auto-generated method stub
if (count != 0) {
System.out.println(arg0.getGeometryType());
try {
Point cen = arg0.getCentroid();
Coordinate latLong = new Coordinate();
JTS.transform(cen.getCoordinate(), latLong, transform);
System.out.println(" ************************* " + count + " " + featureName);
System.out.println("in EPSG:27700 " + cen);
System.out.println("lat long " + latLong);
URL url = new URL("https://maps.googleapis.com/maps/api/staticmap?center="+latLong.x+","+latLong.y+"&zoom=20&size=640x640&maptype=satellite&format=png32&key=AIzaSyDYAQH5nMlF0vEfdIg0seTiGUIcRbLNeI4");
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
//
BufferedImage image = ImageIO.read(is);// new BufferedImage( 640,640, BufferedImage.TYPE_3BYTE_BGR );
// BufferedImage image = new BufferedImage( 640,640, BufferedImage.TYPE_3BYTE_BGR );
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double scale = 11f;
int imageCenX = image.getWidth () >> 1,
imageCenY = image.getHeight() >> 1;
g2.setColor(Color.red);
g2.setStroke(new BasicStroke(2f));
for (Pair<Coordinate, Coordinate> pair : new ConsecutivePairs<Coordinate>( Arrays.asList( arg0.getCoordinates() ), true)) {
double
x1 = pair.first().x - cen.getCoordinate().x,
y1 = pair.first().y - cen.getCoordinate().y,
x2 = pair.second().x - cen.getCoordinate().x,
y2 = pair.second().y - cen.getCoordinate().y;
x1 *= scale; x2 *= scale; y1 *= scale; y2 *= scale;
g2.draw( new Line2D.Double(x1 + imageCenX, - y1 + imageCenY, x2 + imageCenX, - y2 +imageCenY) );
}
g2.drawString( HeightsToRedis.getHeight(featureName) +"m below roof", 5, 15 );
g2.drawString( HeightsToRedis.getRoof(featureName) +"m including roof", 5, 30 );
g2.drawString( latLong.x + ", " + latLong.y + " location ", 5, 45 );
g2.dispose();
ImageIO.write(image, "png", new FileOutputStream ( String.format( "/home/twak/data/footprints/center%04d.png", count )) );
is.close();
if (count > 1000)
System.exit(0);
} catch (Throwable e) {
e.printStackTrace();
System.exit(0);
}
}
count++;
featureName = "?";
}