本文整理匯總了Java中org.geotools.referencing.CRS.lookupEpsgCode方法的典型用法代碼示例。如果您正苦於以下問題:Java CRS.lookupEpsgCode方法的具體用法?Java CRS.lookupEpsgCode怎麽用?Java CRS.lookupEpsgCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.referencing.CRS
的用法示例。
在下文中一共展示了CRS.lookupEpsgCode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCodeFromCrs
import org.geotools.referencing.CRS; //導入方法依賴的package包/類
/**
* Get the code from a {@link CoordinateReferenceSystem}.
*
* @param crs the crs to get the code from.
*
* @return the code, that can be used with {@link CRS#decode(String)} to recreate the crs.
*
* @throws Exception
*/
public static String getCodeFromCrs( CoordinateReferenceSystem crs ) throws Exception {
String code = null;
try {
Integer epsg = CRS.lookupEpsgCode(crs, true);
code = "EPSG:" + epsg; //$NON-NLS-1$
} catch (Exception e) {
// try non epsg
code = CRS.lookupIdentifier(crs, true);
}
return code;
}
示例2: createFeatureList
import org.geotools.referencing.CRS; //導入方法依賴的package包/類
/**
* Create list of {@link SimpleFeature} based on a given {@link SimpleFeatureCollection}
* - for geometries that are not <code>null</code>
* - for new before constructed feature type
*
* @param featureCollection {@link FeatureCollection} to be transformed
* @return {@link SimpleFeature} list
* @throws IOException
* @throws FactoryException
*/
public List<SimpleFeature> createFeatureList(SimpleFeatureCollection featureCollection) throws IOException, FactoryException{
ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
SimpleFeatureIterator sfi = featureCollection.features();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(this.sft_database);
int sridDecoded = -1;
while (sfi.hasNext()){
SimpleFeature sd = sfi.next();
if (sd == null){
LOG.warn("SimpleFeature is null => ignored");
continue;
}
String id = sd.getID();
for (String oldKey : this.hashMapAttributeNamesOrig_After.keySet()){
String newKey = this.hashMapAttributeNamesOrig_After.get(oldKey);
if (! newKey.equalsIgnoreCase("the_geom")){
Object objCurrent = sd.getAttribute(oldKey);
if (objCurrent != null){
featureBuilder.set(newKey, objCurrent);
}else{
LOG.warn("Attribute (old key: " + oldKey + ") null / not found => ignored");
continue;
}
}else{
Geometry gOld = (Geometry) sd.getDefaultGeometry();
if (gOld == null){
LOG.warn("Geometry of feature " + sd + " is null / not found => feature ignored");
continue;
}
// Check if SRID is set
if (gOld.getSRID() == 0){
if (sridDecoded == -1){
Integer srid = CRS.lookupEpsgCode(this.sft_original
.getCoordinateReferenceSystem(), true);
if (srid != null){
sridDecoded = srid.intValue();
}else{
assert(DEFAULT_SRID > 0);
sridDecoded = DEFAULT_SRID;
}
}
gOld.setSRID(sridDecoded);
}
featureBuilder.set(newKey, gOld);
}
}
SimpleFeature featureNew = featureBuilder.buildFeature(id);
featureList.add(featureNew);
}
sfi.close();
return featureList;
}
示例3: finalizeWrite
import org.geotools.referencing.CRS; //導入方法依賴的package包/類
private void finalizeWrite() throws IOException {
Product sourceProduct = getSourceProduct();
final int numBands = sourceProduct.getNumBands();
RenderedImage writeImage;
if (numBands > 1) {
final ParameterBlock parameterBlock = new ParameterBlock();
for (int i = 0; i < numBands; i++) {
parameterBlock.setSource(processedBands.get(sourceProduct.getBandAt(i)), i);
}
writeImage = JAI.create("bandmerge", parameterBlock, null);
} else {
writeImage = processedBands.get(sourceProduct.getBandAt(0));
}
IIOImage outputImage = new IIOImage(writeImage, null, null);
final GeoCoding geoCoding = sourceProduct.getSceneGeoCoding();
final int width = sourceProduct.getSceneRasterWidth();
final int height = sourceProduct.getSceneRasterHeight();
JP2ImageWriter imageWriter = new JP2ImageWriter();
try {
imageWriter.setOutput(outputFile);
imageWriter.setNumberResolution(width <= 2048 && height <= 2048 ? 1 : (int) (Math.log(Math.max(width, height) / 512) / Math.log(2)) + 2);
if (geoCoding != null) {
if (geoCoding instanceof CrsGeoCoding) {
try {
final Integer epsgCode = CRS.lookupEpsgCode(geoCoding.getMapCRS(), true);
GmlRectifiedGrid rectifiedGrid = new GmlRectifiedGrid();
rectifiedGrid.setEpsgNumber(epsgCode);
final AffineTransform transform = sourceProduct.getBandAt(0).getSourceImage().getModel().getImageToModelTransform(0);
rectifiedGrid.setOrigin(new Point2D.Double(transform.getTranslateX(),
transform.getTranslateY()));
rectifiedGrid.setGridEnvelope(new GmlEnvelope<>(0, 0, width, height, "GridEnvelope"));
rectifiedGrid.setOffsetVectorX(new Point2D.Double(transform.getScaleX(), 0));
rectifiedGrid.setOffsetVectorY(new Point2D.Double(0, transform.getScaleY()));
this.metadata.setRectifiedGrid(rectifiedGrid);
} catch (Exception e) {
e.printStackTrace();
}
} else {
GmlEnvelope<Double> gmlEnvelope = new GmlEnvelope<>(geoCoding.getGeoPos(new PixelPos(0, 0), null).getLat(),
geoCoding.getGeoPos(new PixelPos(0, 0), null).getLon(),
geoCoding.getGeoPos(new PixelPos(width - 1, height - 1), null).getLat(),
geoCoding.getGeoPos(new PixelPos(width - 1, height - 1), null).getLon(),
"Envelope");
gmlEnvelope.setPolygonCorners(geoCoding.getGeoPos(new PixelPos(0, 0), null).getLat(),
geoCoding.getGeoPos(new PixelPos(0, 0), null).getLon(),
geoCoding.getGeoPos(new PixelPos(width, 0), null).getLat(),
geoCoding.getGeoPos(new PixelPos(width, 0), null).getLon(),
geoCoding.getGeoPos(new PixelPos(width, height), null).getLat(),
geoCoding.getGeoPos(new PixelPos(width, height), null).getLon(),
geoCoding.getGeoPos(new PixelPos(0, height), null).getLat(),
geoCoding.getGeoPos(new PixelPos(0, height), null).getLon());
gmlEnvelope.setPolygonUse(true);
this.metadata.setEnvelope(gmlEnvelope);
}
final JP2Metadata jp2Metadata = new JP2Metadata(null, this.metadata);
imageWriter.write(jp2Metadata, outputImage, null);
} else {
imageWriter.write(null, outputImage, null);
}
} finally {
processedCount.set(0);
processedBands.clear();
imageWriter.dispose();
}
}