Search in sources :

Example 26 with CRSDefinition

use of eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition in project hale by halestudio.

the class RingHandler method createGeometry.

/**
 * Create a {@link LinearRing} geometry from the given instance.
 *
 * @param instance the instance
 * @param srsDimension the SRS dimension
 * @param allowTryOtherDimension if trying another dimension is allowed on
 *            failure (e.g. 3D instead of 2D)
 * @param reader the I/O Provider to get value
 * @return the {@link LinearRing} geometry
 * @throws GeometryNotSupportedException if the type definition doesn't
 *             represent a geometry type supported by the handler
 */
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing ring = null;
    // for use with GML 2, 3, 3.1, 3.2
    // use generic geometry handler to read curveMembers as MultiLineString
    // or LineString
    Collection<GeometryProperty<?>> properties = genericHandler.createGeometry(instance, srsDimension, reader);
    if (properties != null) {
        if (properties.size() == 1) {
            // geometry could be combined
            GeometryProperty<?> prop = properties.iterator().next();
            try {
                ring = getGeometryFactory().createLinearRing(filterDuplicates(prop.getGeometry().getCoordinates()));
            } catch (IllegalArgumentException e) {
                if (allowTryOtherDimension) {
                    // the error
                    // "Points of LinearRing do not form a closed
                    // linestring"
                    // can be an expression of a wrong dimension being used
                    // we try an alternative, to be sure (e.g. 3D instead of
                    // 2D)
                    int alternativeDimension = (srsDimension == 2) ? (3) : (2);
                    GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
                    log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
                    return geom;
                }
                throw e;
            }
            if (ring != null) {
                CRSDefinition crsDef = prop.getCRSDefinition();
                if (crsDef == null) {
                    GMLGeometryUtil.findCRS(instance);
                }
                return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
            }
        } else {
            throw new GeometryNotSupportedException("Ring components could not be combined to a geometry");
        }
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 27 with CRSDefinition

use of eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition 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 28 with CRSDefinition

use of eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition in project hale by halestudio.

the class AbstractGeoInstanceWriter method unifyGeometryPair.

/**
 * Returns a pair of unified geometry of given geometry and associated CRS
 * definition based on Winding order supplied.
 *
 * @param pair A pair of Geometry and CRSDefinition, on which winding
 *            process will get done.
 * @param report the reporter
 * @return Unified Pair .
 */
protected Pair<Geometry, CRSDefinition> unifyGeometryPair(Pair<Geometry, CRSDefinition> pair, IOReporter report) {
    // get Geometry object
    Geometry geom = pair.getFirst();
    if (geom == null) {
        return pair;
    }
    // getting CRS
    CRSDefinition def = pair.getSecond();
    CoordinateReferenceSystem crs = null;
    if (def != null)
        crs = pair.getSecond().getCRS();
    // unify geometry
    geom = unifyGeometry(geom, report, crs);
    return new Pair<>(geom, pair.getSecond());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Pair(eu.esdihumboldt.util.Pair)

Example 29 with CRSDefinition

use of eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition in project hale by halestudio.

the class DialogCRSProvider method getCRS.

/**
 * @see CRSProvider#getCRS(TypeDefinition, List, CRSDefinition)
 */
@Override
public CRSDefinition getCRS(TypeDefinition parentType, List<QName> propertyPath, final CRSDefinition defaultCrs) {
    // XXX for now always reports the same CRS definition
    if (crsDef == null && !shown) {
        shown = true;
        Display display = PlatformUI.getWorkbench().getDisplay();
        final AtomicReference<CRSDefinition> result = new AtomicReference<CRSDefinition>();
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                SelectCRSDialog dialog = new SelectCRSDialog(Display.getCurrent().getActiveShell(), defaultCrs);
                dialog.open();
                result.set(dialog.getValue());
            }
        });
        crsDef = result.get();
    }
    return crsDef;
}
Also used : CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) AtomicReference(java.util.concurrent.atomic.AtomicReference) Display(org.eclipse.swt.widgets.Display)

Example 30 with CRSDefinition

use of eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition in project hale by halestudio.

the class SelectCRSDialog method okPressed.

/**
 * @see Dialog#okPressed()
 */
@Override
protected void okPressed() {
    CRSDefinition crs;
    if (radioCRS.getSelection()) {
        crs = crsField.getCRSDefinition();
        lastCode = crsField.getCRSDefinition().getCode();
    } else {
        crs = wktField.getCRSDefinition();
        lastWKT = wktField.getCRSDefinition().getWkt();
    }
    value = crs;
    super.okPressed();
}
Also used : CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)

Aggregations

CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)30 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)20 Geometry (com.vividsolutions.jts.geom.Geometry)13 Point (com.vividsolutions.jts.geom.Point)9 CodeDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition)8 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)8 ArrayList (java.util.ArrayList)8 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)6 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)6 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)6 LineString (com.vividsolutions.jts.geom.LineString)5 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)5 WKTDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition)5 ParseException (java.text.ParseException)5 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 LinearRing (com.vividsolutions.jts.geom.LinearRing)3 NoResultException (eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException)3