本文整理汇总了Java中org.osgeo.proj4j.CoordinateTransform类的典型用法代码示例。如果您正苦于以下问题:Java CoordinateTransform类的具体用法?Java CoordinateTransform怎么用?Java CoordinateTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CoordinateTransform类属于org.osgeo.proj4j包,在下文中一共展示了CoordinateTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromHK80toWGS84
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
private static Pair<Double, Double> fromHK80toWGS84(Pair<Double, Double> pair) {
try {
// reference: blog.tiger-workshop.com/hk1980-grid-to-wgs84/
CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
CRSFactory csFactory = new CRSFactory();
CoordinateReferenceSystem HK80 = csFactory.createFromParameters("EPSG:2326", "+proj=tmerc +lat_0=22.31213333333334 +lon_0=114.1785555555556 +k=1 +x_0=836694.05 +y_0=819069.8 +ellps=intl +towgs84=-162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425 +units=m +no_defs");
CoordinateReferenceSystem WGS84 = csFactory.createFromParameters("WGS84", "+proj=longlat +datum=WGS84 +no_defs");
CoordinateTransform trans = ctFactory.createTransform(HK80, WGS84);
ProjCoordinate p = new ProjCoordinate();
ProjCoordinate p2 = new ProjCoordinate();
p.x = pair.first;
p.y = pair.second;
trans.transform(p, p2);
return new Pair<>(p2.x, p2.y);
} catch (IllegalStateException e) {
Timber.e(e);
}
return null;
}
示例2: transform
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
/**
* Convert geometry to different coordinate system given the source/target
* proj4 parameters. Presumably these were pulled from SPATIAL_REF_SYS.
*
* @param geom
* @param srcParams
* @param tgtParams
* @return
* @throws FunctionExecutionException
*/
public static Geometry transform(Geometry geom,
String srcParams,
String tgtParams)
throws FunctionExecutionException {
CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
CRSFactory crsFactory = new CRSFactory();
CoordinateReferenceSystem srcCrs = crsFactory.createFromParameters(null, srcParams);
CoordinateReferenceSystem tgtCrs = crsFactory.createFromParameters(null, tgtParams);
CoordinateTransform coordTransform = ctFactory.createTransform(srcCrs, tgtCrs);
return transformGeometry(coordTransform, geom);
}
示例3: transformGeometry
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformGeometry(CoordinateTransform ct,
Geometry geom)
throws FunctionExecutionException {
if (geom instanceof Polygon) {
return transformPolygon(ct, (Polygon) geom);
} else if (geom instanceof Point) {
return transformPoint(ct, (Point) geom);
} else if (geom instanceof LinearRing) {
return transformLinearRing(ct, (LinearRing) geom);
} else if (geom instanceof LineString) {
return transformLineString(ct, (LineString) geom);
} else if (geom instanceof MultiPolygon) {
return transformMultiPolygon(ct, (MultiPolygon) geom);
} else if (geom instanceof MultiPoint) {
return transformMultiPoint(ct, (MultiPoint) geom);
} else if (geom instanceof MultiLineString) {
return transformMultiLineString(ct, (MultiLineString) geom);
} else if (geom instanceof GeometryCollection) {
return transformGeometryCollection(ct, (GeometryCollection) geom);
} else {
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31164, geom.getGeometryType()));
}
}
示例4: transform
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
/**
* Transforms the referenced envelope to the specified coordinate reference system
* using the specified amount of points.
* <p>
* This method can handle the case where the envelope contains the North or South pole,
* or when it cross the +180° longitude.
*
* @param targetCRS The target coordinate reference system.
* @param lenient {@code true} if datum shift should be applied even if there is
* insuffisient information. Otherwise (if {@code false}), an
* exception is thrown in such case.
* @param numPointsForTransformation The number of points to use for sampling the envelope.
* @return The transformed envelope.
* @throws FactoryException if the math transform can't be determined.
* @throws TransformException if at least one coordinate can't be transformed.
*
* @see CRS#transform(CoordinateOperation, org.opengis.geometry.Envelope)
*
* @since 2.3
*/
public ReferencedEnvelope transform(final CoordinateReferenceSystem targetCRS, final int numPointsForTransformation){
if( this.crs == null ){
// really this is a the code that created this ReferencedEnvelope
throw new NullPointerException("Unable to transform referenced envelope, crs has not yet been provided.");
}
/*
* Gets a first estimation using an algorithm capable to take singularity in account
* (North pole, South pole, 180° longitude). We will expand this initial box later.
*/
CoordinateTransformFactory txFactory = new CoordinateTransformFactory();
CoordinateTransform tx = txFactory.createTransform(crs, targetCRS);
Envelope transformed = Proj.reproject(envelope, crs, targetCRS);
/*
* Now expands the box using the usual utility methods.
*/
//JTS.transform(this, target, transform, numPointsForTransformation);
// -->
Envelope expanded = transform(this.envelope,transformed, tx, numPointsForTransformation);
return new ReferencedEnvelope(expanded, targetCRS);
}
示例5: latlon2twd97
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
public static ProjCoordinate latlon2twd97(LatLng latLng) {
CoordinateReferenceSystem crs1 = mCsFactory.createFromParameters(EPSG_WGS84, FUNC_WGS84);
CoordinateReferenceSystem crs2 = mCsFactory.createFromParameters(EPSG_TWD97, FUNC_TWD97);
CoordinateTransform trans = mCtFactory.createTransform(crs1, crs2);
ProjCoordinate p1 = new ProjCoordinate();
ProjCoordinate p2 = new ProjCoordinate();
p1.x = latLng.longitude;
p1.y = latLng.latitude;
trans.transform(p1, p2);
return p2;
}
示例6: latlon2twd67
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
public static ProjCoordinate latlon2twd67(LatLng latLng) {
CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
CRSFactory csFactory = new CRSFactory();
CoordinateReferenceSystem crs1 = csFactory.createFromParameters(EPSG_WGS84, FUNC_WGS84);
CoordinateReferenceSystem crs2 = csFactory.createFromParameters(EPSG_TWD67, FUNC_TWD67);
CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);
ProjCoordinate p1 = new ProjCoordinate();
ProjCoordinate p2 = new ProjCoordinate();
p1.x = latLng.longitude;
p1.y = latLng.latitude;
trans.transform(p1, p2);
return p2;
}
示例7: transformCoordinates
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static ProjCoordinate[] transformCoordinates(CoordinateTransform ct,
ProjCoordinate[] in) {
ProjCoordinate[] out = new ProjCoordinate[in.length];
for (int i = 0; i < in.length; ++i) {
out[i] = ct.transform(in[i], new ProjCoordinate());
}
return out;
}
示例8: transformMultiPolygon
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformMultiPolygon(CoordinateTransform ct,
MultiPolygon multiPolygon) {
Polygon[] polygon = new Polygon[multiPolygon.getNumGeometries()];
for (int i = 0; i < polygon.length; ++i) {
polygon[i] = multiPolygon.getFactory()
.createPolygon(transformCoordinates(ct,
multiPolygon.getGeometryN(i).getCoordinates()));
}
return multiPolygon.getFactory().createMultiPolygon(polygon);
}
示例9: transformMultiLineString
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformMultiLineString(CoordinateTransform ct,
MultiLineString multiLineString) {
LineString[] lineString = new LineString[multiLineString.getNumGeometries()];
for (int i = 0; i < lineString.length; ++i) {
lineString[i] = multiLineString.getFactory()
.createLineString(transformCoordinates(ct,
multiLineString.getGeometryN(i).getCoordinates()));
}
return multiLineString.getFactory().createMultiLineString(lineString);
}
示例10: transformGeometryCollection
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformGeometryCollection(CoordinateTransform ct,
GeometryCollection geometryCollection)
throws FunctionExecutionException {
Geometry[] geometry = new Geometry[geometryCollection.getNumGeometries()];
for (int i = 0; i < geometry.length; ++i) {
geometry[i] = transformGeometry(ct, geometryCollection.getGeometryN(i));
}
return geometryCollection.getFactory().createGeometryCollection(geometry);
}
示例11: transform
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
/**
* creates a CoordinateTransform object from two crs
* @param from the source crs
* @param to the target crs
* @return the coordinateTransform object which can be used to transform geometries
*/
public static CoordinateTransform transform(CoordinateReferenceSystem from, CoordinateReferenceSystem to) {
CoordinateTransform tx = txFactory.createTransform(from, to);
if (tx == null) {
throw new IllegalArgumentException("Unable to find transform from " + from + " to " + to);
}
return tx;
}
示例12: transformPolygon
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Polygon transformPolygon(CoordinateTransform ct,
Polygon polygon) {
return polygon.getFactory().createPolygon(transformCoordinates(ct, polygon.getCoordinates()));
}
示例13: transformPoint
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformPoint(CoordinateTransform ct,
Point point) {
return point.getFactory().createPoint(transformCoordinates(ct, point.getCoordinates())[0]);
}
示例14: transformLinearRing
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformLinearRing(CoordinateTransform ct,
LinearRing linearRing) {
return linearRing.getFactory().createLinearRing(transformCoordinates(ct, linearRing.getCoordinates()));
}
示例15: transformLineString
import org.osgeo.proj4j.CoordinateTransform; //导入依赖的package包/类
protected static Geometry transformLineString(CoordinateTransform ct,
LineString lineString) {
return lineString.getFactory().createLineString(transformCoordinates(ct, lineString.getCoordinates()));
}