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;
}
}
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);
}
}
}
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;
}
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());
}
}
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());
}
}
Aggregations