Skip to content

Commit

Permalink
PRC-979: added CRS to support query area larger than single hemispher…
Browse files Browse the repository at this point in the history
…e + added support for geoWithin box query
  • Loading branch information
severinbeauvais committed Jan 11, 2019
1 parent 582f427 commit b6b15a2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions api/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,34 @@ var addStandardQueryFilters = function (query, args) {
if (args.swagger.params.centroid && args.swagger.params.centroid.value !== undefined) {
// defaultLog.info("Looking up features based on coords:", args.swagger.params.centroid.value);
// Throws if parsing fails.
_.assignIn(query, {
centroid: { $geoIntersects: { $geometry: { type: "Polygon", coordinates: JSON.parse(args.swagger.params.centroid.value) } } }
});
const coordinates = JSON.parse(args.swagger.params.centroid.value)[0];
if (coordinates.length == 2) {
// use geoWithin box query
_.assignIn(query, {
centroid: {
$geoWithin: {
$box: coordinates
}
}
});
} else {
// use geoIntersects polygon query
// specify custom MongoDB CRS to support queries with area larger than a single hemisphere
_.assignIn(query, {
centroid: {
$geoIntersects: {
$geometry: {
type: "Polygon",
coordinates: [coordinates],
crs: {
type: "name",
properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
}
}
}
}
});
}
}
// Allows filtering of apps that have had their last status change greater than this epoch time.
if (args.swagger.params.statusHistoryEffectiveDate && args.swagger.params.statusHistoryEffectiveDate !== undefined) {
Expand Down

0 comments on commit b6b15a2

Please sign in to comment.