Search in sources :

Example 1 with SpatialReferenceSystemDao

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;
}
Also used : SpatialReferenceSystemDao(mil.nga.geopackage.core.srs.SpatialReferenceSystemDao) SpatialReferenceSystem(mil.nga.geopackage.core.srs.SpatialReferenceSystem) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 2 with SpatialReferenceSystemDao

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;
}
Also used : SpatialReferenceSystemDao(mil.nga.geopackage.core.srs.SpatialReferenceSystemDao) SQLException(java.sql.SQLException) SpatialReferenceSystem(mil.nga.geopackage.core.srs.SpatialReferenceSystem) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) ConversionException(org.springframework.core.convert.ConversionException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

SpatialReferenceSystem (mil.nga.geopackage.core.srs.SpatialReferenceSystem)2 SpatialReferenceSystemDao (mil.nga.geopackage.core.srs.SpatialReferenceSystemDao)2 LineString (org.locationtech.jts.geom.LineString)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1 Point (org.locationtech.jts.geom.Point)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 ConversionException (org.springframework.core.convert.ConversionException)1