本文整理匯總了Java中org.geotools.referencing.CRS類的典型用法代碼示例。如果您正苦於以下問題:Java CRS類的具體用法?Java CRS怎麽用?Java CRS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CRS類屬於org.geotools.referencing包,在下文中一共展示了CRS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: expandBounds
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
* Expands inBounds by multiplying min of inBounds.getWidth and inBounds.getHeight times percent
*
* @param inBounds
* @param percent
* @return
*/
public static Bounds expandBounds(Bounds inBounds, String inCRS, double percent) {
try {
double ulx = inBounds.getLeft();
double uly = inBounds.getTop();
double lrx = inBounds.getRight();
double lry = inBounds.getBottom();
CoordinateReferenceSystem theCRS = CRS.decode(inCRS);
ReferencedEnvelope re = new ReferencedEnvelope(ulx, lrx, lry, uly, theCRS);
double expandBy = Math.min(re.getHeight(), re.getWidth()) * percent;
re.expandBy(expandBy);
return getBounds(re.toBounds(theCRS));
} catch (Exception e) {
}
return null;
}
示例2: execute
import org.geotools.referencing.CRS; //導入依賴的package包/類
@DescribeResult(name = "result", description = "Clipped feature collection")
public SimpleFeatureCollection execute(
@DescribeParameter(name = "features", description = "Input feature collection") SimpleFeatureCollection features,
@DescribeParameter(name = "clip", description = "Geometry to use for clipping (in same CRS as input features)") Geometry clip,
@DescribeParameter(name = "preserveZ", min=0,description = "Attempt to preserve Z values from the original geometry (interpolate value for new points)") Boolean preserveZ)
throws ProcessException {
// only get the geometries in the bbox of the clip
Envelope box = clip.getEnvelopeInternal();
String srs = null;
if(features.getSchema().getCoordinateReferenceSystem() != null) {
srs = CRS.toSRS(features.getSchema().getCoordinateReferenceSystem());
}
BBOX bboxFilter = ff.bbox("", box.getMinX(), box.getMinY(), box.getMaxX(), box.getMaxY(), srs);
// default value for preserve Z
if(preserveZ == null) {
preserveZ = false;
}
// return dynamic collection clipping geometries on the fly
return new ClippingFeatureCollection(features.subCollection(bboxFilter), clip, preserveZ);
}
示例3: parse
import org.geotools.referencing.CRS; //導入依賴的package包/類
@Override
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
Envelope envelope = (Envelope) super.parse(instance, node, value);
// handle the box CRS
CoordinateReferenceSystem crs = this.crs;
if (node.hasAttribute("srsName")) {
URI srs = (URI) node.getAttributeValue("srsName");
crs = CRS.decode(srs.toString());
}
if(crs != null) {
return ReferencedEnvelope.create(envelope, crs);
} else {
return envelope;
}
}
示例4: RasterizedSpatialiteLasLayer
import org.geotools.referencing.CRS; //導入依賴的package包/類
public RasterizedSpatialiteLasLayer( String title, ASpatialDb db, Integer tileSize, boolean transparentBackground,
boolean doIntensity ) throws Exception {
super(makeLevels(title, tileSize, transparentBackground, db, doIntensity));
String plus = doIntensity ? INTENSITY : ELEVATION;
this.layerName = title + " " + plus;
this.setUseTransparentTextures(true);
try {
Envelope tableBounds = db.getTableBounds(LasSourcesTable.TABLENAME);
GeometryColumn spatialiteGeometryColumns = db.getGeometryColumnsForTable(LasCellsTable.TABLENAME);
CoordinateReferenceSystem dataCrs = CRS.decode("EPSG:" + spatialiteGeometryColumns.srid);
CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
ReferencedEnvelope env = new ReferencedEnvelope(tableBounds, dataCrs);
ReferencedEnvelope envLL = env.transform(targetCRS, true);
centre = envLL.centre();
} catch (Exception e) {
e.printStackTrace();
centre = CrsUtilities.WORLD.centre();
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: merge
import org.geotools.referencing.CRS; //導入依賴的package包/類
private Optional<ReferencedEnvelope> merge(final ReferencedEnvelope oldEnv,
final Collection<ReferencedEnvelope> dirtyList) {
final CoordinateReferenceSystem declaredCrs = oldEnv.getCoordinateReferenceSystem();
return dirtyList.stream()
.map(env->{
if(env instanceof ReferencedEnvelope3D) {
return new ReferencedEnvelope(env, CRS.getHorizontalCRS(env.getCoordinateReferenceSystem()));
} else {
return env;
}
})
.map(env->{
try {
return env.transform(declaredCrs, true, 1000);
} catch (TransformException | FactoryException e) {
throw new RuntimeException("Error while merging bounding boxes",e);
}
})
.reduce((env1, env2)->{ReferencedEnvelope x = new ReferencedEnvelope(env1); x.expandToInclude(env2); return x;});
}
示例10: getDeclaredCrs
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
* Returns the declared CRS given the native CRS and the request WFS version
*
* @param nativeCRS
* @param wfsVersion
*
*/
public static CoordinateReferenceSystem getDeclaredCrs(CoordinateReferenceSystem nativeCRS,
String wfsVersion) {
try {
if(nativeCRS == null)
return null;
if (wfsVersion.equals("1.0.0")) {
return nativeCRS;
} else {
String code = GML2EncodingUtils.epsgCode(nativeCRS);
//it's possible that we can't do the CRS -> code -> CRS conversion...so we'll just return what we have
if (code == null) return nativeCRS;
return CRS.decode("urn:x-ogc:def:crs:EPSG:6.11.2:" + code);
}
} catch (Exception e) {
throw new WFSException("We have had issues trying to flip axis of " + nativeCRS, e);
}
}
示例11: toShapeFile
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
* write a shapefile representing the grid in a coordinate ref system ex :
* "EPSG:2975" -> RGR92, "EPSG:2154" -> L93, "EPSG:4326" -> WGS84
*
* @param fileName
* @param epsg
*/
public void toShapeFile(String fileName, String epsg) {
FT_FeatureCollection<IFeature> pop = new FT_FeatureCollection<>();
System.out.println("writing..." + fileName);
for (int i = 0; i < nbRows(); ++i)
for (int j = 0; j < nbCols(); ++j)
pop.add(new DefaultFeature(tiles[i][j]));
CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);
CoordinateReferenceSystem crs = null;
try {
crs = factory.createCoordinateReferenceSystem(epsg);
} catch (FactoryException e) {
e.printStackTrace();
}
ShapefileWriter.write(pop, fileName, crs);
System.out.println("writing done");
}
示例12: compareCarteRecale
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
*
* @param reseauRecale1
* @param reseauRecale2
* @throws Exception
*/
private void compareCarteRecale(CarteTopo reseauRecale1, CarteTopo reseauRecale2) throws Exception {
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
GML encode = new GML(Version.WFS1_0);
encode.setNamespace("geotools", "http://geotools.org");
// Arcs recales du reseau 1
SimpleFeatureCollection arcs1 = GeOxygeneGeoToolsTypes.convert2FeatureCollection(reseauRecale1.getPopArcs(), sourceCRS);
ByteArrayOutputStream output1 = new ByteArrayOutputStream();
encode.encode(output1, arcs1);
// Arcs recales du reseau 2
SimpleFeatureCollection arcs2 = GeOxygeneGeoToolsTypes.convert2FeatureCollection(reseauRecale2.getPopArcs(), sourceCRS);
ByteArrayOutputStream output2 = new ByteArrayOutputStream();
encode.encode(output2, arcs2);
// On compare : est-ce que le XML est comparable ????
assertXMLEqual(output1.toString(), output2.toString());
}
示例13: initialise
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
* Initialise the WKTParser object.
*/
private static void initialise() {
Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);
wktParser = new WKTParser(geometryFactory, primitiveFactory, positionFactory,
aggregateFactory);
wktTypeList.add(new WKTType(WKT_POINT, false, 1, "Point", false, false));
wktTypeList.add(new WKTType(WKT_MULTIPOINT, true, 1, "Point", true, false));
wktTypeList.add(new WKTType(WKT_LINESTRING, false, 2, "Line", false, false));
wktTypeList.add(new WKTType("LINEARRING", false, 2, "Line", false, false));
wktTypeList.add(new WKTType(WKT_MULTILINESTRING, true, 2, "Line", true, false));
wktTypeList.add(new WKTType(WKT_POLYGON, false, -1, "Polygon", false, true));
wktTypeList.add(new WKTType(WKT_MULTIPOLYGON, true, -1, "Polygon", true, true));
for (WKTType wkyType : wktTypeList) {
wktTypeMap.put(wkyType.getName(), wkyType);
}
}
示例14: decode
import org.geotools.referencing.CRS; //導入依賴的package包/類
/**
* Decodes a given code to a {@link org.opengis.referencing.crs.CompoundCRS}
* @param code the code
* @return the compound CRS
* @throws FactoryException if the code does not represent a compound CRS
* or if one of its components could not be decoded
*/
public static CoordinateReferenceSystem decode(String code) throws FactoryException {
code = code.trim();
if (!isCompound(code)) {
throw new NoSuchAuthorityCodeException("No compound CRS", AUTHORITY, code);
}
code = code.substring(PREFIX.length());
String[] parts = code.split(",");
CoordinateReferenceSystem[] crss = new CoordinateReferenceSystem[parts.length];
for (int i = 0; i < crss.length; ++i) {
crss[i] = CRS.decode(AUTHORITY + ":" + parts[i].trim());
}
return new DefaultCompoundCRS("", crss);
}
示例15: setExtend
import org.geotools.referencing.CRS; //導入依賴的package包/類
private void setExtend(Double x1, Double x2, Double y1, Double y2, String
crs) {
CoordinateReferenceSystem coordinateReferenceSystem = null;
try {
coordinateReferenceSystem = CRS.decode(crs);
ReferencedEnvelope initExtend =
new ReferencedEnvelope(x1,
x2,
y1,
y2, coordinateReferenceSystem);
setExtend(initExtend);
} catch (FactoryException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}