Skip to content

Commit

Permalink
implementing /elements/geom
Browse files Browse the repository at this point in the history
gives only the geometry of the OSM-data objects
changing default value of osmMetadata to ‘false’
removing of “Raw” within method names and descriptions
  • Loading branch information
FabiKo117 committed Oct 4, 2018
1 parent 3aa72fd commit dd7d2a9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ParameterDescriptions {
public static final String FORMAT_DESCR = "Output format, e.g.: geojson; default: json";
public static final String OSM_METADATA_DESCR =
"'Boolean' operator 'true or 'false'; default: 'true'";
public static final String INCLUDE_TAGS_DESCR =
"'Boolean' operator 'true or 'false'; default: 'false'";
public static final String SHOW_METADATA_DESCR =
"'Boolean' operator 'true' or 'false'; default: 'false'";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class ElementsController {

/**
* Gives raw OSM objects as GeoJSON features.
* Gives the OSM objects as GeoJSON features.
*
* <p>
* The parameters are described in the
Expand All @@ -36,12 +36,14 @@ public class ElementsController {
* @return {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.output.dataaggregationresponse.Response
* Response}
*/
@ApiOperation(value = "Raw OSM Data", nickname = "rawData")
@ApiOperation(value = "OSM Data", nickname = "rawData")
@ApiImplicitParams({
@ApiImplicitParam(name = "OSMMetadata", value = ParameterDescriptions.OSM_METADATA_DESCR,
defaultValue = "true", paramType = "query", dataType = "string", required = false)})
@ApiImplicitParam(name = "osmMetadata", value = ParameterDescriptions.OSM_METADATA_DESCR,
defaultValue = "false", paramType = "query", dataType = "string", required = false),
@ApiImplicitParam(name = "includeTags", value = ParameterDescriptions.INCLUDE_TAGS_DESCR,
defaultValue = "false", paramType = "query", dataType = "string", required = false)})
@RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST})
public void retrieveRawData(
public void retrieveOSMData(
@ApiParam(hidden = true) @RequestParam(value = "bboxes", defaultValue = "",
required = false) String bboxes,
@ApiParam(hidden = true) @RequestParam(value = "bcircles", defaultValue = "",
Expand All @@ -67,8 +69,55 @@ public void retrieveRawData(
@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),
osmMetadata, includeTags, false, response);
}

/**
* Gives the geometry of OSM objects 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.
*
* @return {@link org.heigit.bigspatialdata.ohsome.ohsomeapi.output.dataaggregationresponse.Response
* Response}
*/
@ApiOperation(value = "Geometry of OSM Data", nickname = "geomData")
@ApiImplicitParams({
@ApiImplicitParam(name = "osmMetadata", value = ParameterDescriptions.OSM_METADATA_DESCR,
defaultValue = "false", paramType = "query", dataType = "string", required = false)})
@RequestMapping(value = "/geom", method = {RequestMethod.GET, RequestMethod.POST})
public void retrieveGeomData(
@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 = "osmMetadata", defaultValue = "",
required = false) String osmMetadata,
@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), osmMetadata,
includeTags, response);
"", true, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter;
import org.wololo.geojson.Feature;
import org.wololo.jts2geojson.GeoJSONWriter;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
Expand All @@ -77,7 +78,7 @@ public class ElementsRequestExecutor {
* a stream.
*/
public static void executeElements(RequestParameters requestParams, String osmMetadata,
String includeOSMTags, HttpServletResponse response)
String includeOSMTags, boolean isGeom, HttpServletResponse response)
throws UnsupportedOperationException, Exception {
final long startTime = System.currentTimeMillis();
MapReducer<OSMEntitySnapshot> mapRed = null;
Expand All @@ -88,10 +89,10 @@ public static void executeElements(RequestParameters requestParams, String osmMe
}
final boolean includeOSMMetadata;
if (osmMetadata != null
&& (osmMetadata.equalsIgnoreCase("false") || osmMetadata.equalsIgnoreCase("no"))) {
includeOSMMetadata = false;
} else {
&& (osmMetadata.equalsIgnoreCase("true") || osmMetadata.equalsIgnoreCase("yes"))) {
includeOSMMetadata = true;
} else {
includeOSMMetadata = false;
}
final boolean includeTags;
if (includeOSMTags != null
Expand Down Expand Up @@ -126,14 +127,20 @@ public static void executeElements(RequestParameters requestParams, String osmMe
properties.put("version", snapshot.getEntity().getVersion());
properties.put("osmId", snapshot.getEntity().getType().toString().toLowerCase() + "/"
+ snapshot.getEntity().getId());
return exeUtils.createOSMDataFeature(keys, values, tt, keysInt, valuesInt, snapshot,
properties, gjw, includeTags);
if (!isGeom) {
return exeUtils.createOSMDataFeature(keys, values, tt, keysInt, valuesInt, snapshot,
properties, gjw, includeTags);
}
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry()), properties);
});
} else {
preResult = mapRed.map(snapshot -> {
Map<String, Object> properties = new TreeMap<>();
return exeUtils.createOSMDataFeature(keys, values, tt, keysInt, valuesInt, snapshot,
properties, gjw, includeTags);
if (!isGeom) {
return exeUtils.createOSMDataFeature(keys, values, tt, keysInt, valuesInt, snapshot,
properties, gjw, includeTags);
}
return new org.wololo.geojson.Feature(gjw.write(snapshot.getGeometry()), null);
});
}
result = preResult.collect();
Expand All @@ -152,25 +159,12 @@ public static void executeElements(RequestParameters requestParams, String osmMe
JsonGenerator jsonGen = jsonFactory.createGenerator(stream, JsonEncoding.UTF8);
ObjectMapper objMapper = new ObjectMapper();
objMapper.enable(SerializationFeature.INDENT_OUTPUT);
objMapper.setSerializationInclusion(Include.NON_NULL);
jsonGen.setCodec(objMapper);
jsonGen.writeObject(osmData);
response.flushBuffer();
}

/**
* Performs an OSM data extraction, where only the geometry of each object is returned.
*
* <p>
*
* @param requestParams <code>RequestParameters</code> object, which holds those parameters that
* are used in every request.
* @param response <code>HttpServletResponse</code> object, which is used to send the response as
* a stream.
*/
public static void executeElementsGeom() {

}

/**
* Performs a count|length|perimeter|area calculation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void postElementsUsingNoTagsTest() {
map.add("bboxes", "8.67452,49.40961,8.70392,49.41823");
map.add("types", "node");
map.add("time", "2016-02-05");
map.add("osmMetadata", "yes");
ResponseEntity<JsonNode> response =
restTemplate.postForEntity(server + port + "/elements", map, JsonNode.class);
assertTrue(response.getBody().get("features").get(0).get("properties").get("osmId").asText()
Expand All @@ -49,19 +50,19 @@ public void getElementsUsingOneTagTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/elements?bboxes=8.67452,49.40961,8.70392,49.41823&types=way&keys=building"
+ "&values=residential&time=2015-12-01",
+ "&values=residential&time=2015-12-01&osmMetadata=true",
JsonNode.class);
assertTrue(response.getBody().get("features").get(0).get("properties").get("osmId").asText()
.equals("way/140112811"));
}

// setting multiple tags
@Test
public void getElementsUsingMultipleTagsTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/elements?bboxes=8.67559,49.40853,8.69379,49.4231&types=way&keys=highway,"
+ "name,maxspeed&values=residential&time=2015-10-01",
+ "name,maxspeed&values=residential&time=2015-10-01&osmMetadata=true",
JsonNode.class);
assertTrue(response.getBody().get("features").get(0).get("properties").get("osmId").asText()
.equals("way/4084860"));
Expand Down

0 comments on commit dd7d2a9

Please sign in to comment.