本文整理匯總了Java中org.geotools.geometry.jts.JTS.transform方法的典型用法代碼示例。如果您正苦於以下問題:Java JTS.transform方法的具體用法?Java JTS.transform怎麽用?Java JTS.transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.geometry.jts.JTS
的用法示例。
在下文中一共展示了JTS.transform方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transform
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public Geometry transform(Geometry source, CrsTransform crsTransform) {
try {
if (crsTransform.isTransforming()) {
Geometry transformableArea = crsTransform.getTransformableGeometry();
if (null != transformableArea && !transformableArea.covers(source)) {
source = source.intersection(transformableArea);
}
return JTS.transform(source, crsTransform);
} else {
return source;
}
} catch (Exception e) { // NOSONAR typically TopologyException, TransformException or FactoryException
logEnvelopeSuggestCrsTransformInfo(crsTransform.getId(), source, e);
return createEmptyGeometryForClass(source.getClass());
}
}
示例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: 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;
}
}
示例5: 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);
}
}
}
示例6: 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);
}
示例7: 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;
}
示例8: 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);
}
示例9: 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);
}
}
}
示例10: convertLonLatToEuclidean
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
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);
}
示例11: getArea
import org.geotools.geometry.jts.JTS; //導入方法依賴的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();
}
}
示例12: extractNormalizedGeometry
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
private Optional<Geometry> extractNormalizedGeometry(SimpleFeature feature, MathTransform crsTransform) throws TransformException {
try {
Geometry geom = (Geometry) feature.getDefaultGeometry();
Geometry transformedGeom = JTS.transform(geom, crsTransform);
transformedGeom.setSRID(Subject.SRID);
return Optional.of(transformedGeom);
} catch (ProjectionException e) {
log.warn("Rejecting feature {}. You will see this if you have assertions enabled (e.g. " +
"you run with `-ea`) as GeoTools runs asserts. See source of GeotoolsDataStoreUtils for details on this. " +
"To fix this, replace `-ea` with `-ea -da:org.geotools...` in your test VM options (probably in" +
"your IDE) to disable assertions in GeoTools.", feature.getID());
return Optional.empty();
}
}
開發者ID:FutureCitiesCatapult,項目名稱:TomboloDigitalConnector,代碼行數:15,代碼來源:AbstractGeotoolsDataStoreImporter.java
示例13: wktToGeometry
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
public static Geometry wktToGeometry(String wkt,String sridXML) throws ParseException {
int srid = Integer.parseInt(sridXML.replace("https://epsg.io/", ""));
WKTReader fromText = new WKTReader(new GeometryFactory(new PrecisionModel(),srid));
Geometry geom = null;
try {
geom = fromText.read(wkt);
if( srid != 4326){
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" + srid);
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
geom = JTS.transform( geom, transform);
geom.setSRID(4326);
//VT: For some reason this transformation swapped X and Y around for EPGS:4326 vs the others
// Coordinate[] original = geom.getCoordinates();
// for(int i =0; i<original.length; i++){
// Double swapValue = original[i].x;
// original[i].x = original[i].y;
// original[i].y = swapValue;
// }
}
} catch (Exception e) {
throw new ParseException("Unable to parse and convert WKT");
}
return geom;
}
示例14: convertUTM_MGA942Geographic_EPSG4326
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
public static Geometry convertUTM_MGA942Geographic_EPSG4326(Double easting, Double northing, String zone) throws NoSuchAuthorityCodeException, FactoryException, MismatchedDimensionException, TransformException{
CoordinateReferenceSystem geographic = CRS.decode("EPSG:4326", false);
CoordinateReferenceSystem geographic2 = ReferencingFactoryFinder.getCRSAuthorityFactory(
"EPSG", null).createCoordinateReferenceSystem("4326");
CoordinateReferenceSystem utm = ReferencingFactoryFinder.getCRSAuthorityFactory(
"EPSG", null).createCoordinateReferenceSystem("283"+zone);
CoordinateOperationFactory coFactory = ReferencingFactoryFinder
.getCoordinateOperationFactory(null);
CoordinateReferenceSystem sourceCRS = utm;
CoordinateReferenceSystem targetCRS = geographic;
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate( easting, northing );
Point point = gf.createPoint( coord );
MathTransform mathTransform =CRS.findMathTransform( sourceCRS, targetCRS,true );
Geometry g2 = JTS.transform(point, mathTransform);
//VT: Flip around to correct the lat lon from the utm to geographic transformation
Coordinate[] original = g2.getCoordinates();
for(int i = 0; i < original.length; i++){
Double swapValue = original[i].x;
original[i].x = original[i].y;
original[i].y = swapValue;
}
return g2;
}
示例15: convertDoublesToPoint
import org.geotools.geometry.jts.JTS; //導入方法依賴的package包/類
private com.vividsolutions.jts.geom.Point convertDoublesToPoint(
Double x,
Double y,
CoordinateReferenceSystem sourceCRS,
CoordinateReferenceSystem targetCRS)
throws TransformException, FactoryException {
com.vividsolutions.jts.geom.GeometryFactory gf = new
com.vividsolutions.jts.geom.GeometryFactory();
com.vividsolutions.jts.geom.Coordinate coo = new com
.vividsolutions.jts.geom.Coordinate(x, y);
com.vividsolutions.jts.geom.Point p = gf.createPoint(coo);
MathTransform transform = CRS.findMathTransform(
sourceCRS, targetCRS);
return (com.vividsolutions.jts.geom.Point) JTS.transform(p, transform);
}