Search in sources :

Example 1 with GeojsonPoint

use of org.n52.io.geojson.old.GeojsonPoint in project series-rest-api by 52North.

the class CRSUtils method convertToGeojsonFrom.

/**
     * Creates a GeoJSON representation of the given point. Adds a named <code>crs</code> member if
     * it is different to the internally used CRS:84.
     *
     * @param point the point to be converted to GeoJSON.
     * @param targetCrs the target CRS.
     * @return a GeoJSON representation of the given point.
     * @throws TransformException if transforming point fails.
     * @throws FactoryException if creating the target CRS fails.
     */
public GeojsonPoint convertToGeojsonFrom(Point point, String targetCrs) throws TransformException, FactoryException {
    Point transformedPoint = (Point) transformInnerToOuter(point, targetCrs);
    GeojsonPoint asGeoJSON = convertToGeojsonFrom(transformedPoint);
    if (!DEFAULT_CRS.equalsIgnoreCase(targetCrs)) {
        asGeoJSON.setCrs(GeojsonCrs.createNamedCRS(targetCrs));
    }
    return asGeoJSON;
}
Also used : Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint)

Example 2 with GeojsonPoint

use of org.n52.io.geojson.old.GeojsonPoint in project series-rest-api by 52North.

the class IoParameters method transformToInnerCrs.

/**
     * @param point
     *        a GeoJSON point to be transformed to internally used CRS:84.
     * @param crsUtils
     *        a reference helper.
     * @return a transformed GeoJSON instance.
     * @throws IoParseException
     *         if point could not be transformed, or if requested CRS object could not be created.
     */
private GeojsonPoint transformToInnerCrs(GeojsonPoint point, CRSUtils crsUtils) {
    try {
        Point toTransformed = crsUtils.convertToPointFrom(point, getCrs());
        Point crs84Point = (Point) crsUtils.transformOuterToInner(toTransformed, getCrs());
        return crsUtils.convertToGeojsonFrom(crs84Point);
    } catch (TransformException e) {
        throw new IoParseException("Could not transform to internally used CRS:84.", e);
    } catch (FactoryException e) {
        throw new IoParseException("Check if 'crs' parameter is a valid EPSG CRS. Was: '" + getCrs() + "'.", e);
    }
}
Also used : IoParseException(org.n52.io.IoParseException) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint)

Aggregations

Point (com.vividsolutions.jts.geom.Point)2 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)2 IoParseException (org.n52.io.IoParseException)1 FactoryException (org.opengis.referencing.FactoryException)1 TransformException (org.opengis.referencing.operation.TransformException)1