Search in sources :

Example 11 with WKTDefinition

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);
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) CodeDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition) WKTDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition) FactoryException(org.opengis.referencing.FactoryException)

Example 12 with WKTDefinition

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;
}
Also used : CodeDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition) SpatialReferenceSystem(mil.nga.geopackage.core.srs.SpatialReferenceSystem) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) WKTDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition)

Aggregations

WKTDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition)12 CodeDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition)11 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)8 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)6 GeometryMetadata (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryMetadata)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 Geometry (org.locationtech.jts.geom.Geometry)3 MultiLineString (org.locationtech.jts.geom.MultiLineString)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 WKTReader2 (org.geotools.geometry.jts.WKTReader2)2 LineString (org.locationtech.jts.geom.LineString)2 FactoryException (org.opengis.referencing.FactoryException)2 PGgeometry (org.postgis.PGgeometry)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 SpatialReferenceSystem (mil.nga.geopackage.core.srs.SpatialReferenceSystem)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1