本文整理汇总了Java中org.geotools.geometry.jts.JTS类的典型用法代码示例。如果您正苦于以下问题:Java JTS类的具体用法?Java JTS怎么用?Java JTS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JTS类属于org.geotools.geometry.jts包,在下文中一共展示了JTS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: orthodromicDistance
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
void orthodromicDistance() throws Exception {
Coordinate start = null;
Coordinate end = null;
CoordinateReferenceSystem crs = null;
// orthodromicDistance start
double distance = JTS.orthodromicDistance(start, end, crs);
int totalmeters = (int) distance;
int km = totalmeters / 1000;
int meters = totalmeters - (km * 1000);
float remaining_cm = (float) (distance - totalmeters) * 10000;
remaining_cm = Math.round(remaining_cm);
float cm = remaining_cm / 100;
System.out.println("Distance = " + km + "km " + meters + "m " + cm + "cm");
// orthodromicDistance end
}
示例2: convertLonLatToEuclidean
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
@Deprecated
public static ProjectedCoordinate convertLonLatToEuclidean(
Coordinate lonlat) {
final MathTransform transform = getTransform(lonlat);
final Coordinate to = new Coordinate();
// the transform seems to swap the lat lon pairs
Coordinate latlon = new Coordinate(lonlat.y, lonlat.x);
try {
JTS.transform(latlon, to,
transform);
} catch (final TransformException e) {
e.printStackTrace();
}
return new ProjectedCoordinate(transform, new Coordinate(to.y, to.x), lonlat);
}
示例3: setCrs
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
public void setCrs(final CoordinateReferenceSystem crs) {
try {
// System.out.println(content.layers().size());
final ReferencedEnvelope rEnv = getDisplayArea();
// System.out.println(rEnv);
final CoordinateReferenceSystem sourceCRS = rEnv.getCoordinateReferenceSystem();
final CoordinateReferenceSystem targetCRS = crs;
final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
final com.vividsolutions.jts.geom.Envelope newJtsEnv = JTS.transform(rEnv, transform);
final ReferencedEnvelope newEnvelope = new ReferencedEnvelope(newJtsEnv, targetCRS);
content.getViewport().setBounds(newEnvelope);
fullExtent = null;
doSetDisplayArea(newEnvelope);
// ReferencedEnvelope displayArea =
getDisplayArea();
// System.out.println(displayArea);
} catch (final Exception e) {
e.printStackTrace();
}
}
示例4: CRSTransform
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
/**
* CRS transform.
*
* @param sourceEpsgCRSCode the source epsg CRS code
* @param targetEpsgCRSCode the target epsg CRS code
* @return true, if successful
*/
public boolean CRSTransform(String sourceEpsgCRSCode, String targetEpsgCRSCode)
{
try {
CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEpsgCRSCode);
CoordinateReferenceSystem targetCRS = CRS.decode(targetEpsgCRSCode);
final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
this.CRStransformation=true;
this.sourceEpsgCode=sourceEpsgCRSCode;
this.targetEpgsgCode=targetEpsgCRSCode;
this.rawSpatialRDD = this.rawSpatialRDD.map(new Function<T,T>()
{
@Override
public T call(T originalObject) throws Exception {
return (T) JTS.transform(originalObject,transform);
}
});
return true;
} catch (FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
示例5: transformEnvelope
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private ReferencedEnvelope transformEnvelope(CoordinateReferenceSystem fromCRS,
CoordinateReferenceSystem toCRS,
Rectangle2D bounds) {
try {
MathTransform transform = CRS.findMathTransform(fromCRS, toCRS);
Envelope sourceEnvelope = new Envelope(bounds.getMinX(), bounds.getMaxX(),
bounds.getMinY(), bounds.getMaxY());
final Envelope envelope = JTS.transform(sourceEnvelope, transform);
return new ReferencedEnvelope(envelope.getMinX(), envelope.getMaxX(),
envelope.getMinY(), envelope.getMaxY(),
toCRS);
} catch (FactoryException | TransformException e) {
e.printStackTrace();
return null;
}
}
示例6: call
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
public Object call(Properties bindings, Object[] args) {
if(args.length==2){
String lat = args[0].toString();
String lng = args[1].toString();
double[] latlng = {
Double.parseDouble(lat),
Double.parseDouble(lng)
};
GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
return JTS.toGeometry(builder.createPoint(latlng).getDirectPosition());
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 arguments");
}
示例7: getCells
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private Object getCells( Envelope env ) throws Exception {
MathTransform ll2CRSTransform = CRS.findMathTransform(leafletCRS, databaseCrs);
MathTransform crs2llTransform = CRS.findMathTransform(databaseCrs, leafletCRS);
Polygon searchPolygonLL = GeometryUtilities.createPolygonFromEnvelope(env);
Geometry searchPolygonLLCRS = JTS.transform(searchPolygonLL, ll2CRSTransform);
long t1 = System.currentTimeMillis();
List<LasCell> lasCells = LasCellsTable.getLasCells(currentConnectedDatabase, searchPolygonLLCRS, true, true, false, false,
false);
int size = lasCells.size();
long t2 = System.currentTimeMillis();
System.out.println("time: " + (t2 - t1) + " size = " + size);
if (size == 0) {
return null;
}
loadedElementsNumText.setText("" + size);
JSONObject rootObj = cells2Json(crs2llTransform, lasCells);
return rootObj.toString();
}
示例8: reprojectToEqualArea
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
/**
* Private method which reprojects the input Geometry in the input CRS to a Lambert-Equal Area CRS used for calculating Geometry Area and
* perimeter.
*
* @param sourceCRS Source geometry CRS.
* @param sourceGeometry Source Geometry
* @return
* @throws FactoryException
* @throws TransformException
*/
private Geometry reprojectToEqualArea(CoordinateReferenceSystem sourceCRS,
Geometry sourceGeometry) throws FactoryException, TransformException {
// Reproject to the Lambert Equal Area
// Geometry center used for centering the reprojection on the Geometry(reduces distance artifacts)
Point center = sourceGeometry.getCentroid();
// Creation of the MathTransform associated to the reprojection
MathTransform transPoint = CRS.findMathTransform(sourceCRS, WGS84, true);
Point centerRP = (Point) JTS.transform(center, transPoint);
// Creation of a wkt for the selected Geometry
String wkt = PROJ_4326.replace("%LAT0%", String.valueOf(centerRP.getY()));
wkt = wkt.replace("%LON0%", String.valueOf(centerRP.getX()));
// Parsing of the selected WKT
final CoordinateReferenceSystem targetCRS = CRS.parseWKT(wkt);
// Creation of the MathTransform associated to the reprojection
MathTransform trans = CRS.findMathTransform(sourceCRS, targetCRS);
// Geometry reprojection
Geometry geoPrj;
if (!trans.isIdentity()) {
geoPrj = JTS.transform(sourceGeometry, trans);
} else {
geoPrj = sourceGeometry;
}
return geoPrj;
}
示例9: readGridcoverageImageForTile
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
/**
* Read the image of a tile from a generic geotools coverage reader.
*
* @param reader the reader, expected to be in CRS 3857.
* @param x the tile x.
* @param y the tile y.
* @param zoom the zoomlevel.
* @return the image.
* @throws IOException
*/
public static BufferedImage readGridcoverageImageForTile(AbstractGridCoverage2DReader reader, int x, int y,
int zoom, CoordinateReferenceSystem resampleCrs) throws IOException {
double north = tile2lat(y, zoom);
double south = tile2lat(y + 1, zoom);
double west = tile2lon(x, zoom);
double east = tile2lon(x + 1, zoom);
Coordinate ll = new Coordinate(west, south);
Coordinate ur = new Coordinate(east, north);
try {
CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
MathTransform transform = CRS.findMathTransform(sourceCRS, resampleCrs);
ll = JTS.transform(ll, null, transform);
ur = JTS.transform(ur, null, transform);
} catch (Exception e) {
e.printStackTrace();
}
BufferedImage image =
ImageUtilities.imageFromReader(reader, TILESIZE, TILESIZE, ll.x, ur.x, ll.y, ur.y, resampleCrs);
return image;
}
示例10: RL2NwwLayer
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
public RL2NwwLayer( RL2CoverageHandler rl2Handler, Integer tileSize ) throws Exception {
super(makeLevels(rl2Handler, tileSize));
RasterCoverage rasterCoverage = rl2Handler.getRasterCoverage();
this.layerName = rasterCoverage.coverage_name;
double w = rasterCoverage.extent_minx;
double s = rasterCoverage.extent_miny;
double e = rasterCoverage.extent_maxx;
double n = rasterCoverage.extent_maxy;
double centerX = w + (e - w) / 2.0;
double centerY = s + (n - s) / 2.0;
Coordinate centerCoordinate = new Coordinate(centerX, centerY);
CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
CoordinateReferenceSystem sourceCRS = CrsUtilities.getCrsFromSrid(rasterCoverage.srid);
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
centerCoordinateLL = JTS.transform(centerCoordinate, null, transform);
this.setUseTransparentTextures(true);
}
示例11: drawCells
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private static void drawCells( ASpatialDb db, ColorInterpolator colorInterp, PointTransformation pointTransformation,
Geometry polygon, Graphics2D gr, MathTransform data2NwwTransform, boolean doIntensity, int finalTileSize )
throws Exception {
int maxPerImage = 100000;
List<LasCell> lasCells = LasCellsTable.getLasCells(db, null, polygon, true, true, false, false, false, maxPerImage);
int size = lasCells.size();
if (size > 0) {
int jump = size / maxPerImage;
for( int i = 0; i < size; i = i + 1 + jump ) {
LasCell lasCell = lasCells.get(i);
if (lasCell.pointsCount == 0) {
continue;
}
Polygon levelPolygon = lasCell.polygon;
Geometry polygonNww = JTS.transform(levelPolygon, data2NwwTransform);
GeneralPath p = polygonToPath(pointTransformation, polygonNww, finalTileSize);
Color c = colorInterp.getColorFor(doIntensity ? lasCell.avgIntensity : lasCell.avgElev);
gr.setPaint(c);
gr.fill(p);
}
}
}
示例12: drawLevels
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private static void drawLevels( ASpatialDb db, ColorInterpolator colorInterp, PointTransformation pointTransformation,
Geometry polygon, Graphics2D gr, int lasLevelsNum, MathTransform data2NwwTransform, boolean doIntensity,
int finalTileSize ) throws Exception {
int maxPerImage = 100000;
List<LasLevel> lasLevels = LasLevelsTable.getLasLevels(db, lasLevelsNum, polygon);
int size = lasLevels.size();
if (size > 0) {
int jump = size / maxPerImage;
for( int i = 0; i < size; i = i + 1 + jump ) {
LasLevel lasLevel = lasLevels.get(i);
Polygon levelPolygon = lasLevel.polygon;
Geometry polygonNww = JTS.transform(levelPolygon, data2NwwTransform);
GeneralPath p = polygonToPath(pointTransformation, polygonNww, finalTileSize);
Color c = colorInterp.getColorFor(doIntensity ? lasLevel.avgIntensity : lasLevel.avgElev);
gr.setPaint(c);
gr.fill(p);
}
}
}
示例13: convertLonLatToEuclidean
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private static ProjectedCoordinate convertLonLatToEuclidean(
Coordinate lonlat) {
final MathTransform transform = getTransform(lonlat);
final Coordinate to = new Coordinate();
// the transform seems to swap the lat lon pairs
Coordinate latlon = new Coordinate(lonlat.y, lonlat.x);
try {
JTS.transform(latlon, to, transform);
} catch (final TransformException e) {
e.printStackTrace();
}
return new ProjectedCoordinate(transform, new Coordinate(to.y, to.x), lonlat);
}
示例14: getPointES
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
private Double getPointES(GridCoverage2D raster, Point point) {
Double result = null;
try {
DirectPosition position = JTS.toDirectPosition(point.getCoordinate(), GeometryUtils.WGS_84_CRS);
double[] resultArray = raster.evaluate(position, (double[]) null);
if (resultArray[0] != RASTER_NO_DATA_VALUE) {
result = resultArray[0];
} else {
LOGGER.debug(String.format(ES_NOT_FOUND_NO_DATA_MESSAGE, point.getX(), point.getY()));
}
} catch (PointOutsideCoverageException e) {
// Ignore the exception - if the point is outside of the raster area, the result is null
LOGGER.debug(String.format(ES_NOT_FOUND_OUTSIDE_AREA_MESSAGE, point.getX(), point.getY()));
}
return result;
}
示例15: loadRasterOpensCorrectFile
import org.geotools.geometry.jts.JTS; //导入依赖的package包/类
@Test
public void loadRasterOpensCorrectFile() throws Exception {
// Arrange
File rasterFile = new File(TEST_DATA_PATH, "raster.tif");
// Act
GridCoverage2D raster = null;
try {
raster = RasterUtils.loadRaster(rasterFile);
// Assert
double[] value1 = raster.evaluate(JTS.toDirectPosition(new Coordinate(0, 0), GeometryUtils.WGS_84_CRS), (double[]) null);
assertThat(value1[0]).isEqualTo(0.0);
double[] value2 = raster.evaluate(JTS.toDirectPosition(new Coordinate(-100, 50), GeometryUtils.WGS_84_CRS), (double[]) null);
assertThat(value2[0]).isEqualTo(0.2772243076469749);
double[] value3 = raster.evaluate(JTS.toDirectPosition(new Coordinate(75, -5), GeometryUtils.WGS_84_CRS), (double[]) null);
assertThat(value3[0]).isEqualTo(-9999.0);
} finally {
// Cleanup
RasterUtils.disposeRaster(raster);
}
}