Search in sources :

Example 1 with EpsgCrs

use of de.ii.xtraplatform.crs.domain.EpsgCrs in project ldproxy by interactive-instruments.

the class TilesQueriesHandlerImpl method getMultiLayerTileResponse.

private Response getMultiLayerTileResponse(QueryInputTileMultiLayer queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    Tile multiLayerTile = queryInput.getTile();
    List<String> collectionIds = multiLayerTile.getCollectionIds();
    Map<String, FeatureQuery> queryMap = queryInput.getQueryMap();
    Map<String, Tile> singleLayerTileMap = queryInput.getSingleLayerTileMap();
    FeatureProvider2 featureProvider = multiLayerTile.getFeatureProvider().get();
    TileMatrixSet tileMatrixSet = multiLayerTile.getTileMatrixSet();
    int tileLevel = multiLayerTile.getTileLevel();
    int tileRow = multiLayerTile.getTileRow();
    int tileCol = multiLayerTile.getTileCol();
    if (!(multiLayerTile.getOutputFormat() instanceof TileFormatWithQuerySupportExtension))
        throw new RuntimeException(String.format("Unexpected tile format without query support. Found: %s", multiLayerTile.getOutputFormat().getClass().getSimpleName()));
    TileFormatWithQuerySupportExtension outputFormat = (TileFormatWithQuerySupportExtension) multiLayerTile.getOutputFormat();
    // process parameters and generate query
    Optional<CrsTransformer> crsTransformer = Optional.empty();
    EpsgCrs targetCrs = tileMatrixSet.getCrs();
    if (featureProvider.supportsCrs()) {
        EpsgCrs sourceCrs = featureProvider.crs().getNativeCrs();
        crsTransformer = crsTransformerFactory.getTransformer(sourceCrs, targetCrs);
    }
    List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), i18n, requestContext.getLanguage());
    Map<String, ByteArrayOutputStream> byteArrayMap = new HashMap<>();
    for (String collectionId : collectionIds) {
        // TODO limitation of the current model: all layers have to come from the same feature provider and use the same CRS
        Tile tile = singleLayerTileMap.get(collectionId);
        if (!multiLayerTile.getTemporary()) {
            // use cached tile
            try {
                Optional<InputStream> tileContent = tileCache.getTile(tile);
                if (tileContent.isPresent()) {
                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                    ByteStreams.copy(tileContent.get(), buffer);
                    byteArrayMap.put(collectionId, buffer);
                    continue;
                }
            } catch (SQLException | IOException e) {
            // could not read the cache, generate the tile
            }
        }
        String featureTypeId = apiData.getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class).map(cfg -> cfg.getFeatureType().orElse(collectionId)).orElse(collectionId);
        FeatureQuery query = queryMap.get(collectionId);
        ImmutableFeatureTransformationContextTiles transformationContext;
        try {
            transformationContext = new ImmutableFeatureTransformationContextTiles.Builder().api(api).apiData(apiData).featureSchema(featureProvider.getData().getTypes().get(featureTypeId)).tile(tile).tileCache(tileCache).collectionId(collectionId).ogcApiRequest(requestContext).crsTransformer(crsTransformer).codelists(entityRegistry.getEntitiesForType(Codelist.class).stream().collect(Collectors.toMap(PersistentEntity::getId, c -> c))).defaultCrs(queryInput.getDefaultCrs()).links(links).isFeatureCollection(true).fields(query.getFields()).limit(query.getLimit()).offset(0).i18n(i18n).outputStream(new OutputStreamToByteConsumer()).build();
        } catch (Exception e) {
            throw new RuntimeException("Error building the tile transformation context.", e);
        }
        Optional<FeatureTokenEncoder<?>> encoder = outputFormat.getFeatureEncoder(transformationContext);
        if (outputFormat.supportsFeatureQuery() && encoder.isPresent()) {
            FeatureStream featureStream = featureProvider.queries().getFeatureStream(query);
            ResultReduced<byte[]> result = generateTile(featureStream, encoder.get(), transformationContext, outputFormat);
            if (result.isSuccess()) {
                byte[] bytes = result.reduced();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream(bytes.length);
                buffer.write(bytes, 0, bytes.length);
                byteArrayMap.put(collectionId, buffer);
            }
        } else {
            throw new NotAcceptableException(MessageFormat.format("The requested media type {0} cannot be generated, because it does not support streaming.", requestContext.getMediaType().type()));
        }
    }
    TileFormatWithQuerySupportExtension.MultiLayerTileContent result;
    try {
        result = outputFormat.combineSingleLayerTilesToMultiLayerTile(tileMatrixSet, singleLayerTileMap, byteArrayMap);
    } catch (IOException e) {
        throw new RuntimeException("Error accessing the tile cache.", e);
    }
    // try to write/update tile in cache, if all collections have been processed
    if (result.isComplete) {
        try {
            tileCache.storeTile(multiLayerTile, result.byteArray);
        } catch (Throwable e) {
            String msg = "Failure to write the multi-layer file of tile {}/{}/{}/{} in dataset '{}', format '{}' to the cache";
            LogContext.errorAsInfo(LOGGER, e, msg, tileMatrixSet.getId(), tileLevel, tileRow, tileCol, api.getId(), outputFormat.getExtension());
        }
    }
    Date lastModified = null;
    EntityTag etag = getEtag(result.byteArray);
    Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
    if (Objects.nonNull(response))
        return response.build();
    return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? links : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("%s_%d_%d_%d.%s", tileMatrixSet.getId(), tileLevel, tileRow, tileCol, outputFormat.getMediaType().fileExtension())).entity(result.byteArray).build();
}
Also used : Date(java.util.Date) Link(de.ii.ogcapi.foundation.domain.Link) LoggerFactory(org.slf4j.LoggerFactory) TileSetFormatExtension(de.ii.ogcapi.tiles.domain.TileSetFormatExtension) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) TileSetsFormatExtension(de.ii.ogcapi.tiles.domain.TileSetsFormatExtension) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) TileMatrixSetRepository(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetRepository) Tile(de.ii.ogcapi.tiles.domain.Tile) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer) PersistentEntity(de.ii.xtraplatform.store.domain.entities.PersistentEntity) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ImmutableFeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.ImmutableFeatureTransformationContextTiles) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) TilesQueriesHandler(de.ii.ogcapi.tiles.domain.TilesQueriesHandler) Builder(de.ii.ogcapi.tiles.domain.ImmutableTileSets.Builder) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) ByteStreams(com.google.common.io.ByteStreams) Sink(de.ii.xtraplatform.streams.domain.Reactive.Sink) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) TileSet(de.ii.ogcapi.tiles.domain.TileSet) LogContext(de.ii.xtraplatform.base.domain.LogContext) DataType(de.ii.ogcapi.tiles.domain.TileSet.DataType) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ClientBuilder(javax.ws.rs.client.ClientBuilder) TileMatrixSetLimitsGenerator(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimitsGenerator) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) QueriesHandler(de.ii.ogcapi.foundation.domain.QueriesHandler) ImmutableTileSets(de.ii.ogcapi.tiles.domain.ImmutableTileSets) FeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.FeatureTransformationContextTiles) TileCache(de.ii.ogcapi.tiles.domain.TileCache) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) MinMax(de.ii.ogcapi.tiles.domain.MinMax) I18n(de.ii.ogcapi.foundation.domain.I18n) IOException(java.io.IOException) FeatureStream(de.ii.xtraplatform.features.domain.FeatureStream) EntityTag(javax.ws.rs.core.EntityTag) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) StaticTileProviderStore(de.ii.ogcapi.tiles.domain.StaticTileProviderStore) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) SinkReduced(de.ii.xtraplatform.streams.domain.Reactive.SinkReduced) ServerErrorException(javax.ws.rs.ServerErrorException) ResultReduced(de.ii.xtraplatform.features.domain.FeatureStream.ResultReduced) TileSets(de.ii.ogcapi.tiles.domain.TileSets) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) FeatureStream(de.ii.xtraplatform.features.domain.FeatureStream) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) PersistentEntity(de.ii.xtraplatform.store.domain.entities.PersistentEntity) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) EntityTag(javax.ws.rs.core.EntityTag) ImmutableFeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.ImmutableFeatureTransformationContextTiles) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Tile(de.ii.ogcapi.tiles.domain.Tile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) NotAcceptableException(javax.ws.rs.NotAcceptableException) IOException(java.io.IOException) ServerErrorException(javax.ws.rs.ServerErrorException) Date(java.util.Date) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) NotAcceptableException(javax.ws.rs.NotAcceptableException) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) Link(de.ii.ogcapi.foundation.domain.Link)

Example 2 with EpsgCrs

use of de.ii.xtraplatform.crs.domain.EpsgCrs in project ldproxy by interactive-instruments.

the class TileFormatMVT method getMaxAllowableOffset.

@Override
public double getMaxAllowableOffset(Tile tile) {
    double maxAllowableOffsetTileMatrixSet = tile.getTileMatrixSet().getMaxAllowableOffset(tile.getTileLevel(), tile.getTileRow(), tile.getTileCol());
    Unit<?> tmsCrsUnit = crsInfo.getUnit(tile.getTileMatrixSet().getCrs());
    EpsgCrs nativeCrs = crsSupport.getStorageCrs(tile.getApiData(), Optional.empty());
    Unit<?> nativeCrsUnit = crsInfo.getUnit(nativeCrs);
    if (tmsCrsUnit.equals(nativeCrsUnit))
        return maxAllowableOffsetTileMatrixSet;
    else if (tmsCrsUnit.equals(Units.DEGREE) && nativeCrsUnit.equals(Units.METRE))
        return maxAllowableOffsetTileMatrixSet * 111333.0;
    else if (tmsCrsUnit.equals(Units.METRE) && nativeCrsUnit.equals(Units.DEGREE))
        return maxAllowableOffsetTileMatrixSet / 111333.0;
    LOGGER.error("TileFormatMVT.getMaxAllowableOffset: Cannot convert between axis units '{}' and '{}'.", tmsCrsUnit.getName(), nativeCrsUnit.getName());
    return 0;
}
Also used : EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs)

Example 3 with EpsgCrs

use of de.ii.xtraplatform.crs.domain.EpsgCrs in project ldproxy by interactive-instruments.

the class EndpointRoutesPost method computeRoute.

/**
 * creates a new route
 *
 * @return a route according to the RouteExchangeModel
 */
@POST
@SuppressWarnings("UnstableApiUsage")
public Response computeRoute(@Auth Optional<User> optionalUser, @Context OgcApi api, @Context ApiRequestContext requestContext, @Context UriInfo uriInfo, @Context HttpServletRequest request, byte[] requestBody) {
    OgcApiDataV2 apiData = api.getData();
    checkAuthorization(apiData, optionalUser);
    FeatureProvider2 featureProvider = providers.getFeatureProviderOrThrow(api.getData());
    ensureFeatureProviderSupportsRouting(featureProvider);
    String featureTypeId = api.getData().getExtension(RoutingConfiguration.class).map(RoutingConfiguration::getFeatureType).orElseThrow(() -> new IllegalStateException("No feature type has been configured for routing."));
    EpsgCrs defaultCrs = apiData.getExtension(RoutingConfiguration.class).map(RoutingConfiguration::getDefaultEpsgCrs).orElse(OgcCrs.CRS84);
    Map<String, Integer> coordinatePrecision = apiData.getExtension(RoutingConfiguration.class).map(RoutingConfiguration::getCoordinatePrecision).orElse(ImmutableMap.of());
    String speedLimitUnit = apiData.getExtension(RoutingConfiguration.class).map(RoutingConfiguration::getSpeedLimitUnit).orElse("kmph");
    Double elevationProfileSimplificationTolerance = apiData.getExtension(RoutingConfiguration.class).map(RoutingConfiguration::getElevationProfileSimplificationTolerance).orElse(null);
    List<OgcApiQueryParameter> allowedParameters = getQueryParameters(extensionRegistry, api.getData(), "/routes", HttpMethods.POST);
    FeatureQuery query = ogcApiFeaturesQuery.requestToBareFeatureQuery(api.getData(), featureTypeId, defaultCrs, coordinatePrecision, 1, Integer.MAX_VALUE, Integer.MAX_VALUE, toFlatMap(uriInfo.getQueryParameters()), allowedParameters);
    RouteDefinition definition;
    try {
        // parse input
        definition = mapper.readValue(requestBody, RouteDefinition.class);
    } catch (IOException e) {
        throw new IllegalArgumentException(String.format("The content of the route definition is invalid: %s", e.getMessage()), e);
    }
    String routeId = Hashing.murmur3_128().newHasher().putObject(definition, RouteDefinition.FUNNEL).putString(Optional.ofNullable(request.getHeader("crs")).orElse(defaultCrs.toUriString()), StandardCharsets.UTF_8).hash().toString();
    if (apiData.getExtension(RoutingConfiguration.class).map(RoutingConfiguration::isManageRoutesEnabled).orElse(false)) {
        if (routeRepository.routeExists(apiData, routeId)) {
            // If the same route is already stored, just return the stored route
            QueryHandlerRoutes.QueryInputRoute queryInput = new ImmutableQueryInputRoute.Builder().routeId(routeId).build();
            return queryHandler.handle(QueryHandlerRoutes.Query.GET_ROUTE, queryInput, requestContext);
        }
    }
    QueryHandlerRoutes.QueryInputComputeRoute queryInput = new ImmutableQueryInputComputeRoute.Builder().from(getGenericQueryInput(api.getData())).definition(definition).routeId(routeId).featureProvider(featureProvider).featureTypeId(featureTypeId).query(query).crs(Optional.ofNullable(request.getHeader("crs"))).defaultCrs(defaultCrs).speedLimitUnit(speedLimitUnit).elevationProfileSimplificationTolerance(Optional.ofNullable(elevationProfileSimplificationTolerance)).build();
    return queryHandler.handle(QueryHandlerRoutes.Query.COMPUTE_ROUTE, queryInput, requestContext);
}
Also used : FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) IOException(java.io.IOException) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) QueryHandlerRoutes(de.ii.ogcapi.routes.domain.QueryHandlerRoutes) ImmutableQueryInputComputeRoute(de.ii.ogcapi.routes.domain.ImmutableQueryInputComputeRoute) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) ImmutableRouteDefinition(de.ii.ogcapi.routes.domain.ImmutableRouteDefinition) RouteDefinition(de.ii.ogcapi.routes.domain.RouteDefinition) POST(javax.ws.rs.POST)

Example 4 with EpsgCrs

use of de.ii.xtraplatform.crs.domain.EpsgCrs in project ldproxy by interactive-instruments.

the class FeaturesQueryImpl method requestToFeatureQuery.

@Override
public FeatureQuery requestToFeatureQuery(OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData, EpsgCrs defaultCrs, Map<String, Integer> coordinatePrecision, Map<String, String> parameters, List<OgcApiQueryParameter> allowedParameters, String featureId) {
    for (OgcApiQueryParameter parameter : allowedParameters) {
        parameters = parameter.transformParameters(collectionData, parameters, apiData);
    }
    final CqlFilter filter = CqlFilter.of(In.of(ScalarLiteral.of(featureId)));
    final String collectionId = collectionData.getId();
    final String featureTypeId = apiData.getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class).map(cfg -> cfg.getFeatureType().orElse(collectionId)).orElse(collectionId);
    final ImmutableFeatureQuery.Builder queryBuilder = ImmutableFeatureQuery.builder().type(featureTypeId).filter(filter).returnsSingleFeature(true).crs(defaultCrs);
    for (OgcApiQueryParameter parameter : allowedParameters) {
        parameter.transformQuery(collectionData, queryBuilder, parameters, apiData);
    }
    return processCoordinatePrecision(queryBuilder, coordinatePrecision).build();
}
Also used : Function(de.ii.xtraplatform.cql.domain.Function) SpatialLiteral(de.ii.xtraplatform.cql.domain.SpatialLiteral) Property(de.ii.xtraplatform.cql.domain.Property) Arrays(java.util.Arrays) CrsTransformationException(de.ii.xtraplatform.crs.domain.CrsTransformationException) Unit(javax.measure.Unit) LoggerFactory(org.slf4j.LoggerFactory) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) FeatureQueryEncoder(de.ii.xtraplatform.features.domain.FeatureQueryEncoder) Or(de.ii.xtraplatform.cql.domain.Or) CrsInfo(de.ii.xtraplatform.crs.domain.CrsInfo) Units(org.kortforsyningen.proj.Units) Locale(java.util.Locale) Map(java.util.Map) CqlPredicate(de.ii.xtraplatform.cql.domain.CqlPredicate) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) Splitter(com.google.common.base.Splitter) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) FeatureProviderDataV2(de.ii.xtraplatform.features.domain.FeatureProviderDataV2) ImmutableSet(com.google.common.collect.ImmutableSet) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) TemporalOperator(de.ii.xtraplatform.cql.domain.TemporalOperator) Collection(java.util.Collection) Set(java.util.Set) PARAMETER_BBOX(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration.PARAMETER_BBOX) Collectors(java.util.stream.Collectors) Cql(de.ii.xtraplatform.cql.domain.Cql) Objects(java.util.Objects) List(java.util.List) CqlFilter(de.ii.xtraplatform.cql.domain.CqlFilter) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) ID_PLACEHOLDER(de.ii.xtraplatform.cql.domain.In.ID_PLACEHOLDER) Like(de.ii.xtraplatform.cql.domain.Like) Optional(java.util.Optional) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) PARAMETER_DATETIME(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration.PARAMETER_DATETIME) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) SpatialOperation(de.ii.xtraplatform.cql.domain.SpatialOperation) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) ImmutableQueryValidationInputCoordinates(de.ii.ogcapi.features.core.domain.ImmutableQueryValidationInputCoordinates) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Singleton(javax.inject.Singleton) OptionalInt(java.util.OptionalInt) DATETIME_INTERVAL_SEPARATOR(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration.DATETIME_INTERVAL_SEPARATOR) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) And(de.ii.xtraplatform.cql.domain.And) FeaturesQuery(de.ii.ogcapi.features.core.domain.FeaturesQuery) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) In(de.ii.xtraplatform.cql.domain.In) SchemaBase(de.ii.xtraplatform.features.domain.SchemaBase) ImmutableList(com.google.common.collect.ImmutableList) Eq(de.ii.xtraplatform.cql.domain.Eq) SpatialOperator(de.ii.xtraplatform.cql.domain.SpatialOperator) TemporalOperation(de.ii.xtraplatform.cql.domain.TemporalOperation) Value(org.immutables.value.Value) Envelope(de.ii.xtraplatform.cql.domain.Geometry.Envelope) OgcCrs(de.ii.xtraplatform.crs.domain.OgcCrs) TemporalLiteral(de.ii.xtraplatform.cql.domain.TemporalLiteral) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) Logger(org.slf4j.Logger) RangeMeaning(org.opengis.referencing.cs.RangeMeaning) FeaturesCollectionQueryables(de.ii.ogcapi.features.core.domain.FeaturesCollectionQueryables) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) ScalarLiteral(de.ii.xtraplatform.cql.domain.ScalarLiteral) SchemaInfo(de.ii.ogcapi.features.core.domain.SchemaInfo) ImmutableFeatureQuery(de.ii.xtraplatform.features.domain.ImmutableFeatureQuery) PARAMETER_Q(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration.PARAMETER_Q) ImmutableFeatureQuery(de.ii.xtraplatform.features.domain.ImmutableFeatureQuery) CqlFilter(de.ii.xtraplatform.cql.domain.CqlFilter) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter)

Example 5 with EpsgCrs

use of de.ii.xtraplatform.crs.domain.EpsgCrs in project ldproxy by interactive-instruments.

the class CapabilityCrs method onStartup.

@Override
public ValidationResult onStartup(OgcApi api, MODE apiValidation) {
    Optional<CrsConfiguration> crsConfiguration = api.getData().getExtension(CrsConfiguration.class).filter(ExtensionConfiguration::isEnabled);
    if (crsConfiguration.isEmpty()) {
        return ValidationResult.of();
    }
    EpsgCrs defaultCrs = api.getData().getExtension(FeaturesCoreConfiguration.class).map(FeaturesCoreConfiguration::getDefaultEpsgCrs).orElse(OgcCrs.CRS84);
    EpsgCrs providerCrs = featuresCoreProviders.getFeatureProvider(api.getData()).flatMap(featureProvider2 -> featureProvider2.getData().getNativeCrs()).orElse(OgcCrs.CRS84);
    EpsgCrs lastCrs = null;
    try {
        lastCrs = defaultCrs;
        crsTransformerFactory.getTransformer(providerCrs, defaultCrs);
        for (EpsgCrs crs : crsConfiguration.get().getAdditionalCrs()) {
            lastCrs = crs;
            crsTransformerFactory.getTransformer(providerCrs, crs);
        }
    } catch (Throwable e) {
        return ImmutableValidationResult.builder().mode(apiValidation).addErrors(String.format("Could not find transformation for %s -> %s: %s", providerCrs.toHumanReadableString(), lastCrs.toHumanReadableString(), e.getMessage())).build();
    }
    try {
        lastCrs = defaultCrs;
        crsTransformerFactory.getTransformer(defaultCrs, providerCrs);
        for (EpsgCrs crs : crsConfiguration.get().getAdditionalCrs()) {
            lastCrs = crs;
            crsTransformerFactory.getTransformer(crs, providerCrs);
        }
    } catch (Throwable e) {
        return ImmutableValidationResult.builder().mode(apiValidation).addErrors(String.format("Could not find transformation for %s -> %s: %s", lastCrs.toHumanReadableString(), providerCrs.toHumanReadableString(), e.getMessage())).build();
    }
    return ValidationResult.of();
}
Also used : Builder(de.ii.ogcapi.crs.domain.ImmutableCrsConfiguration.Builder) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) ImmutableValidationResult(de.ii.xtraplatform.store.domain.entities.ImmutableValidationResult) MODE(de.ii.xtraplatform.store.domain.entities.ValidationResult.MODE) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) Inject(javax.inject.Inject) CrsConfiguration(de.ii.ogcapi.crs.domain.CrsConfiguration) ValidationResult(de.ii.xtraplatform.store.domain.entities.ValidationResult) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) OgcCrs(de.ii.xtraplatform.crs.domain.OgcCrs) Optional(java.util.Optional) ApiBuildingBlock(de.ii.ogcapi.foundation.domain.ApiBuildingBlock) CrsConfiguration(de.ii.ogcapi.crs.domain.CrsConfiguration) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration)

Aggregations

EpsgCrs (de.ii.xtraplatform.crs.domain.EpsgCrs)23 ImmutableList (com.google.common.collect.ImmutableList)10 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)10 List (java.util.List)10 Optional (java.util.Optional)10 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)9 Collectors (java.util.stream.Collectors)9 Inject (javax.inject.Inject)9 Singleton (javax.inject.Singleton)9 FeaturesCoreConfiguration (de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)8 CrsTransformerFactory (de.ii.xtraplatform.crs.domain.CrsTransformerFactory)8 FeatureQuery (de.ii.xtraplatform.features.domain.FeatureQuery)8 Map (java.util.Map)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 FeatureProvider2 (de.ii.xtraplatform.features.domain.FeatureProvider2)7 Objects (java.util.Objects)7 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)6 Link (de.ii.ogcapi.foundation.domain.Link)6 IOException (java.io.IOException)6 Logger (org.slf4j.Logger)6