def get_flowline(request): #If POST then generate the flowline if request.method == 'POST': print("Received!") print("Processing Flowline!") # process JSON xy points (Deserialize JSON) json_data = json.loads(request.body) long = json_data['long'] lat = json_data['lat'] distance = json_data['dist'] #Translator for lon,lat to x,y lonLatTrans = LonLatToProj([[long, lat]]) # create datasets; this is temporary until I find a way to store it myDatasetDict = createInitialDatasets() # put translated point into flowline initialFlowline = Flowline(lonLatTrans.xPoints[0], lonLatTrans.yPoints[0], myDatasetDict, distance) # Translate points back to lat,long xyTrans = ProjToLatLon(initialFlowline.flowLine) # dump flowline into JSONResponse (Serialize the dict) flowLinePoints = {'lon':xyTrans.lonPoints,'lat':xyTrans.latPoints} #Send the JSON back return JsonResponse(flowLinePoints) else: return(HttpResponse("This is not a POST Request"))
def get_point_data(request): if request.method == 'POST': json_data = json.loads(request.body) long = json_data['lon'] lat = json_data['lat'] lonLatTrans = LonLatToProj([[long, lat]]) datasetDict = createInitialDatasets() interp_point = Point(datasetDict, lonLatTrans.xPoints, lonLatTrans.yPoints) #Returns a JSON containing all the datasets for the point return JsonResponse(interp_point.dataValues) else: return HttpResponse("This is not a POST request")
def get_point_data(request): # c = {} # c.update(csrf(request)) if request.method == 'POST': json_data = json.loads(request.body) code = "" dictCode = "" if (json_data['which'] == 'Ant'): projCode = 'epsg:3031' dictCode = 'dictAnt' else: projCode = 'epsg:3413' dictCode = 'dict' if 'lng' in json_data.keys(): lng = json_data['lng'] lat = json_data['lat'] lonLatTrans = LonLatToProj([[lng, lat]], projCode) interp_point = Point(lcache.get(dictCode), lonLatTrans.xPoints[0], lonLatTrans.yPoints[0]) interp_point.dataValues['lng'] = round(float(lng), 4) interp_point.dataValues['lat'] = round(float(lat), 4) elif 'x' in json_data.keys(): x = json_data['x'] y = json_data['y'] interp_point = Point(lcache.get(dictCode), x, y) latLng = ProjToLatLon([[x, y]], projCode) interp_point.dataValues['lng'] = round(latLng.lonPoints[0], 4) interp_point.dataValues['lat'] = round(latLng.latPoints[0], 4) return JsonResponse(interp_point.dataValues) # else: return print("Not a valid point"); else: return HttpResponse("This is not a POST request")
self.flowLine = [] for x in range(0, self.distance): self.flowLine.append(None) self.flowLine[0] = [xStart, yStart] self.flowLine = myIntegrator.integrate(xStart, yStart, self.flowLine, 0, 1000) if (None in self.flowLine): print("Integration Error try again with new x, y") if __name__ == '__main__': latPoint = 69.87 longPoint = -47.01 from QSSICode.translation import LonLatToProj myTranslator = LonLatToProj([[longPoint, latPoint]]) from QSSICode.createDatasets import createInitialDatasets myDatasetDict = createInitialDatasets() myFlowline = Flowline(myTranslator.xPoints[0], myTranslator.yPoints[0], myDatasetDict, 100) print(myFlowline.flowLine) print(myFlowline.flowLine[0]) print(myFlowline.flowLine[1])
def get_flowline_with_data(request): if request.method == 'POST': json_data = json.loads(request.body) termMinimum = 15 code = "" dictCode = "" if (json_data['which'] == 'Ant'): projCode = 'epsg:3031' dictCode = 'dictAnt' else: projCode = 'epsg:3413' dictCode = 'dict' stepSize = 1000 glacier = "" if 'lng' in json_data.keys(): lng = json_data['lng'] lat = json_data['lat'] lonLatTrans = LonLatToProj([[lng, lat]], projCode) if (json_data['which'] == 'Ant'): glacier = FlowlineAnt(lonLatTrans.xPoints[0], lonLatTrans.yPoints[0], lcache.get(dictCode), int(json_data['threshold']), stepSize * 5, json_data['extLength'], projCode) else: glacier = Flowline(lonLatTrans.xPoints[0], lonLatTrans.yPoints[0], lcache.get(dictCode), int(json_data['threshold']), stepSize, json_data['extLength'], projCode) elif 'x' in json_data.keys(): x = json_data['x'] y = json_data['y'] if (json_data['which'] == 'Ant'): glacier = FlowlineAnt(x, y, lcache.get(dictCode), int(json_data['threshold']), stepSize * 5, json_data['extLength'], projCode) else: glacier = Flowline(x, y, lcache.get(dictCode), int(json_data['threshold']), stepSize, json_data['extLength'], projCode) glacierData = {} glacierData['clickedIndex'] = glacier.clickedIndex glacierData['flowline'] = glacier.flowlineData glacierData['avgFlowline'] = glacier.avgFlowlineData glacierData['shears'] = [ np.ndarray.tolist(glacier.shearOne), np.ndarray.tolist(glacier.shearTwo) ] for i in range(json_data['extLength']): glacierData['avgFlowline'][i]['t2m'] = glacierData['avgFlowline'][ json_data['extLength']]['t2m'] glacierData['flowline'][i]['t2m'] = glacierData['flowline'][ json_data['extLength']]['t2m'] glacierData['flowline'][i]['width'] = glacierData['flowline'][ json_data['extLength']]['width'] if (glacierData['avgFlowline'][0]['thickness'] > termMinimum): glacierData['avgFlowline'][0]['thickness'] = termMinimum thickAtTerm = glacierData['avgFlowline'][ json_data['extLength']]['thickness'] for i in range(1, json_data['extLength']): glacierData['avgFlowline'][i]['thickness'] = min( glacierData['avgFlowline'][i]['thickness'], i * (thickAtTerm - termMinimum) / json_data['extLength'] + termMinimum) if (glacierData['flowline'][0]['thickness'] > termMinimum): glacierData['flowline'][0]['thickness'] = termMinimum thickAtTerm = glacierData['flowline'][ json_data['extLength']]['thickness'] for i in range(1, json_data['extLength']): glacierData['flowline'][i]['thickness'] = min( glacierData['flowline'][i]['thickness'], i * (thickAtTerm - termMinimum) / json_data['extLength'] + termMinimum) return JsonResponse(glacierData) else: return HttpResponse("This is not a POST request")