use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class CodeTest method testWithVersion.
/**
* Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:8.3:4326"} identifier.
* This test intentionally uses an identifier with the {@code IOGP} authority instead than EPSG
* for the same reason than {@link #testSimple()}.
*/
@Test
@DependsOnMethod("testSimple")
public void testWithVersion() {
final SimpleCitation IOGP = new SimpleCitation("IOGP");
// See above javadoc.
final ReferenceIdentifier id = new ImmutableIdentifier(IOGP, "EPSG", "4326", "8.2", null);
final Code value = new Code(id);
assertEquals("codeSpace", "EPSG:8.2", value.codeSpace);
assertEquals("code", "4326", value.code);
/*
* Reverse operation. Note that the authority is lost since there is no room for that in a
* <gml:identifier> element. Current implementation sets the authority to the code space.
*/
final ReferenceIdentifier actual = value.getIdentifier();
assertSame("authority", Citations.EPSG, actual.getAuthority());
assertEquals("codeSpace", "EPSG", actual.getCodeSpace());
assertEquals("version", "8.2", actual.getVersion());
assertEquals("code", "4326", actual.getCode());
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class DefaultGeographicCRSTest method testIdentifiers.
/**
* Verifies the {@link CommonCRS#WGS84} identifiers in both normalized and unnormalized CRS.
* The intent is actually to test the replacement of {@code "EPSG:4326"} by {@code "CRS:84"}.
*/
@Test
public void testIdentifiers() {
GeographicCRS crs = CommonCRS.WGS72.geographic();
ReferenceIdentifier identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "EPSG", identifier.getCodeSpace());
assertEquals("code", "4322", identifier.getCode());
crs = CommonCRS.WGS72.normalizedGeographic();
assertTrue(crs.getIdentifiers().isEmpty());
crs = CommonCRS.WGS84.geographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "EPSG", identifier.getCodeSpace());
assertEquals("code", "4326", identifier.getCode());
crs = CommonCRS.WGS84.normalizedGeographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "CRS", identifier.getCodeSpace());
assertEquals("code", "84", identifier.getCode());
crs = CommonCRS.NAD83.geographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "EPSG", identifier.getCodeSpace());
assertEquals("code", "4269", identifier.getCode());
crs = CommonCRS.NAD83.normalizedGeographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "CRS", identifier.getCodeSpace());
assertEquals("code", "83", identifier.getCode());
crs = CommonCRS.NAD27.geographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "EPSG", identifier.getCodeSpace());
assertEquals("code", "4267", identifier.getCode());
crs = CommonCRS.NAD27.normalizedGeographic();
identifier = getSingleton(crs.getIdentifiers());
assertEquals("codespace", "CRS", identifier.getCodeSpace());
assertEquals("code", "27", identifier.getCode());
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class ParameterFormat method formatSummary.
/**
* Implementation of public {@code format(…)} methods for {@code NAME_SUMMARY} content level.
*
* @param objects the collection of objects to format.
* @param out the stream or buffer where to write the summary.
* @throws IOException if an error occurred will writing to the given appendable.
*/
private void formatSummary(final IdentifiedObject[] objects, final Appendable out) throws IOException {
final Vocabulary resources = Vocabulary.getResources(displayLocale);
/*
* Prepares all rows before we write them to the output stream, because not all
* identified objects may have names with the same scopes in the same order. We
* also need to iterate over all rows in order to know the number of columns.
*
* The first column is reserved for the identifier. We put null as a sentinal key for
* that column name, to be replaced later by "Identifier" in user locale. We can not
* put the localized strings in the map right now because they could conflict with
* the scope of some alias to be processed below.
*/
boolean hasIdentifiers = false;
final List<String[]> rows = new ArrayList<>();
final Map<String, Integer> columnIndices = new LinkedHashMap<>();
// See above comment for the meaning of "null" here.
columnIndices.put(null, 0);
if (preferredCodespaces != null) {
for (final String codespace : preferredCodespaces) {
columnIndices.put(codespace, columnIndices.size());
}
}
for (final IdentifiedObject object : objects) {
// Will growth later if needed.
String[] row = new String[columnIndices.size()];
/*
* Put the first identifier in the first column. If no identifier has a codespace in the list
* supplied by the user, then we will use the first identifier (any codespace) as a fallback.
*/
final Set<ReferenceIdentifier> identifiers = object.getIdentifiers();
if (identifiers != null) {
// Paranoiac check.
Identifier identifier = null;
for (final ReferenceIdentifier candidate : identifiers) {
if (candidate != null) {
// Paranoiac check.
if (isPreferredCodespace(candidate.getCodeSpace())) {
identifier = candidate;
// Format now.
break;
}
if (identifier == null) {
// To be used as a fallback if we find nothing better.
identifier = candidate;
}
}
}
if (identifier != null) {
row[0] = IdentifiedObjects.toString(identifier);
hasIdentifiers = true;
}
}
/*
* If the name's codespace is in the list of codespaces asked by the user, add that name
* in the current row and clear the 'name' locale variable. Otherwise, keep the 'name'
* locale variable in case we found no alias to format.
*/
ReferenceIdentifier name = object.getName();
if (name != null) {
// Paranoiac check.
final String codespace = name.getCodeSpace();
if (isPreferredCodespace(codespace)) {
row = putIfAbsent(resources, row, columnIndices, codespace, name.getCode());
name = null;
}
}
/*
* Put all aliases having a codespace in the list asked by the user.
*/
final Collection<GenericName> aliases = object.getAlias();
if (aliases != null) {
// Paranoiac check.
for (final GenericName alias : aliases) {
if (alias != null) {
// Paranoiac check.
final String codespace = NameToIdentifier.getCodeSpace(alias, displayLocale);
if (isPreferredCodespace(codespace)) {
row = putIfAbsent(resources, row, columnIndices, codespace, alias.tip().toInternationalString().toString(displayLocale));
name = null;
}
}
}
}
/*
* If no name and no alias have a codespace in the list of codespaces asked by the user,
* force the addition of primary name regardless its codespace.
*/
if (name != null) {
row = putIfAbsent(resources, row, columnIndices, name.getCodeSpace(), name.getCode());
}
rows.add(row);
}
/*
* Writes the table. The header will contain one column for each codespace in the order declared
* by the user. If the user did not specified any codespace, or if we had to write codespace not
* on the user list, then those codespaces will be written in the order we found them.
*/
final boolean hasColors = (colors != null);
final TableAppender table = new TableAppender(out, columnSeparator);
table.setMultiLinesCells(true);
table.appendHorizontalSeparator();
for (String codespace : columnIndices.keySet()) {
if (codespace == null) {
// Skip empty column.
if (!hasIdentifiers)
continue;
codespace = resources.getString(Vocabulary.Keys.Identifier);
}
if (hasColors) {
codespace = X364.BOLD.sequence() + codespace + X364.NORMAL.sequence();
}
table.append(codespace);
nextColumn(table);
}
table.appendHorizontalSeparator();
/*
* Writes row content.
*/
final int numColumns = columnIndices.size();
for (final String[] row : rows) {
for (int i = hasIdentifiers ? 0 : 1; i < numColumns; i++) {
if (i < row.length) {
final String name = row[i];
if (name != null) {
table.append(name);
}
}
nextColumn(table);
}
table.nextLine();
}
table.appendHorizontalSeparator();
table.flush();
}
use of org.opengis.referencing.ReferenceIdentifier in project ddf by codice.
the class GeospatialUtil method transformToEPSG4326LonLatFormat.
/**
* Transform a geometry to EPSG:4326 format with lon/lat coordinate ordering. NOTE: This method
* will NOT perform the transform swapping coordinates even if the sourceCrsName is EPSG:4326.
*
* @param geometry - Geometry to transform
* @param sourceCrs - Source geometry's coordinate reference system
* @return Geometry - Transformed geometry into EPSG:4326 lon/lat coordinate system
*/
public static Geometry transformToEPSG4326LonLatFormat(Geometry geometry, CoordinateReferenceSystem sourceCrs) throws GeoFormatException {
if (geometry == null) {
throw new GeoFormatException("Unable to convert null geometry");
}
// information
if (sourceCrs == null || CollectionUtils.isEmpty(sourceCrs.getIdentifiers())) {
return geometry;
}
Geometry transformedGeometry = geometry;
try {
boolean sourceCrsMatchesTarget = false;
for (ReferenceIdentifier referenceIdentifier : sourceCrs.getIdentifiers()) {
if (referenceIdentifier.toString().equalsIgnoreCase(EPSG_4326)) {
sourceCrsMatchesTarget = true;
break;
}
}
if (!sourceCrsMatchesTarget) {
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
CoordinateReferenceSystem targetCRS = factory.createCoordinateReferenceSystem(EPSG_4326);
MathTransform transform = CRS.findMathTransform(sourceCrs, targetCRS);
transformedGeometry = JTS.transform(geometry, transform);
LOGGER.debug("Converted CRS {} into {} : {}", sourceCrs, EPSG_4326, geometry);
}
} catch (FactoryException | TransformException e) {
throw new GeoFormatException("Unable to convert coordinate to " + EPSG_4326, e);
}
return transformedGeometry;
}
use of org.opengis.referencing.ReferenceIdentifier in project hale by halestudio.
the class SelectCRSDialog method updateMessage.
/**
* Update the dialog message
*
* @param editor the active editor
*/
private void updateMessage(CRSFieldEditor editor) {
if (editor.isValid()) {
setErrorMessage(null);
CoordinateReferenceSystem crs = editor.getCRSDefinition().getCRS();
if (crs.getIdentifiers().isEmpty()) {
setMessage(crs.getName().toString(), IMessageProvider.INFORMATION);
} else {
ReferenceIdentifier firstId = crs.getIdentifiers().iterator().next();
setMessage(MessageFormat.format("[{0}:{1}] {2}", firstId.getCodeSpace(), firstId.getCode(), crs.getName().getCode()), IMessageProvider.INFORMATION);
}
} else {
setErrorMessage(editor.getErrorMessage());
setMessage(DEF_MESSAGE);
}
}
Aggregations