Class ExecutionUtils


  • public class ExecutionUtils
    extends Object
    Holds helper methods that are used by the executor classes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ExecutionUtils.MatchType
      Enum type used in /ratio computation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Double cacheInUserData​(org.locationtech.jts.geom.Geometry geom, org.heigit.bigspatialdata.oshdb.api.generic.function.SerializableSupplier<Double> mapper)
      Caches the given mapper value in the user data of the Geometry object.
      String combineFiltersWithOr​(String firstFilter, String secondFilter)
      Combines the two given filters with an OR operation.
      <K extends Comparable<K> & Serializable,​V extends Number>
      SortedMap<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<Integer,​K>,​org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp>,​V>
      computeNestedResult​(RequestResource requestResource, org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<Integer,​K>,​org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp>,​org.locationtech.jts.geom.Geometry> preResult)
      Computes the result depending on the RequestResource using a MapAggregator object as input and returning a SortedMap.
      <K extends Comparable<K> & Serializable,​V extends Number>
      SortedMap<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​K>,​V>
      computeResult​(RequestResource requestResource, org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​K>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> preResult)
      Computes the result depending on the RequestResource using a MapAggregator object as input and returning a SortedMap.
      List<String[]> createCsvTopComments​(String url, String text, String apiVersion, Metadata metadata)
      Creates the comments of the csv response (Attribution, API-Version and optional Metadata).
      org.wololo.geojson.Feature createOSMFeature​(org.heigit.bigspatialdata.oshdb.osm.OSMEntity entity, org.locationtech.jts.geom.Geometry geometry, Map<String,​Object> properties, Set<Integer> keysInt, boolean includeTags, boolean includeOSMMetadata, boolean isContributionsEndpoint, ElementsGeometry elemGeom, EnumSet<org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType> contributionTypes)
      Creates the Feature objects in the OSM data response.
      Response createRatioGroupByBoundaryResponse​(Object[] boundaryIds, String[] timeArray, Double[] resultValues1, Double[] resultValues2, long startTime, RequestResource reqRes, String requestUrl, javax.servlet.http.HttpServletResponse servletResponse)
      Creates a RatioGroupByBoundaryResponse.
      Response createRatioResponse​(String[] timeArray, Double[] value1, Double[] value2, long startTime, RequestResource reqRes, String requestUrl, javax.servlet.http.HttpServletResponse servletResponse)
      Creates a RatioResponse.
      static DecimalFormat defineDecimalFormat​(String format)
      Defines a certain decimal format.
      int[] extractContributionTags​(org.heigit.bigspatialdata.oshdb.api.object.OSMContribution contrib)
      Extracts the tags from the given OSMContribution depending on the ContributionType.
      ContributionsResult[] fillContributionsResult​(SortedMap<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​? extends Number> entryVal, boolean isDensity, InputProcessor inputProcessor, DecimalFormat df, org.locationtech.jts.geom.Geometry geom)
      Fills the ContributionsResult array with respective ContributionsResult objects.
      Double[] fillElementsRatioGroupByBoundaryResultValues​(Set<? extends Map.Entry<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​? extends Number>> resultSet, DecimalFormat df)
      Fills the result value arrays for the ratio/groupBy/boundary response.
      ElementsResult[] fillElementsResult​(SortedMap<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​? extends Number> entryVal, boolean isDensity, DecimalFormat df, org.locationtech.jts.geom.Geometry geom)
      Fills the ElementsResult array with respective ElementsResult objects.
      org.locationtech.jts.geom.Geometry getGeometry​(org.heigit.bigspatialdata.oshdb.api.object.OSMContribution contribution, boolean clipGeometries, boolean before)
      Extracts and returns a geometry out of the given contribution.
      org.apache.commons.lang3.tuple.Pair<org.apache.commons.lang3.tuple.Pair<Integer,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapSnapshotToTags​(int keysInt, Integer[] valuesInt, org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot f)
      Maps the given OSMEntitySnapshot to a given tag, or to the remainder (having -1, -1 as identifier) if none of the given tags is included.
      static <A,​U extends Comparable<U> & Serializable,​V extends Comparable<V> & Serializable>
      SortedMap<V,​SortedMap<U,​A>>
      nest​(Map<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<U,​V>,​A> result)
      Adapted helper function, which works like nest but has switched <U> and <V> parameters.
      boolean[] setRequestedSimpleFeatures​(Set<SimpleFeatureType> simpleFeatureTypes)
      Sets the boolean values for the respective simple feature type: 0 = hasPoint, 1 = hasLine, 2 = hasPolygon, 3 = hasOther.
      org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> snapshotFilter​(org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapRed, Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes1, Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes2, Set<SimpleFeatureType> simpleFeatureTypes1, Set<SimpleFeatureType> simpleFeatureTypes2, Integer[] keysInt1, Integer[] keysInt2, Integer[] valuesInt1, Integer[] valuesInt2)
      Applies a filter on the given MapReducer object using the given parameters.
      org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer<org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> snapshotFilter​(org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer<org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapRed, Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes1, Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes2, Set<SimpleFeatureType> simpleFeatureTypes1, Set<SimpleFeatureType> simpleFeatureTypes2, Integer[] keysInt1, Integer[] keysInt2, Integer[] valuesInt1, Integer[] valuesInt2)
      Applies a filter on the given MapReducer object using the given parameters.
      boolean snapshotMatches​(org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot snapshot, Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes, Set<SimpleFeatureType> simpleFeatureTypes, Integer[] keysInt, Integer[] valuesInt)
      Compares the type(s) and tag(s) of the given snapshot to the given types|tags.
      void streamResponse​(javax.servlet.http.HttpServletResponse servletResponse, ExtractionResponse osmData, Stream<org.wololo.geojson.Feature> resultStream)
      Streams the result of /elements, /elementsFullHistory and /contributions endpoints as an outputstream.
      void writeCsvResponse​(GroupByObject[] resultSet, javax.servlet.http.HttpServletResponse servletResponse, List<String[]> comments)
      Writes a response in the csv format for /groupBy requests.
      void writeCsvResponse​(Result[] resultSet, javax.servlet.http.HttpServletResponse servletResponse, List<String[]> comments)
      Writes a response in the csv format for /count|length|perimeter|area(/density)(/ratio) requests.
    • Constructor Detail

      • ExecutionUtils

        public ExecutionUtils​(ProcessingData processingData)
    • Method Detail

      • snapshotFilter

        public org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer<org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> snapshotFilter​(org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer<org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapRed,
                                                                                                                                                      Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes1,
                                                                                                                                                      Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes2,
                                                                                                                                                      Set<SimpleFeatureType> simpleFeatureTypes1,
                                                                                                                                                      Set<SimpleFeatureType> simpleFeatureTypes2,
                                                                                                                                                      Integer[] keysInt1,
                                                                                                                                                      Integer[] keysInt2,
                                                                                                                                                      Integer[] valuesInt1,
                                                                                                                                                      Integer[] valuesInt2)
        Applies a filter on the given MapReducer object using the given parameters.
      • snapshotFilter

        public org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> snapshotFilter​(org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapRed,
                                                                                                                                                                                                                                                                                                 Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes1,
                                                                                                                                                                                                                                                                                                 Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes2,
                                                                                                                                                                                                                                                                                                 Set<SimpleFeatureType> simpleFeatureTypes1,
                                                                                                                                                                                                                                                                                                 Set<SimpleFeatureType> simpleFeatureTypes2,
                                                                                                                                                                                                                                                                                                 Integer[] keysInt1,
                                                                                                                                                                                                                                                                                                 Integer[] keysInt2,
                                                                                                                                                                                                                                                                                                 Integer[] valuesInt1,
                                                                                                                                                                                                                                                                                                 Integer[] valuesInt2)
        Applies a filter on the given MapReducer object using the given parameters. Used in /ratio/groupBy/boundary requests.
      • snapshotMatches

        public boolean snapshotMatches​(org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot snapshot,
                                       Set<org.heigit.bigspatialdata.oshdb.osm.OSMType> osmTypes,
                                       Set<SimpleFeatureType> simpleFeatureTypes,
                                       Integer[] keysInt,
                                       Integer[] valuesInt)
        Compares the type(s) and tag(s) of the given snapshot to the given types|tags.
      • defineDecimalFormat

        public static DecimalFormat defineDecimalFormat​(String format)
        Defines a certain decimal format.
        Parameters:
        format - String defining the format (e.g.: "#.####" for getting 4 digits after the comma)
        Returns:
        DecimalFormat object with the defined format.
      • cacheInUserData

        public static Double cacheInUserData​(org.locationtech.jts.geom.Geometry geom,
                                             org.heigit.bigspatialdata.oshdb.api.generic.function.SerializableSupplier<Double> mapper)
        Caches the given mapper value in the user data of the Geometry object.
        Parameters:
        geom - Geometry of an OSMEntitySnapshot object
        mapper - arbitrary function that returns a time-independent value from a snapshot object, for example lenght, area, perimeter
        Returns:
        evaluated mapper function or cached value stored in the user data of the Geometry object
      • nest

        public static <A,​U extends Comparable<U> & Serializable,​V extends Comparable<V> & SerializableSortedMap<V,​SortedMap<U,​A>> nest​(Map<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<U,​V>,​A> result)
        Adapted helper function, which works like nest but has switched <U> and <V> parameters.
        Type Parameters:
        A - an arbitrary data type, used for the data value items
        U - an arbitrary data type, used for the index'es key items
        V - an arbitrary data type, used for the index'es key items
        Parameters:
        result - the "flat" result data structure that should be converted to a nested structure
        Returns:
        a nested data structure: for each index part there is a separate level of nested maps
      • writeCsvResponse

        public void writeCsvResponse​(GroupByObject[] resultSet,
                                     javax.servlet.http.HttpServletResponse servletResponse,
                                     List<String[]> comments)
        Writes a response in the csv format for /groupBy requests.
      • writeCsvResponse

        public void writeCsvResponse​(Result[] resultSet,
                                     javax.servlet.http.HttpServletResponse servletResponse,
                                     List<String[]> comments)
        Writes a response in the csv format for /count|length|perimeter|area(/density)(/ratio) requests.
      • setRequestedSimpleFeatures

        public boolean[] setRequestedSimpleFeatures​(Set<SimpleFeatureType> simpleFeatureTypes)
        Sets the boolean values for the respective simple feature type: 0 = hasPoint, 1 = hasLine, 2 = hasPolygon, 3 = hasOther.
      • createCsvTopComments

        public List<String[]> createCsvTopComments​(String url,
                                                   String text,
                                                   String apiVersion,
                                                   Metadata metadata)
        Creates the comments of the csv response (Attribution, API-Version and optional Metadata).
      • createOSMFeature

        public org.wololo.geojson.Feature createOSMFeature​(org.heigit.bigspatialdata.oshdb.osm.OSMEntity entity,
                                                           org.locationtech.jts.geom.Geometry geometry,
                                                           Map<String,​Object> properties,
                                                           Set<Integer> keysInt,
                                                           boolean includeTags,
                                                           boolean includeOSMMetadata,
                                                           boolean isContributionsEndpoint,
                                                           ElementsGeometry elemGeom,
                                                           EnumSet<org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType> contributionTypes)
        Creates the Feature objects in the OSM data response.
      • computeResult

        public <K extends Comparable<K> & Serializable,​V extends NumberSortedMap<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​K>,​V> computeResult​(RequestResource requestResource,
                                                                                                                                                                                                                                            org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​K>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> preResult)
                                                                                                                                                                                                                                     throws Exception
        Computes the result depending on the RequestResource using a MapAggregator object as input and returning a SortedMap.
        Throws:
        Exception - thrown by #count() count, and sum
      • computeNestedResult

        public <K extends Comparable<K> & Serializable,​V extends NumberSortedMap<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<Integer,​K>,​org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp>,​V> computeNestedResult​(RequestResource requestResource,
                                                                                                                                                                                                                                                                                                                                org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<Integer,​K>,​org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp>,​org.locationtech.jts.geom.Geometry> preResult)
                                                                                                                                                                                                                                                                                                                         throws Exception
        Computes the result depending on the RequestResource using a MapAggregator object as input and returning a SortedMap.
        Throws:
        Exception
      • extractContributionTags

        public int[] extractContributionTags​(org.heigit.bigspatialdata.oshdb.api.object.OSMContribution contrib)
        Extracts the tags from the given OSMContribution depending on the ContributionType.
      • fillElementsResult

        public ElementsResult[] fillElementsResult​(SortedMap<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​? extends Number> entryVal,
                                                   boolean isDensity,
                                                   DecimalFormat df,
                                                   org.locationtech.jts.geom.Geometry geom)
        Fills the ElementsResult array with respective ElementsResult objects.
      • fillContributionsResult

        public ContributionsResult[] fillContributionsResult​(SortedMap<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​? extends Number> entryVal,
                                                             boolean isDensity,
                                                             InputProcessor inputProcessor,
                                                             DecimalFormat df,
                                                             org.locationtech.jts.geom.Geometry geom)
        Fills the ContributionsResult array with respective ContributionsResult objects.
      • fillElementsRatioGroupByBoundaryResultValues

        public Double[] fillElementsRatioGroupByBoundaryResultValues​(Set<? extends Map.Entry<org.heigit.bigspatialdata.oshdb.api.generic.OSHDBCombinedIndex<org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp,​Integer>,​? extends Number>> resultSet,
                                                                     DecimalFormat df)
        Fills the result value arrays for the ratio/groupBy/boundary response.
        Parameters:
        resultSet - Set containing the result values
        df - DecimalFormat defining the number of digits of the result values
        Returns:
        Double[] containing the formatted result values
      • mapSnapshotToTags

        public org.apache.commons.lang3.tuple.Pair<org.apache.commons.lang3.tuple.Pair<Integer,​Integer>,​org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot> mapSnapshotToTags​(int keysInt,
                                                                                                                                                                                                    Integer[] valuesInt,
                                                                                                                                                                                                    org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot f)
        Maps the given OSMEntitySnapshot to a given tag, or to the remainder (having -1, -1 as identifier) if none of the given tags is included.
        Parameters:
        keysInt - int value of the groupByKey parameter
        valuesInt - Integer[] of the groupByValues parameter
        f - OSMEntitySnapshot
        Returns:
        nested Pair containing the integer values of the tag category and the OSMEntitySnapshot
      • createRatioResponse

        public Response createRatioResponse​(String[] timeArray,
                                            Double[] value1,
                                            Double[] value2,
                                            long startTime,
                                            RequestResource reqRes,
                                            String requestUrl,
                                            javax.servlet.http.HttpServletResponse servletResponse)
        Creates a RatioResponse.
      • createRatioGroupByBoundaryResponse

        public Response createRatioGroupByBoundaryResponse​(Object[] boundaryIds,
                                                           String[] timeArray,
                                                           Double[] resultValues1,
                                                           Double[] resultValues2,
                                                           long startTime,
                                                           RequestResource reqRes,
                                                           String requestUrl,
                                                           javax.servlet.http.HttpServletResponse servletResponse)
        Creates a RatioGroupByBoundaryResponse.
      • getGeometry

        public org.locationtech.jts.geom.Geometry getGeometry​(org.heigit.bigspatialdata.oshdb.api.object.OSMContribution contribution,
                                                              boolean clipGeometries,
                                                              boolean before)
        Extracts and returns a geometry out of the given contribution. The boolean values specify if it should be clipped/unclipped and if the geometry before/after a contribution should be taken.
      • combineFiltersWithOr

        public String combineFiltersWithOr​(String firstFilter,
                                           String secondFilter)
        Combines the two given filters with an OR operation. Used in /ratio computation.