Skip to content

Commit

Permalink
implement /elements/bbox and /elements/centroid
Browse files Browse the repository at this point in the history
which provides the bbox or centroid for each osm object as geometry
  • Loading branch information
FabiKo117 committed Oct 22, 2018
1 parent f086380 commit f40f91d
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,108 @@ public void retrieveOSMData(
@ApiParam(hidden = true) HttpServletRequest request,
@ApiParam(hidden = true) HttpServletResponse response)
throws UnsupportedOperationException, Exception {
ElementsRequestExecutor.executeElements(new RequestParameters(request.getMethod(), true, false,
bboxes, bcircles, bpolys, types, keys, values, userids, time, showMetadata), properties,
response);
ElementsRequestExecutor
.executeElements(
new RequestParameters(request.getMethod(), true, false, bboxes, bcircles, bpolys, types,
keys, values, userids, time, showMetadata),
ElementsGeometry.RAW, properties, response);
}

/**
* Gives the OSM objects with their bounding box in the geometry field as GeoJSON features.
*
* <p>
* The parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.controller.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param properties <code>String</code> array defining what types of properties should be
* included within the properties response field. It can contain "tags" and/or "metadata",
* meaning that it would add the OSM-tags or metadata of the respective OSM object to the
* properties.
* @return {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.output.dataaggregationresponse.Response
* Response}
*/
@ApiOperation(value = "OSM Data", nickname = "rawDataBbox")
@ApiImplicitParam(name = "properties", value = ParameterDescriptions.PROPERTIES_DESCR,
defaultValue = "tags", paramType = "query", dataType = "string", required = false)
@RequestMapping(value = "/bbox", method = {RequestMethod.GET, RequestMethod.POST})
public void retrieveOSMDataWithBBox(
@ApiParam(hidden = true) @RequestParam(value = "bboxes", defaultValue = "",
required = false) String bboxes,
@ApiParam(hidden = true) @RequestParam(value = "bcircles", defaultValue = "",
required = false) String bcircles,
@ApiParam(hidden = true) @RequestParam(value = "bpolys", defaultValue = "",
required = false) String bpolys,
@ApiParam(hidden = true) @RequestParam(value = "types", defaultValue = "",
required = false) String[] types,
@ApiParam(hidden = true) @RequestParam(value = "keys", defaultValue = "",
required = false) String[] keys,
@ApiParam(hidden = true) @RequestParam(value = "values", defaultValue = "",
required = false) String[] values,
@ApiParam(hidden = true) @RequestParam(value = "userids", defaultValue = "",
required = false) String[] userids,
@ApiParam(hidden = true) @RequestParam(value = "time", defaultValue = "",
required = false) String[] time,
@ApiParam(hidden = true) @RequestParam(value = "properties", defaultValue = "",
required = false) String[] properties,
@ApiParam(hidden = true) @RequestParam(value = "showMetadata",
defaultValue = "false") String showMetadata,
@ApiParam(hidden = true) HttpServletRequest request,
@ApiParam(hidden = true) HttpServletResponse response)
throws UnsupportedOperationException, Exception {
ElementsRequestExecutor.executeElements(
new RequestParameters(request.getMethod(), true, false, bboxes, bcircles, bpolys, types,
keys, values, userids, time, showMetadata),
ElementsGeometry.BBOX, properties, response);
}

/**
* Gives the OSM objects with their centroid in the geometry field as GeoJSON features.
*
* <p>
* The parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.controller.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param properties <code>String</code> array defining what types of properties should be
* included within the properties response field. It can contain "tags" and/or "metadata",
* meaning that it would add the OSM-tags or metadata of the respective OSM object to the
* properties.
* @return {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.output.dataaggregationresponse.Response
* Response}
*/
@ApiOperation(value = "OSM Data", nickname = "rawDataCentroid")
@ApiImplicitParam(name = "properties", value = ParameterDescriptions.PROPERTIES_DESCR,
defaultValue = "tags", paramType = "query", dataType = "string", required = false)
@RequestMapping(value = "/centroid", method = {RequestMethod.GET, RequestMethod.POST})
public void retrieveOSMDataWithCentroid(
@ApiParam(hidden = true) @RequestParam(value = "bboxes", defaultValue = "",
required = false) String bboxes,
@ApiParam(hidden = true) @RequestParam(value = "bcircles", defaultValue = "",
required = false) String bcircles,
@ApiParam(hidden = true) @RequestParam(value = "bpolys", defaultValue = "",
required = false) String bpolys,
@ApiParam(hidden = true) @RequestParam(value = "types", defaultValue = "",
required = false) String[] types,
@ApiParam(hidden = true) @RequestParam(value = "keys", defaultValue = "",
required = false) String[] keys,
@ApiParam(hidden = true) @RequestParam(value = "values", defaultValue = "",
required = false) String[] values,
@ApiParam(hidden = true) @RequestParam(value = "userids", defaultValue = "",
required = false) String[] userids,
@ApiParam(hidden = true) @RequestParam(value = "time", defaultValue = "",
required = false) String[] time,
@ApiParam(hidden = true) @RequestParam(value = "properties", defaultValue = "",
required = false) String[] properties,
@ApiParam(hidden = true) @RequestParam(value = "showMetadata",
defaultValue = "false") String showMetadata,
@ApiParam(hidden = true) HttpServletRequest request,
@ApiParam(hidden = true) HttpServletResponse response)
throws UnsupportedOperationException, Exception {
ElementsRequestExecutor.executeElements(
new RequestParameters(request.getMethod(), true, false, bboxes, bcircles, bpolys, types,
keys, values, userids, time, showMetadata),
ElementsGeometry.CENTROID, properties, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.heigit.bigspatialdata.ohsome.ohsomeapi.controller.rawdata;

/** Enumeration defining the geometry of the OSM elements(RAW, BBOX, CENTROID). */
public enum ElementsGeometry {

RAW, BBOX, CENTROID
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.geojson.GeoJsonObject;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.Application;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.controller.rawdata.ElementsGeometry;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.exception.BadRequestException;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.executor.ExecutionUtils.MatchType;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.inputprocessing.BoundaryType;
Expand Down Expand Up @@ -85,8 +86,9 @@ public class ElementsRequestExecutor {
* @param response <code>HttpServletResponse</code> object, which is used to send the response as
* a stream.
*/
public static void executeElements(RequestParameters requestParams, String[] propertiesParameter,
HttpServletResponse response) throws UnsupportedOperationException, Exception {
public static void executeElements(RequestParameters requestParams, ElementsGeometry elemGeom,
String[] propertiesParameter, HttpServletResponse response)
throws UnsupportedOperationException, Exception {
MapReducer<OSMEntitySnapshot> mapRed = null;
InputProcessor inputProcessor = new InputProcessor();
String requestUrl = null;
Expand Down Expand Up @@ -150,13 +152,13 @@ public static void executeElements(RequestParameters requestParams, String[] pro
properties.put("lastEdit", snapshot.getEntity().getTimestamp().toString());
properties.put("changesetId", snapshot.getEntity().getChangesetId());
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, snapshot, properties, gjw, includeTags);
valuesInt, snapshot, properties, gjw, includeTags, elemGeom);
});
} else {
preResult = mapRed.map(snapshot -> {
Map<String, Object> properties = new TreeMap<>();
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, snapshot, properties, gjw, includeTags);
valuesInt, snapshot, properties, gjw, includeTags, elemGeom);
});
}
Stream<Feature> streamResult = preResult.stream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.geojson.Feature;
import org.geojson.GeoJsonObject;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.Application;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.controller.rawdata.ElementsGeometry;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.exception.BadRequestException;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.inputprocessing.BoundaryType;
import org.heigit.bigspatialdata.ohsome.ohsomeapi.inputprocessing.GeometryBuilder;
Expand Down Expand Up @@ -41,14 +42,17 @@
import org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMType;
import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTag;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp;
import org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType;
import org.heigit.bigspatialdata.oshdb.util.geometry.Geo;
import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.OSMTag;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.TagTranslator;
import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter;
import org.wololo.jts2geojson.GeoJSONWriter;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygonal;

Expand Down Expand Up @@ -101,7 +105,8 @@ public Geometry getGeometry(BoundaryType boundary, GeometryBuilder geomBuilder)
/** Creates the <code>Feature</code> objects in the OSM data response. */
public org.wololo.geojson.Feature createOSMDataFeature(String[] keys, String[] values,
TagTranslator tt, int[] keysInt, int[] valuesInt, OSMEntitySnapshot snapshot,
Map<String, Object> properties, GeoJSONWriter gjw, boolean includeTags) {
Map<String, Object> properties, GeoJSONWriter gjw, boolean includeTags,
ElementsGeometry elemGeom) {
properties.put("snapshotTimestamp", snapshot.getTimestamp().toString());
properties.put("osmId", snapshot.getEntity().getType().toString().toLowerCase() + "/"
+ snapshot.getEntity().getId());
Expand All @@ -123,7 +128,20 @@ public org.wololo.geojson.Feature createOSMDataFeature(String[] keys, String[] v
}
}
}
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry()), properties);
switch (elemGeom) {
case RAW:
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry()), properties);
case BBOX:
Envelope envelope = snapshot.getGeometry().getEnvelopeInternal();
OSHDBBoundingBox bbox = OSHDBGeometryBuilder.boundingBoxOf(envelope);
return new org.wololo.geojson.Feature(gjw.write(OSHDBGeometryBuilder.getGeometry(bbox)),
properties);
case CENTROID:
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry().getCentroid()),
properties);
default:
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry()), properties);
}
}

/** Computes the result for the /count|length|perimeter|area/groupBy/boundary resources. */
Expand Down

0 comments on commit f40f91d

Please sign in to comment.