Search in sources :

Example 1 with NoSuchAuthorityCodeException

use of org.opengis.referencing.NoSuchAuthorityCodeException in project hale by halestudio.

the class WKTPreferencesCRSFactory method createCoordinateReferenceSystem.

/**
 * @see CRSAuthorityFactory#createCoordinateReferenceSystem(String)
 */
@Override
public synchronized CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException {
    if (code == null) {
        return null;
    }
    if (!code.startsWith(AUTHORITY_PREFIX)) {
        throw new NoSuchAuthorityCodeException("This factory only understands EPSG codes", AUTHORITY, // $NON-NLS-1$
        code);
    }
    final String epsgNumber = code.substring(code.indexOf(':') + 1).trim();
    if (cache.containsKey(epsgNumber)) {
        CoordinateReferenceSystem value = cache.get(epsgNumber);
        if (value != null) {
            // CRS was already created
            return value;
        }
    }
    try {
        node.sync();
    } catch (BackingStoreException e) {
        // $NON-NLS-1$
        _log.warn("Error synchronizing preferences", e);
    }
    String wkt = node.get(epsgNumber, null);
    if (wkt == null) {
        // $NON-NLS-1$
        throw new NoSuchAuthorityCodeException("Unknown EPSG code", AUTHORITY, code);
    }
    if (wkt.indexOf(epsgNumber) == -1) {
        wkt = wkt.trim();
        wkt = wkt.substring(0, wkt.length() - 1);
        // $NON-NLS-1$ //$NON-NLS-2$
        wkt += ",AUTHORITY[\"EPSG\",\"" + epsgNumber + "\"]]";
        // $NON-NLS-1$ //$NON-NLS-2$
        _log.warn("EPSG:" + epsgNumber + " lacks a proper identifying authority in its Well-Known Text. It is being added programmatically.");
    }
    try {
        CoordinateReferenceSystem crs = crsFactory.createFromWKT(wkt);
        cache.put(epsgNumber, crs);
        return crs;
    } catch (FactoryException fex) {
        throw fex;
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) FactoryException(org.opengis.referencing.FactoryException) BackingStoreException(java.util.prefs.BackingStoreException) InternationalString(org.opengis.util.InternationalString) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 2 with NoSuchAuthorityCodeException

use of org.opengis.referencing.NoSuchAuthorityCodeException in project GeoGig by boundlessgeo.

the class FormatCommonV2 method writePropertyType.

private static void writePropertyType(PropertyType type, DataOutput data) throws IOException {
    writeName(type.getName(), data);
    data.writeByte(FieldType.forBinding(type.getBinding()).getTag());
    if (type instanceof GeometryType) {
        GeometryType gType = (GeometryType) type;
        CoordinateReferenceSystem crs = gType.getCoordinateReferenceSystem();
        String srsName;
        if (crs == null) {
            srsName = "urn:ogc:def:crs:EPSG::0";
        } else {
            final boolean longitudeFirst = CRS.getAxisOrder(crs, false) == AxisOrder.EAST_NORTH;
            final boolean codeOnly = true;
            String crsCode = CRS.toSRS(crs, codeOnly);
            if (crsCode != null) {
                srsName = (longitudeFirst ? "EPSG:" : "urn:ogc:def:crs:EPSG::") + crsCode;
                // able to decode it later. If not, we will use WKT instead
                try {
                    CRS.decode(srsName, longitudeFirst);
                } catch (NoSuchAuthorityCodeException e) {
                    srsName = null;
                } catch (FactoryException e) {
                    srsName = null;
                }
            } else {
                srsName = null;
            }
        }
        if (srsName != null) {
            data.writeBoolean(true);
            data.writeUTF(srsName);
        } else {
            final String wkt;
            if (crs instanceof Formattable) {
                wkt = ((Formattable) crs).toWKT(Formattable.SINGLE_LINE);
            } else {
                wkt = crs.toWKT();
            }
            data.writeBoolean(false);
            data.writeUTF(wkt);
        }
    }
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Integer.toBinaryString(java.lang.Integer.toBinaryString) Formattable(org.geotools.referencing.wkt.Formattable)

Example 3 with NoSuchAuthorityCodeException

use of org.opengis.referencing.NoSuchAuthorityCodeException 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 4 with NoSuchAuthorityCodeException

use of org.opengis.referencing.NoSuchAuthorityCodeException in project sis by apache.

the class EPSGFactoryTest method testCreateByName.

/**
 * Tests the creation of CRS using name instead of primary key.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 *
 * @see #testProjectedByName()
 */
@Test
public void testCreateByName() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    assertSame(factory.createUnit("9002"), factory.createUnit("foot"));
    assertNotSame(factory.createUnit("9001"), factory.createUnit("foot"));
    /*
         * Test a name with colons.
         */
    final CoordinateSystem cs = factory.createCoordinateSystem("Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations: north, east. UoM: degree");
    assertEpsgNameAndIdentifierEqual("Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations: north, east. UoM: degree", 6422, cs);
    /*
         * Tests with a unknown name. The exception should be NoSuchAuthorityCodeException
         * (some previous version wrongly threw a SQLException when using HSQL database).
         */
    try {
        factory.createGeographicCRS("WGS83");
        fail("Should not find a geographic CRS named “WGS83” (the actual name is “WGS 84”).");
    } catch (NoSuchAuthorityCodeException e) {
        // This is the expected exception.
        assertEquals("WGS83", e.getAuthorityCode());
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Example 5 with NoSuchAuthorityCodeException

use of org.opengis.referencing.NoSuchAuthorityCodeException in project sis by apache.

the class CommonAuthorityFactoryTest method testAuto42001.

/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42001"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
public void testAuto42001() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42001,-123,0");
    assertSame("With other coord.", crs, factory.createProjectedCRS("AUTO : 42001, -122, 10 "));
    assertSame("Omitting namespace.", crs, factory.createProjectedCRS(" 42001, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO2 :  42001, 1, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO1 :  42001, 9001, -122 , 10 "));
    assertSame("Legacy namespace.", crs, factory.createProjectedCRS("AUTO:42001,9001,-122,10"));
    assertSame("When the given parameters match exactly the UTM central meridian and latitude of origin," + " the CRS created by AUTO:42002 should be the same than the CRS created by AUTO:42001.", crs, factory.createProjectedCRS("AUTO2:42002,1,-123,0"));
    assertEpsgNameAndIdentifierEqual("WGS 84 / UTM zone 10N", 32610, crs);
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode());
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, -123, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 0, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING, 0, p.parameter(Constants.FALSE_NORTHING).doubleValue(), STRICT);
    assertEquals("axis[0].unit", Units.METRE, crs.getCoordinateSystem().getAxis(0).getUnit());
    try {
        factory.createObject("AUTO:42001");
        fail("Should not have accepted incomplete code.");
    } catch (NoSuchAuthorityCodeException e) {
        assertEquals("42001", e.getAuthorityCode());
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Aggregations

NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)23 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)8 FactoryException (org.opengis.referencing.FactoryException)7 InternationalString (org.opengis.util.InternationalString)5 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)2 File (java.io.File)2 ResultSet (java.sql.ResultSet)2 Identifier (org.opengis.metadata.Identifier)2 Citation (org.opengis.metadata.citation.Citation)2 Material (com.jme3.material.Material)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Vector2f (com.jme3.math.Vector2f)1 Vector3f (com.jme3.math.Vector3f)1 Vector4f (com.jme3.math.Vector4f)1 Geometry (com.jme3.scene.Geometry)1 Mesh (com.jme3.scene.Mesh)1 Mode (com.jme3.scene.Mesh.Mode)1