Skip to content

Commit

Permalink
#483 MeasureTool Fix nodata issue (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman authored Dec 22, 2023
1 parent dc16666 commit c689c8e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
20 changes: 12 additions & 8 deletions private/api/2ptsToProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# Takes in a [[x,y],[x,y],[x,y],[x,y]...[x,y],[x,y]]
# and returns an array of values on the raster at those points in order

# Just temporary, script outputs them as None
NODATA_VALUE = -1100101

def getRasterDataValues(pointArray):
valuesArray = []
Expand All @@ -33,8 +35,8 @@ def getRasterDataValues(pointArray):
value = band.ReadAsArray(
pointArray[i][0], pointArray[i][1], 1, 1)[0][0]
except:
# -1100101 = (e)rror
value = -1100101
# (e)rror
value = NODATA_VALUE

noData = band.GetNoDataValue()
if noData is not None:
Expand All @@ -43,7 +45,7 @@ def getRasterDataValues(pointArray):
if abs(noData) > 1000000000:
decPlaces = 10
if abs(value) >= abs(noData / decPlaces) and abs(value) <= abs(noData * decPlaces):
value = -1100101
value = NODATA_VALUE
valuesArray.append(value)
return valuesArray

Expand All @@ -60,9 +62,9 @@ def getRasterDataCoords(pointArray):
valueY = bandY.ReadAsArray(
pointArray[i][0], pointArray[i][1], 1, 1)[0][0]
except:
# -1100101 = (e)rror
valueX = -1100101
valueY = -1100101
# (e)rror
valueX = NODATA_VALUE
valueY = NODATA_VALUE

noDataX = bandX.GetNoDataValue()
if noDataX is not None:
Expand All @@ -71,7 +73,7 @@ def getRasterDataCoords(pointArray):
if abs(noDataX) > 1000000000:
decPlaces = 10
if abs(valueX) >= abs(noDataX / decPlaces) and abs(valueX) <= abs(noDataX * decPlaces):
valueX = -1100101
valueX = NODATA_VALUE

noDataY = bandY.GetNoDataValue()
if noDataY is not None:
Expand All @@ -80,7 +82,7 @@ def getRasterDataCoords(pointArray):
if abs(noDataY) > 1000000000:
decPlaces = 10
if abs(valueY) >= abs(noDataY / decPlaces) and abs(valueY) <= abs(noDataY * decPlaces):
valueY = -1100101
valueY = NODATA_VALUE

coordsArray.append([valueX, valueY])

Expand Down Expand Up @@ -208,6 +210,8 @@ def latLonsToPixel(latLonPairs):
# Come latlon with elevs and print
for i in range(0, len(latLonElevArray)):
latLonElevArray[i] = [latLonElevArray[i][1], latLonElevArray[i][0]]
if elevArray[i] == NODATA_VALUE:
elevArray[i] = None
latLonElevArray[i].append(elevArray[i])

print(latLonElevArray)
2 changes: 1 addition & 1 deletion scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ setups.getBackendSetups(function (setups) {
logger("warn", error);
res.status(400).send();
} else {
res.send(stdout);
res.send(stdout.replace(/None/g, null));
}
}
);
Expand Down
5 changes: 5 additions & 0 deletions src/essence/Basics/Formulae_/Formulae_.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,13 @@ var Formulae_ = {
return r.test(url)
},
csvToJSON: function (csv) {
if (csv == null) return {}

var lines = csv.split('\n')
var result = []

if (lines == null || lines[0] == null) return {}

var headers = lines[0].split(',')
for (var i = 1; i < lines.length; i++) {
var obj = {}
Expand Down
8 changes: 6 additions & 2 deletions src/essence/Tools/Measure/MeasureTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const Measure = () => {
: `rgba(255, 0, 47, ${alpha})`
},
},
spanGaps: true,
spanGaps: false,
borderWidth: 1,
fill: 'start',
pointRadius: 0,
Expand Down Expand Up @@ -469,7 +469,11 @@ const Measure = () => {
.css({ opacity: 1 })

$('#measureInfoElev > div:last-child')
.text(`${d[4].toFixed(3)}m`)
.text(
d[4] != null
? `${d[4].toFixed(3)}m`
: 'No Data'
)
.css({ opacity: 1 })

const text2d =
Expand Down

0 comments on commit c689c8e

Please sign in to comment.