Search in sources :

Example 26 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project mkgmap by openstreetmap.

the class PrecompSeaGenerator method createTransformation.

/**
 * Retrieves the transformation that is necessary to transform the
 * data from the shape file to WGS84.
 * @param shapeCRS the projection of the shape file
 * @return the transformation ({@code null} if no transformation required)
 * @throws NoSuchAuthorityCodeException if the given projection of the shape file is not supported
 * @throws FactoryException if the given projection of the shape file is not supported
 */
private MathTransform createTransformation(String shapeCRS) throws NoSuchAuthorityCodeException, FactoryException {
    if ("WGS84".equals(shapeCRS)) {
        return null;
    }
    if ("Mercator".equals(shapeCRS)) {
        shapeCRS = "EPSG:3857";
    }
    CoordinateReferenceSystem crsInShapefile = CRS.decode(shapeCRS);
    CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
    // allow for some error due to different datums
    boolean lenient = true;
    return CRS.findMathTransform(crsInShapefile, targetCRS, lenient);
}
Also used : CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 27 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project activityinfo by bedatadriven.

the class GeometryConverter method createTransform.

private MathTransform createTransform(GeometryType type) throws FactoryException {
    CoordinateReferenceSystem sourceCrs = type.getCoordinateReferenceSystem();
    if (sourceCrs == null) {
        // if it's not WGS84, we'll soon find out as we check the geometry against the
        // country bounds
        sourceCrs = DefaultGeographicCRS.WGS84;
    }
    CoordinateReferenceSystem geoCRS = DefaultGeographicCRS.WGS84;
    // allow for some error due to different datums
    boolean lenient = true;
    return CRS.findMathTransform(sourceCrs, geoCRS, lenient);
}
Also used : CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 28 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.

the class FieldConfigBoundingBox method getBBox.

/**
 * Generates the bounding box from the ui.
 *
 * @return the b box
 */
private ReferencedEnvelope getBBox() {
    if (xMinTextField == null) {
        return null;
    }
    double minX = xMinTextField.getText().isEmpty() ? 0.0 : Double.valueOf(xMinTextField.getText());
    double maxX = xMaxTextField.getText().isEmpty() ? 0.0 : Double.valueOf(xMaxTextField.getText());
    double minY = yMinTextField.getText().isEmpty() ? 0.0 : Double.valueOf(yMinTextField.getText());
    double maxY = yMaxTextField.getText().isEmpty() ? 0.0 : Double.valueOf(yMaxTextField.getText());
    ValueComboBoxData crsDataValue = crsComboBox.getSelectedValue();
    CoordinateReferenceSystem crs = null;
    try {
        if (crsDataValue != null) {
            crs = CRS.decode(crsDataValue.getKey());
        }
    } catch (NoSuchAuthorityCodeException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (FactoryException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    ReferencedEnvelope envelope = new ReferencedEnvelope(minX, maxX, minY, maxY, crs);
    return envelope;
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData)

Example 29 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.

the class InLineFeatureModel method updateCRS.

/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();
        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);
        SimpleFeatureType newFeatureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);
        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);
            ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }
            SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType, featureList);
            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        this.fireTableStructureChanged();
        this.fireTableDataChanged();
        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
Also used : SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DataStore(org.geotools.data.DataStore) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 30 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.

the class CoordManagerTest method testGetInstance.

/**
 * Test method for {@link com.sldeditor.common.coordinate.CoordManager#getInstance()}.
 * Test method for {@link com.sldeditor.common.coordinate.CoordManager#getCRSList()}.
 * Test method for {@link com.sldeditor.common.coordinate.CoordManager#getCRSCode(org.opengis.referencing.crs.CoordinateReferenceSystem)}.
 * Test method for {@link com.sldeditor.common.coordinate.CoordManager#getWGS84()}.
 *
 * @throws NoSuchAuthorityCodeException the no such authority code exception
 * @throws FactoryException the factory exception
 */
@Test
public void testGetInstance() throws NoSuchAuthorityCodeException, FactoryException {
    CoordManager.getInstance().populateCRSList();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    List<ValueComboBoxData> crsList = CoordManager.getInstance().getCRSList();
    assertTrue(crsList.size() > 0);
    CoordinateReferenceSystem crs = CoordManager.getInstance().getCRS(null);
    assertNull(crs);
    crs = CoordManager.getInstance().getWGS84();
    assertTrue(crs != null);
    String code = CoordManager.getInstance().getCRSCode(null);
    assertTrue(code.compareTo("") == 0);
    code = CoordManager.getInstance().getCRSCode(crs);
    assertTrue(code.compareTo("EPSG:4326") == 0);
    String projectedCRSCode = "EPSG:27700";
    CoordinateReferenceSystem projectedCRS = CRS.decode(projectedCRSCode);
    code = CoordManager.getInstance().getCRSCode(projectedCRS);
    assertTrue(code.compareTo(projectedCRSCode) == 0);
}
Also used : CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) Test(org.junit.Test)

Aggregations

CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)210 Test (org.junit.Test)80 MathTransform (org.opengis.referencing.operation.MathTransform)32 FactoryException (org.opengis.referencing.FactoryException)25 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)24 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)23 Geometry (com.vividsolutions.jts.geom.Geometry)21 TransformException (org.opengis.referencing.operation.TransformException)21 DependsOnMethod (org.apache.sis.test.DependsOnMethod)19 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)13 Geometry (org.locationtech.jts.geom.Geometry)11 FactoryException (org.opengis.util.FactoryException)11 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 DirectPosition (org.opengis.geometry.DirectPosition)9 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)9 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)9 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)9 ArrayList (java.util.ArrayList)8 GeometryType (org.opengis.feature.type.GeometryType)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)7