Skip to content

Commit

Permalink
Merge pull request #125 from NASA-AMMOS/MMGIS-2.5.0
Browse files Browse the repository at this point in the history
MMGIS 2.5.0
  • Loading branch information
fcalef authored Jan 19, 2022
2 parents d0ef1d5 + b39f36d commit 375a6aa
Show file tree
Hide file tree
Showing 100 changed files with 13,992 additions and 4,881 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Missions
Missions_rel
Missions_dev
.env
**/.git
**/.git
data
*DS_Store
*__pycache__
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/src/pre/tools.js

/build/*
/data/*
*__pycache__

sessions

Expand Down
29 changes: 20 additions & 9 deletions API/Backend/Draw/models/published.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,50 @@ const { sequelize } = require("../../../connection");
const attributes = {
intent: {
type: Sequelize.ENUM,
values: ["roi", "campaign", "campsite", "trail", "signpost"],
values: [
"roi",
"campaign",
"campsite",
"trail",
"signpost",
"polygon",
"line",
"point",
"text",
"arrow",
],
allowNull: false,
unique: false,
defaultValue: null
defaultValue: null,
},
parent: {
type: Sequelize.DataTypes.INTEGER,
unique: false,
allowNull: true
allowNull: true,
},
children: {
type: Sequelize.DataTypes.ARRAY(Sequelize.DataTypes.INTEGER),
unique: false,
allowNull: true
allowNull: true,
},
level: {
type: Sequelize.INTEGER,
unique: false,
allowNull: false
allowNull: false,
},
properties: {
type: Sequelize.JSON,
allowNull: true,
defaultValue: {}
defaultValue: {},
},
geom: {
type: Sequelize.GEOMETRY,
allowNull: true
}
allowNull: true,
},
};

const options = {
timestamps: false
timestamps: false,
};

var Published = sequelize.define("publisheds", attributes, options);
Expand Down
143 changes: 84 additions & 59 deletions API/Backend/Draw/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ router.post("/getfile", function (req, res, next) {
(req.body.test === "true" ? "publisheds_test" : "publisheds") +
"" +
(req.body.intent && req.body.intent.length > 0
? " WHERE intent=:intent"
? req.body.intent === "all"
? " WHERE intent IN ('polygon', 'line', 'point', 'text', 'arrow')"
: " WHERE intent=:intent"
: ""),
{
replacements: {
Expand Down Expand Up @@ -698,7 +700,14 @@ const compile = function (req, res, callback) {
where: {
is_master: true,
intent: {
[Sequelize.Op.in]: ["roi", "campaign", "campsite", "trail", "signpost"],
[Sequelize.Op.in]: [
"roi",
"campaign",
"campsite",
"trail",
"signpost",
"all",
],
},
},
}).then((files) => {
Expand Down Expand Up @@ -775,11 +784,11 @@ const compile = function (req, res, callback) {
" " +
"AND a.id != b.id" +
" " +
"AND ((ST_OVERLAPS(a.geom, b.geom)" +
"AND ((ST_OVERLAPS(ST_BUFFER(a.geom, -0.000005, 'join=mitre'), b.geom)" +
" " +
"AND NOT ST_Touches(a.geom, b.geom))" +
" " +
"OR ST_CROSSES(a.geom, b.geom))" +
"OR ST_CROSSES(ST_BUFFER(a.geom, -0.000005, 'join=mitre'), b.geom))" +
" " +
"UNION ALL" +
" " +
Expand Down Expand Up @@ -810,6 +819,7 @@ const compile = function (req, res, callback) {
.spread((results) => {
let hierarchy = [];
let intentOrder = ["roi", "campaign", "campsite", "signpost"];
let excludeIntents = ["polygon", "line", "point", "text", "arrow"];
let flatHierarchy = [];
let issues = [];
let changes = [];
Expand All @@ -819,32 +829,36 @@ const compile = function (req, res, callback) {
let intersects = [];
let contains = [];
let children = [];
for (let r = 0; r < results.length; r++) {
if (results[r].id == features[f].id) {
let childProps = JSON.parse(results[r].associated_properties);
if (results[r].association === "intersects") {
intersects.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});
} else if (results[r].association === "contains") {
contains.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});
children.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});

if (!excludeIntents.includes(features[f].intent)) {
for (let r = 0; r < results.length; r++) {
if (results[r].id == features[f].id) {
let childProps = JSON.parse(results[r].associated_properties);
if (results[r].association === "intersects") {
intersects.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});
} else if (results[r].association === "contains") {
contains.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});
children.push({
name: childProps.name,
uuid: childProps.uuid,
id: results[r].associated_id,
intent: results[r].associated_intent,
});
}
}
}
}

let featureProps = JSON.parse(features[f].properties);
flatHierarchy.push({
feature: features[f],
Expand Down Expand Up @@ -976,28 +990,32 @@ const compile = function (req, res, callback) {
//Build the root of the trees
for (let f = 0; f < features.length; f++) {
let isCovered = false;
for (let r = 0; r < results.length; r++) {
if (
results[r].association === "contains" &&
results[r].associated_id == features[f].id
) {
isCovered = true;
break;
if (!excludeIntents.includes(features[f].intent)) {
for (let r = 0; r < results.length; r++) {
if (
!excludeIntents.includes(results[r].intent) &&
results[r].association === "contains" &&
results[r].associated_id == features[f].id
) {
isCovered = true;
break;
}
}

if (!isCovered) {
let featureProps = JSON.parse(features[f].properties);
hierarchy.push({
intent: features[f].intent,
id: features[f].id,
name: featureProps.name,
uuid: featureProps.uuid,
children: {
intersects: [],
contains: [],
},
});
continue;
}
}
if (!isCovered) {
let featureProps = JSON.parse(features[f].properties);
hierarchy.push({
intent: features[f].intent,
id: features[f].id,
name: featureProps.name,
uuid: featureProps.uuid,
children: {
intersects: [],
contains: [],
},
});
continue;
}
}

Expand Down Expand Up @@ -1099,7 +1117,7 @@ const compile = function (req, res, callback) {
}
}

//The Saviorng
//The Savioring
depthTraversalB(hierarchy, 0);
function depthTraversalB(node, depth) {
for (let i = 0; i < node.length; i++) {
Expand Down Expand Up @@ -1156,6 +1174,8 @@ const compile = function (req, res, callback) {
let intent = node.intent;
let props = JSON.parse(node.feature.properties);

if (excludeIntents.includes(intent)) continue;

//Check for duplicate uuids
if (props.uuid == null) {
issues.push({
Expand Down Expand Up @@ -1478,7 +1498,7 @@ router.post("/publish", function (req, res, next) {
logger("error", "Failed to publish. " + message, req.originalUrl, req);
res.send({
status: "failure",
message: "Failed to publish." + message,
message: "Failed to publish. " + message,
body: {},
});
}
Expand All @@ -1493,19 +1513,17 @@ router.post("/publish", function (req, res, next) {
failureCallback
) {
Table.findAll({
limit: 1,
where: {
file_id: file_id,
},
order: [["history_id", "DESC"]],
})
.then((histories) => {
let maxHistoryId = -Infinity;
if (histories && histories.length > 0) {
for (let i = 0; i < histories.length; i++) {
maxHistoryId = Math.max(histories[i].history_id, maxHistoryId);
}
.then((lastHistory) => {
if (lastHistory && lastHistory.length > 0) {
return {
historyIndex: maxHistoryId + 1,
history: histories[maxHistoryId].history,
historyIndex: lastHistory[0].history_id + 1,
history: lastHistory[0].history,
};
} else return { historyIndex: 0, history: [] };
})
Expand Down Expand Up @@ -1580,7 +1598,14 @@ router.post("/publish", function (req, res, next) {
cb(true);
return null;
})
.catch(function (error) {
.catch(function (err) {
logger(
"error",
"Error adding to published.",
req.originalUrl,
req,
err
);
cb(false);
return null;
});
Expand Down
11 changes: 6 additions & 5 deletions API/Backend/Draw/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const routerDraw = require("./routes/draw").router;

let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/files",
s.ensureUser(),
Expand All @@ -24,17 +24,18 @@ let setup = {
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {
onceSynced: (s) => {
routeFiles.makeMasterFiles([
"roi",
"campaign",
"campsite",
"trail",
"signpost"
"signpost",
"all",
]);
}
},
};

module.exports = setup;
Loading

0 comments on commit 375a6aa

Please sign in to comment.