本文整理汇总了Java中org.geotools.referencing.CRS.findMathTransform方法的典型用法代码示例。如果您正苦于以下问题:Java CRS.findMathTransform方法的具体用法?Java CRS.findMathTransform怎么用?Java CRS.findMathTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.referencing.CRS
的用法示例。
在下文中一共展示了CRS.findMathTransform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGeoFromPixel
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Computes the map coordinates given the pixel location in the image reference
* @param xpix the pixel location in x
* @param ypix the pixel location in y
* @param outputEpsgProjection is the projection system of the result (for instance "EPSG:4326") if null use the original projection
* @return [longitude, latitude]
*
*
*/
public double[] getGeoFromPixel(double xpix, double ypix, String outputEpsgProjection) {
double[] out = new double[2];
pix2geo.transform(new double[]{xpix , ypix }, 0, out, 0, 1);
//pix2geo.transform(new double[]{xpix + m_translationX, ypix + m_translationY}, 0, out, 0, 1);
if (outputEpsgProjection != null) {
try {
double[] temp = new double[3];
CoordinateReferenceSystem crs = CRS.decode(outputEpsgProjection);
MathTransform math = CRS.findMathTransform(sourceCRS, crs);
math.transform(new double[]{out[0], out[1], 0}, 0, temp, 0, 1);
out[0] = temp[0];
out[1] = temp[1];
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
return out;
}
示例2: getPixelFromGeo
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Computes the subpixel (i.e. precision greater than integer) location of a map coordinates
* @param xgeo is the longitude
* @param ygeo is the latitude
* @param inputEpsgProjection is the projection system of (xgeo, ygeo) (for instance "EPSG:4326"). if null use the original projection
* @return [xpixel, ypixel]
*
*/
public double[] getPixelFromGeo(double xgeo, double ygeo, String inputEpsgProjection) {
double[] out = new double[]{xgeo, ygeo};
if (inputEpsgProjection != null) {
try {
double[] temp = new double[]{xgeo, ygeo, 0};
CoordinateReferenceSystem crs = CRS.decode(inputEpsgProjection);
MathTransform math = CRS.findMathTransform(crs, sourceCRS);
math.transform(temp, 0, temp, 0, 1);
out[0] = temp[0];
out[1] = temp[1];
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
geo2pix.transform(out, 0, out, 0, 1);
out[0] = out[0];
out[1] = out[1];
return out;
}
示例3: getPixelFromGeo
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
*
*/
public double[] getPixelFromGeo(double xgeo, double ygeo, String inputEpsgProjection) {
double[] out = new double[]{xgeo, ygeo};
if (inputEpsgProjection != null) {
try {
double[] temp = new double[]{xgeo, ygeo, 0};
CoordinateReferenceSystem crs = CRS.decode(inputEpsgProjection);
MathTransform math = CRS.findMathTransform(crs, sourceCRS);
math.transform(temp, 0, temp, 0, 1);
out[0] = temp[0];
out[1] = temp[1];
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
geo2pix.transform(out, 0, out, 0, 1);
return out;
}
示例4: getGeoFromPixel
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public double[] getGeoFromPixel(double xpix, double ypix, String outputEpsgProjection) {
double[] out = new double[2];
pix2geo.transform(new double[]{xpix, ypix}, 0, out, 0, 1);
if (outputEpsgProjection != null) {
try {
double[] temp = new double[3];
CoordinateReferenceSystem crs = CRS.decode(outputEpsgProjection);
MathTransform math = CRS.findMathTransform(sourceCRS, crs);
math.transform(new double[]{out[0], out[1], 0}, 0, temp, 0, 1);
out[0] = temp[0];
out[1] = temp[1];
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
return out;
}
示例5: NLSDEMTask
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public NLSDEMTask(String apiKey, URI prjFileLocation, String tiffStorage) throws URISyntaxException {
if (prjFileLocation == null)
// Fallback to EPSG3067 found within JAR
prjFileLocation = NLSDEMTask.class.getResource("EPSG3067.prj").toURI();
if (tiffStorage == null)
tiffStorage = System.getProperty("java.io.tmpdir");
Path prjFile = Paths.get(prjFileLocation);
if (!Files.isReadable(prjFile))
throw new IllegalArgumentException(
".prj file " + prjFileLocation + " cannot be read. See that it exists and is readable!");
this.sourceCRS = DefaultGeographicCRS.WGS84;
try {
PrjFileReader reader = new PrjFileReader(FileChannel.open(prjFile, StandardOpenOption.READ));
targetCRS = reader.getCoordinateReferenceSystem();
transform = CRS.findMathTransform(sourceCRS, targetCRS);
} catch (FactoryException | IOException e) {
throw new IllegalArgumentException(".prj file provided is invalid!", e);
}
this.nlsXmlClient = new NLSXMLClient(apiKey, tiffStorage);
this.tiffDownloaderService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
new NLSTiffDownloaderFactory());
}
示例6: getTransform
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Get the {@code MathTransform} to reproject data from the coordinate system of
* the {@code MapContext's} to that of the {@code MapLayer}.
*
* @return the transform or {@code null} if either the layer's coordinate system is the same
* as that of the map context, or either has a {@code null} CRS.
*/
public MathTransform getTransform() {
if (transform == null && !transformFailed && dataCRS != null) {
MapContent content = getMapContent();
if (content == null) {
throw new IllegalStateException("map context should not be null");
}
CoordinateReferenceSystem contextCRS = content.getCoordinateReferenceSystem();
try {
transform = CRS.findMathTransform(contextCRS, dataCRS, true);
} catch (Exception ex) {
LOGGER.warning("Can't transform map context to map layer CRS");
transformFailed = true;
}
}
return transform;
}
示例7: setCrs
import org.geotools.referencing.CRS; //导入方法依赖的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();
}
}
示例8: CRSTransform
import org.geotools.referencing.CRS; //导入方法依赖的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;
}
}
示例9: getCells
import org.geotools.referencing.CRS; //导入方法依赖的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();
}
示例10: reprojectToEqualArea
import org.geotools.referencing.CRS; //导入方法依赖的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;
}
示例11: getAreaSimple
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public double getAreaSimple(
Geometry polygon )
throws Exception {
Point centroid = polygon.getCentroid();
CoordinateReferenceSystem equalAreaCRS = lookupUtmCrs(
centroid.getY(),
centroid.getX());
MathTransform transform = CRS.findMathTransform(
DefaultGeographicCRS.WGS84,
equalAreaCRS,
true);
Geometry transformedPolygon = JTS.transform(
polygon,
transform);
return transformedPolygon.getArea() * SQM_2_SQKM;
}
示例12: RL2NwwLayer
import org.geotools.referencing.CRS; //导入方法依赖的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);
}
示例13: transformJTSGeometry
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
protected Geometry transformJTSGeometry(Geometry geom, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem crs) throws Exception {
final MathTransform transform = CRS.findMathTransform(sourceCRS, crs, true);
final Mutable<Boolean> anyChanged = new Mutable<Boolean>(false);
geom = (Geometry) geom.clone();
geom.apply(new CoordinateFilter() {
@Override
public void filter(Coordinate c) {
DirectPosition dpFrom = new DirectPosition2D(sourceCRS, c.x, c.y);
DirectPosition dpTo = new DirectPosition2D();
try {
transform.transform(dpFrom, dpTo);
c.x = dpTo.getOrdinate(0);
c.y = dpTo.getOrdinate(1);
anyChanged.set(true);
} catch (TransformException e) {
LOG.warn("Failed to transform point " + c, e);
}
}
});
if (anyChanged.get()) {
geom.geometryChanged();
}
return geom;
}
示例14: FeatureCollectionIterator
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public FeatureCollectionIterator(
FeatureCollection<SimpleFeatureType, SimpleFeature> features,
int sourceEpsg) {
if (features != null) {
iter = features.features();
if (sourceEpsg != targetEpsg) {
try {
CoordinateReferenceSystem targetCRS = CRS.decode(
SRS_NAMESPACE + targetEpsg, true);
CoordinateReferenceSystem sourceCRS = CRS.decode(
SRS_NAMESPACE + sourceEpsg, true);
transform = CRS.findMathTransform(sourceCRS, targetCRS,
true);
} catch (Exception e) {
LOGGER.warn("Could not detemine source and target CRS definitions. Geometry will not be indexed!");
}
}
}
}
示例15: setDefaultProjection
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public void setDefaultProjection(String epsgGeoProj){
this.defaultEpsgProjection=epsgGeoProj;
try {
sourceCRS = CRS.decode(epsgGeoProj);
defaultCrs = CRS.decode(defaultEpsgProjection);
defaultMath = CRS.findMathTransform(defaultCrs, sourceCRS);
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}