use of eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition in project hale by halestudio.
the class CRSDefinitionUtil method createDefinition.
/**
* Create a {@link CRSDefinition} from an existing coordinate reference
* system.
*
* @param crs the coordinate reference system
* @param cache the cache for CRS resolving
* @return the CRS definition
*/
public static CRSDefinition createDefinition(CoordinateReferenceSystem crs, @Nullable CRSResolveCache cache) {
ReferenceIdentifier name = crs.getName();
// try to find CRS in EPSG DB
CRSDefinition def;
if (cache != null) {
def = cache.resolveCRS(crs);
} else {
def = lookupCrs(crs);
}
if (def != null) {
return def;
}
// try by code
if (name != null) {
String code = name.getCode();
if (code != null && !code.isEmpty()) {
// try decoding
try {
boolean lonFirst = (CRS.getAxisOrder(crs) == AxisOrder.EAST_NORTH);
crs = CRS.decode(code, lonFirst);
return new CodeDefinition(code, crs);
} catch (Exception e) {
// ignore
}
}
}
// use WKT
return new WKTDefinition(crs.toWKT(), crs);
}
use of eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition in project hale by halestudio.
the class GeopackageInstanceWriter method findOrCreateSrs.
private SpatialReferenceSystem findOrCreateSrs(GeoPackage geoPackage, CRSDefinition crs, SimpleLog log) throws SQLException {
SpatialReferenceSystem srs = null;
if (crs instanceof CodeDefinition) {
String code = ((CodeDefinition) crs).getCode();
srs = findSrs(geoPackage, null, code, null, log);
if (srs == null) {
// XXX creating a CRS currently only supported for EPSG codes
String epsg = CodeDefinition.extractEPSGCode(code);
if (epsg != null) {
srs = createEpsgSrs(geoPackage, (CodeDefinition) crs, epsg);
return srs;
}
}
} else if (crs instanceof WKTDefinition) {
String wkt = ((WKTDefinition) crs).getWkt();
srs = findSrs(geoPackage, null, null, wkt, log);
}
return srs;
}
Aggregations