Java Code Examples for org.opengis.referencing.crs.CoordinateReferenceSystem#toWKT()

The following examples show how to use org.opengis.referencing.crs.CoordinateReferenceSystem#toWKT() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MosaicMapProjectionPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private String convertToWkt(CoordinateReferenceSystem crs) {
    // according to GeoTools it is better to use to String or the Formattable directly
    // https://osgeo-org.atlassian.net/browse/GEOS-4746
    // But first try toWKT(), there must be a reason for being strict in this method.
    try {
        return crs.toWKT();
    } catch (UnformattableObjectException e) {
        SystemUtils.LOG.log(Level.WARNING, "Could not strictly convert CRS to WKT. " +
                "Used lenient method instead.", e);
        return crs.toString();
    }
}
 
Example 2
Source File: ImportTrackAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(Reader reader, GeoCoding geoCoding) throws IOException {
    CsvReader csvReader = new CsvReader(reader, new char[]{'\t', ' '}, true, "#");
    SimpleFeatureType trackFeatureType = createTrackFeatureType(geoCoding);
    ListFeatureCollection featureCollection = new ListFeatureCollection(trackFeatureType);
    double[] record;
    int pointIndex = 0;
    while ((record = csvReader.readDoubleRecord()) != null) {
        if (record.length < 3) {
            throw new IOException("Illegal track file format.\n" +
                                          "Expecting tab-separated lines containing 3 values: lat, lon, data.");
        }

        float lat = (float) record[0];
        float lon = (float) record[1];
        double data = record[2];

        final SimpleFeature feature = createFeature(trackFeatureType, geoCoding, pointIndex, lat, lon, data);
        if (feature != null) {
            featureCollection.add(feature);
        }

        pointIndex++;
    }

    if (featureCollection.isEmpty()) {
        throw new IOException("No track point found or all of them are located outside the scene boundaries.");
    }

    final CoordinateReferenceSystem mapCRS = geoCoding.getMapCRS();
    if (!mapCRS.equals(DefaultGeographicCRS.WGS84)) {
        try {
            transformFeatureCollection(featureCollection, mapCRS);
        } catch (TransformException e) {
            throw new IOException("Cannot transform the ship track onto CRS '" + mapCRS.toWKT() + "'.", e);
        }
    }

    return featureCollection;
}
 
Example 3
Source File: FileIterator.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    if (pCode != null) {
        CoordinateReferenceSystem crs = CrsUtilities.getCrsFromEpsg(pCode);
        prjWkt = crs.toWKT();
    }

    if (filesList == null) {
        filesList = new ArrayList<File>();
        pathsList = new ArrayList<String>();

        new FileTraversal(fileFilter){
            public void onFile( final File f ) {
                if (pRegex == null) {
                    filesList.add(f);
                    pathsList.add(f.getAbsolutePath());
                } else {
                    if (f.getName().matches(".*" + pRegex + ".*")) { //$NON-NLS-1$//$NON-NLS-2$
                        filesList.add(f);
                        pathsList.add(f.getAbsolutePath());
                    }
                }
            }
        }.traverse(new File(inFolder));

        if (prjWkt != null) {
            for( File file : filesList ) {
                String nameWithoutExtention = FileUtilities.getNameWithoutExtention(file);
                if (nameWithoutExtention != null) {
                    File prjFile = new File(file.getParentFile(), nameWithoutExtention + ".prj"); //$NON-NLS-1$
                    if (!prjFile.exists()) {
                        // create it
                        FileUtilities.writeFile(prjWkt, prjFile);
                    }
                }
            }
        }

    }

    if (filesList.size() > fileIndex)
        outCurrentfile = filesList.get(fileIndex).getAbsolutePath();

    if (fileIndex == filesList.size() - 1) {
        doProcess = false;
    }
    fileIndex++;

}
 
Example 4
Source File: OmsFileIterator.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    if (pCode != null) {
        CoordinateReferenceSystem crs = CrsUtilities.getCrsFromEpsg(pCode, null);
        prjWkt = crs.toWKT();
    }

    if (filesList == null) {
        filesList = new ArrayList<File>();
        pathsList = new ArrayList<String>();

        new FileTraversal(fileFilter){
            public void onFile( final File f ) {
                if (pRegex == null) {
                    filesList.add(f);
                    pathsList.add(f.getAbsolutePath());
                } else {
                    if (f.getName().matches(".*" + pRegex + ".*")) { //$NON-NLS-1$//$NON-NLS-2$
                        filesList.add(f);
                        pathsList.add(f.getAbsolutePath());
                    }
                }
            }
        }.traverse(new File(inFolder));

        if (prjWkt != null) {
            for( File file : filesList ) {
                String nameWithoutExtention = FileUtilities.getNameWithoutExtention(file);
                if (nameWithoutExtention != null) {
                    File prjFile = new File(file.getParentFile(), nameWithoutExtention + ".prj"); //$NON-NLS-1$
                    if (!prjFile.exists()) {
                        // create it
                        FileUtilities.writeFile(prjWkt, prjFile);
                    }
                }
            }
        }

    }

    if (filesList.size() > fileIndex)
        outCurrentfile = filesList.get(fileIndex).getAbsolutePath();

    if (fileIndex == filesList.size() - 1) {
        doProcess = false;
    }
    fileIndex++;

}