|
|
@ -120,141 +120,7 @@ def json_track_upload( request ): |
|
|
|
|
|
|
|
### Heavily based on code from http://kuhlit.blogspot.com/2011/04/ajax-file-uploads-and-csrf-in-django-13.html |
|
|
|
### end of file-upload w/ django support |
|
|
|
|
|
|
|
def json_path_id_post(request): |
|
|
|
args = request.POST |
|
|
|
ls = [] |
|
|
|
# take only first linestring... |
|
|
|
str_path = args.getlist("LS")[0] |
|
|
|
height_limit = args.get("h-limit") |
|
|
|
if not height_limit or height_limit == 0: |
|
|
|
height_limit = None |
|
|
|
else: |
|
|
|
height_limit = int(height_limit) |
|
|
|
|
|
|
|
path = GEOSGeometry(str_path) |
|
|
|
|
|
|
|
interpolated_path = [] |
|
|
|
prev_p = Point(path[0]) |
|
|
|
interpolated_path.append(path[0]) |
|
|
|
|
|
|
|
sampling_step = 0.002 |
|
|
|
## sampling = 0.002 (~100m) |
|
|
|
for p in path[1:]: |
|
|
|
n_p = Point(p) |
|
|
|
d = prev_p.distance(n_p) |
|
|
|
if d > sampling_step: |
|
|
|
start_idx = path.project(prev_p) |
|
|
|
nsamples = int(d/sampling_step) |
|
|
|
for i in xrange(nsamples): |
|
|
|
idx = start_idx + sampling_step + i*sampling_step |
|
|
|
interpolated_path.append(list(path.interpolate(idx))) |
|
|
|
prev_p = n_p |
|
|
|
interpolated_path.append(p) |
|
|
|
|
|
|
|
indexes = [path.project(Point(x)) for x in interpolated_path] |
|
|
|
|
|
|
|
inter_space_ids, intersections = get_space_intersect_path(LineString(interpolated_path), height_limit) |
|
|
|
relief_profile = get_relief_profile_along_track(interpolated_path) |
|
|
|
|
|
|
|
ret_json = { |
|
|
|
'ZID' : inter_space_ids, |
|
|
|
'intersections' :intersections, |
|
|
|
'indexes': indexes, |
|
|
|
'interpolated' : geojson.geometry.LineString(interpolated_path), |
|
|
|
'relief_profile': relief_profile, |
|
|
|
} |
|
|
|
|
|
|
|
r = geojson.dumps( ret_json ) |
|
|
|
return HttpResponse(r, mimetype='application/json' ) |
|
|
|
|
|
|
|
## |
|
|
|
# get a FeatureCollection out of a list of zone id |
|
|
|
# Can be via GET or POST |
|
|
|
|
|
|
|
# disable csrf protection |
|
|
|
#@csrf_exempt |
|
|
|
def json_zone_post(request): |
|
|
|
args = request.POST |
|
|
|
zones = [] |
|
|
|
for i in args.getlist("ZID"): |
|
|
|
zones += i.split(',') |
|
|
|
return internal_json_zones(zones) |
|
|
|
|
|
|
|
def json_zones(request, zone_ids): |
|
|
|
zs = zone_ids.split(',') |
|
|
|
return internal_json_zones(zs) |
|
|
|
|
|
|
|
def internal_json_zones(zone_list): |
|
|
|
try: |
|
|
|
spaces = [] |
|
|
|
for zid in zone_list: |
|
|
|
z = AirSpaces.objects.get(pk=zid) |
|
|
|
spaces.append(z) |
|
|
|
|
|
|
|
js_spaces = geojson.FeatureCollection(spaces) |
|
|
|
s = geojson.dumps(js_spaces) |
|
|
|
|
|
|
|
except AirSpaces.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
return HttpResponse(s, mimetype='application/json') |
|
|
|
|
|
|
|
|
|
|
|
def json_zones_by_name(request, name): |
|
|
|
try: |
|
|
|
zones = AirSpaces.objects.filter(name__icontains=name) |
|
|
|
|
|
|
|
data = [z.pk for z in zones] |
|
|
|
return HttpResponse(json.dumps(data), mimetype='application/json') |
|
|
|
|
|
|
|
# js_spaces = geojson.FeatureCollection(list(zones)) |
|
|
|
# s = geojson.dumps(js_spaces) |
|
|
|
# return HttpResponse(s, mimetype='application/json') |
|
|
|
except AirSpaces.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
def json_zone(request, zone_id): |
|
|
|
try: |
|
|
|
z = AirSpaces.objects.get(pk=zone_id) |
|
|
|
s = geojson.dumps(z) |
|
|
|
except AirSpaces.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
return HttpResponse(s, mimetype='application/json') |
|
|
|
|
|
|
|
|
|
|
|
def json_zone_bbox(request, lowlat, lowlon, highlat, highlon): |
|
|
|
zone_bbox = Polygon(((float(lowlat),float(lowlon)), |
|
|
|
(float(lowlat), float(highlon)), |
|
|
|
(float(highlat), float(highlon)), |
|
|
|
(float(highlat), float(lowlon)), |
|
|
|
(float(lowlat), float(lowlon)))) |
|
|
|
spaces = AirSpaces.objects.filter(geom__intersects=zone_bbox) |
|
|
|
js_spaces = geojson.FeatureCollection(list(spaces)) |
|
|
|
|
|
|
|
return HttpResponse(geojson.dumps(js_spaces), mimetype='application/json') |
|
|
|
|
|
|
|
def jsonID_zone_bbox(request, lowlat, lowlon, highlat, highlon): |
|
|
|
zone_bbox = Polygon(((float(lowlat),float(lowlon)), |
|
|
|
(float(lowlat), float(highlon)), |
|
|
|
(float(highlat), float(highlon)), |
|
|
|
(float(highlat), float(lowlon)), |
|
|
|
(float(lowlat), float(lowlon)))) |
|
|
|
spaces = AirSpaces.objects.filter(geom__intersects=zone_bbox) |
|
|
|
|
|
|
|
data = [z.pk for z in spaces] |
|
|
|
|
|
|
|
return HttpResponse(json.dumps(data), mimetype='application/json') |
|
|
|
|
|
|
|
|
|
|
|
def jsonID_zone_point(request, lat, lon, radius): |
|
|
|
point = Point(float(lat), float(lon)) |
|
|
|
spaces = AirSpaces.objects.filter(geom__distance_lte=(point, D(m=int(radius)))) |
|
|
|
|
|
|
|
data = [z.pk for z in spaces] |
|
|
|
return HttpResponse(json.dumps(data), mimetype='application/json') |
|
|
|
|
|
|
|
|
|
|
|
def amap(request): |
|
|
|
ctx = RequestContext( request, { |
|
|
|
'csrf_token': csrf.get_token( request ), |
|
|
|