use of mil.nga.geopackage.core.srs.SpatialReferenceSystemDao in project hale by halestudio.
the class GeopackageInstanceWriter method createEpsgSrs.
private SpatialReferenceSystem createEpsgSrs(GeoPackage geoPackage, CodeDefinition crs, String epsg) throws SQLException {
SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
SpatialReferenceSystem srs = new SpatialReferenceSystem();
CoordinateReferenceSystem geoCrs = crs.getCRS();
srs.setSrsName(geoCrs.getName().toString());
int codeId = Integer.parseInt(epsg);
String wkt = geoCrs.toWKT();
// XXX how to avoid clashes?
srs.setSrsId(codeId);
srs.setOrganization("EPSG");
srs.setOrganizationCoordsysId(codeId);
// XXX not sure what the difference between the definition types is
srs.setDefinition(wkt);
srs.setDefinition_12_063(wkt);
if (geoCrs.getRemarks() != null) {
srs.setDescription(geoCrs.getRemarks().toString());
}
srsDao.create(srs);
return srs;
}
use of mil.nga.geopackage.core.srs.SpatialReferenceSystemDao in project hale by halestudio.
the class GeopackageInstanceWriter method findSrs.
private SpatialReferenceSystem findSrs(GeoPackage geoPackage, String org, String code, String wkt, SimpleLog log) {
SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
SpatialReferenceSystem srs = null;
if (org == null && code != null) {
// try to split auth and code from code
// extract EPSG code
String epsg = CodeDefinition.extractEPSGCode(code);
if (epsg != null) {
org = "EPSG";
code = epsg;
}
}
if (org != null && code != null) {
try {
long codeNum = Long.parseLong(code);
srs = srsDao.queryForOrganizationCoordsysId(org, codeNum);
} catch (Exception e) {
log.warn("Failed to use SRS code for geometry column", e);
}
}
if (srs == null && wkt != null) {
try {
List<SpatialReferenceSystem> candidates = srsDao.queryForEq(SpatialReferenceSystem.COLUMN_DEFINITION, wkt);
if (!candidates.isEmpty()) {
srs = candidates.get(0);
}
} catch (SQLException e) {
log.warn("Failed to retrieve SRS based on WKT definition", e);
}
if (srs == null) {
// TODO create new SRS entry with definition?
}
}
return srs;
}
Aggregations