forked from podolaceklukas/assignment-gis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update libraries to work with latest node version
- Loading branch information
1 parent
6f74645
commit ff2fa27
Showing
10 changed files
with
5,574 additions
and
4,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,7 @@ typings/ | |
.env | ||
|
||
# next.js build output | ||
.next | ||
.next | ||
|
||
# osm pbf file | ||
osm2pgsql/map.osm.pbf |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 109 additions & 107 deletions
216
pdt-marinehelper-server/api/controllers/covesController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,172 @@ | ||
const db = require("../../db"); | ||
|
||
exports.getAllAnchorages = (req, res, next) => { | ||
exports.getAllAnchorages = async (req, res, next) => { | ||
const SELECT_ANCHORAGES_QUERY = | ||
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ST_AsGeoJSON(ST_Transform(way, 4326)) AS center ' + | ||
"FROM planet_osm_point " + | ||
"WHERE \"seamark:type\" = 'anchorage'"; | ||
` | ||
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ST_AsGeoJSON(ST_Transform(way, 4326)) AS center | ||
FROM planet_osm_point | ||
WHERE "seamark:type" = 'anchorage' | ||
`; | ||
|
||
db.query(SELECT_ANCHORAGES_QUERY, [], (err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
try { | ||
const dbOut = await db.query(SELECT_ANCHORAGES_QUERY) | ||
|
||
const result = res1.rows.map(row => { | ||
const result = dbOut?.rows?.map?.(row => { | ||
const center = JSON.parse(row.center); | ||
return { ...row, center }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "anchorages fetched", | ||
result: result, | ||
error: err | ||
result, | ||
}); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
exports.getNearbyAnchorages = (req, res, next) => { | ||
exports.getNearbyAnchorages = async (req, res, next) => { | ||
const { lat, lng, maxDistance } = req.query; | ||
const SELECT_ANCHORAGES_QUERY = | ||
"WITH pos AS ( "+ | ||
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+ | ||
") "+ | ||
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ' + | ||
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, " + | ||
"ST_Distance(pos.pos, ST_Transform(way, 4326)) AS st_distance " + | ||
"FROM planet_osm_point, pos pos " + | ||
"WHERE \"seamark:type\" = 'anchorage' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" + | ||
"ORDER BY st_distance"; | ||
|
||
db.query(SELECT_ANCHORAGES_QUERY, [maxDistance, lng, lat], (err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
const result = res1.rows.map(row => { | ||
` | ||
WITH pos AS ( | ||
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos | ||
) | ||
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", | ||
ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, | ||
ST_Distance(pos.pos, ST_Transform(way, 4326)) AS st_distance | ||
FROM planet_osm_point, pos pos | ||
WHERE "seamark:type" = 'anchorage' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int) | ||
ORDER BY st_distance | ||
`; | ||
|
||
try { | ||
const dbOut = await db.query(SELECT_ANCHORAGES_QUERY, [maxDistance, lng, lat]) | ||
|
||
const result = dbOut?.rows?.map?.(row => { | ||
const center = JSON.parse(row.center); | ||
return { ...row, center }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "anchorages fetched", | ||
result: result, | ||
error: err | ||
result, | ||
}); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
exports.getAllMoorings = (req, res, next) => { | ||
exports.getAllMoorings = async (req, res, next) => { | ||
const SELECT_MOORINGS_QUERY = | ||
'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as center ' + | ||
"FROM planet_osm_point " + | ||
"WHERE \"seamark:type\" = 'mooring'"; | ||
` | ||
SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as center | ||
FROM planet_osm_point | ||
WHERE "seamark:type" = 'mooring' | ||
`; | ||
|
||
db.query(SELECT_MOORINGS_QUERY, [], (err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
try { | ||
const dbOut = await db.query(SELECT_MOORINGS_QUERY) | ||
|
||
const result = res1.rows.map(row => { | ||
const result = dbOut?.rows?.map?.(row => { | ||
const center = JSON.parse(row.center); | ||
return { ...row, center }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "moorings fetched", | ||
result: result, | ||
error: err | ||
result, | ||
}); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
exports.getNearbyMoorings = (req, res, next) => { | ||
exports.getNearbyMoorings = async (req, res, next) => { | ||
const { lat, lng, maxDistance } = req.query; | ||
const SELECT_MOORINGS_QUERY = | ||
"WITH pos AS ( "+ | ||
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+ | ||
") "+ | ||
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ' + | ||
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, " + | ||
"ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance " + | ||
"FROM planet_osm_point, pos pos " + | ||
"WHERE \"seamark:type\" = 'mooring' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" + | ||
"ORDER BY st_distance"; | ||
|
||
db.query(SELECT_MOORINGS_QUERY, [maxDistance, lng, lat], (err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
const result = res1.rows.map(row => { | ||
` | ||
WITH pos AS ( | ||
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos | ||
) | ||
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", | ||
ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, | ||
ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance | ||
FROM planet_osm_point, pos pos | ||
WHERE "seamark:type" = 'mooring' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int) | ||
ORDER BY st_distance | ||
`; | ||
|
||
try { | ||
const dbOut = await db.query(SELECT_MOORINGS_QUERY, [maxDistance, lng, lat]) | ||
|
||
const result = dbOut?.rows?.map?.(row => { | ||
const center = JSON.parse(row.center); | ||
return { ...row, center }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "moorings fetched", | ||
result: result, | ||
error: err | ||
result, | ||
}); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
exports.getAllUnderwaterCablesAndPipes = (req, res, next) => { | ||
exports.getAllUnderwaterCablesAndPipes = async (req, res, next) => { | ||
const SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY = | ||
'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geometry ' + | ||
"FROM planet_osm_line " + | ||
"WHERE \"seamark:type\" = 'pipeline_submarine' OR \"seamark:type\" = 'cable_submarine'"; | ||
` | ||
SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geometry | ||
FROM planet_osm_line | ||
WHERE "seamark:type" = 'pipeline_submarine' OR "seamark:type" = 'cable_submarine' | ||
`; | ||
|
||
db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, [], (err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
try { | ||
const dbOut = await db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY) | ||
|
||
const result = res1.rows.map(row => { | ||
const result = dbOut?.rows?.map?.(row => { | ||
const geometry = JSON.parse(row.geometry); | ||
return { ...row, geometry }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "underwater cables and pipes fetched", | ||
result: result, | ||
error: err | ||
result, | ||
}); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
exports.getNearbyUnderwaterCablesAndPipes = (req, res, next) => { | ||
exports.getNearbyUnderwaterCablesAndPipes = async (req, res, next) => { | ||
const { lat, lng, maxDistance } = req.query; | ||
const SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY = | ||
"WITH pos AS ( "+ | ||
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+ | ||
") "+ | ||
'SELECT osm_id, "seamark:type", "seamark:name", ' + | ||
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry, " + | ||
"ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance " + | ||
"FROM planet_osm_line, pos pos " + | ||
"WHERE (\"seamark:type\" = 'pipeline_submarine' OR \"seamark:type\" = 'cable_submarine') AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" + | ||
"ORDER BY st_distance"; | ||
|
||
db.query( | ||
SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, | ||
[maxDistance, lng, lat], | ||
(err, res1) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
const result = res1.rows.map(row => { | ||
const geometry = JSON.parse(row.geometry); | ||
return { ...row, geometry }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "underwater cables and pipes fetched", | ||
result: result, | ||
error: err | ||
}); | ||
} | ||
); | ||
` | ||
WITH pos AS ( | ||
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos | ||
) | ||
SELECT osm_id, "seamark:type", "seamark:name", | ||
ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry, | ||
ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance | ||
FROM planet_osm_line, pos pos | ||
WHERE ("seamark:type" = 'pipeline_submarine' OR "seamark:type" = 'cable_submarine') AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int) | ||
ORDER BY st_distance | ||
`; | ||
|
||
try { | ||
const dbOut = await db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, [maxDistance, lng, lat]) | ||
|
||
const result = dbOut?.rows?.map?.(row => { | ||
const geometry = JSON.parse(row.geometry); | ||
return { ...row, geometry }; | ||
}); | ||
|
||
res.status(200).json({ | ||
message: "underwater cables and pipes fetched", | ||
result, | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; |
Oops, something went wrong.