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();
}
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);
}
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());
}
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;
}
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();
}
Aggregations