def testing(): """ r = Report.current() #r = Report.get(Key('ahBpbWF6b24tcHJvdG90eXBlcg4LEgZSZXBvcnQYiaECDA')) logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' s = Stats() polygon = [[[-61.9,-11.799],[-61.9,-11.9],[-61.799,-11.9],[-61.799,-11.799],[-61.9,-11.799]]] return str(s.get_stats_for_polygon("PRODES_2009", polygon)) #return str(ndfi.mapid2()) #return str(ndfi.freeze_map(1089491, r.key().id())) """ s = Stats() return jsonify(s._execute_cmd("/value", { "image": json.dumps({"creator":"SAD/com.google.earthengine.examples.sad.GetStatsList","args":[ [{"creator":"SAD/com.google.earthengine.examples.sad.ProdesImage","args":["PRODES_2009"]}, {"creator":"SAD/com.google.earthengine.examples.sad.ProdesImage","args":["PRODES_IMAZON_2011a"]}],{"type":"FeatureCollection","table_id":1505198},"name"]}), "fields": "classHistogram"}))
def polygon_stats(format=None): reports = request.args.get('reports', None) if not reports: abort(400) try: reports = map(int, reports.split(',')) except ValueError: logging.error("bad format for report id") abort(400) try: reports = [Report.get_by_id(x) for x in reports] except ValueError: logging.error("can't find some report") abort(404) #TODO: test if polygon is ccw # exchange lat, lon -> lon, lat polygon = json.loads(request.args.get('polygon', None)) polygon.append(polygon[0]) logging.info(polygon) logging.info(path_to_kml([polygon])) if not polygon: abort(404) ee = Stats() normalized_poly = [(coord[1], coord[0]) for coord in polygon] stats = ee.get_stats_for_polygon([(str(r.key().id()), r.assetid) for r in reports], [normalized_poly]) this_report = ReportType.factory(format) this_report.init("custom polygon") try: this_report.write_header() for i, s in enumerate(stats): r = reports[i] this_report.write_row(r, s, None, path_to_kml([polygon])) this_report.write_footer() return this_report.response("report_polygon") except (KeyError, ValueError, IndexError): abort(404)
def polygon_stats(format=None): reports = request.args.get('reports', None) if not reports: abort(400) try: reports = map(int, reports.split(',')) except ValueError: logging.error("bad format for report id") abort(400) try: reports = [Report.get_by_id(x) for x in reports] except ValueError: logging.error("can't find some report") abort(404) #TODO: test if polygon is ccw # exchange lat, lon -> lon, lat polygon = json.loads(request.args.get('polygon', None)) polygon.append(polygon[0]) logging.info(polygon) logging.info(path_to_kml([polygon])) if not polygon: abort(404) ee = Stats() normalized_poly = [(coord[1], coord[0]) for coord in polygon] stats = ee.get_stats_for_polygon([(str(r.key().id()), r.assetid) for r in reports], [normalized_poly]) this_report = ReportType.factory(format) this_report.init("custom polygon") try: this_report.write_header() for i,s in enumerate(stats): r = reports[i] this_report.write_row(r, s, None, path_to_kml([polygon])) this_report.write_footer() return this_report.response("report_polygon") except (KeyError, ValueError, IndexError): abort(404)
def testing(): """ r = Report.current() #r = Report.get(Key('ahBpbWF6b24tcHJvdG90eXBlcg4LEgZSZXBvcnQYiaECDA')) logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' s = Stats() polygon = [[[-61.9,-11.799],[-61.9,-11.9],[-61.799,-11.9],[-61.799,-11.799],[-61.9,-11.799]]] return str(s.get_stats_for_polygon("PRODES_2009", polygon)) #return str(ndfi.mapid2()) #return str(ndfi.freeze_map(1089491, r.key().id())) """ s = Stats() return jsonify( s._execute_cmd( "/value", { "image": json.dumps({ "creator": "SAD/com.google.earthengine.examples.sad.GetStatsList", "args": [[{ "creator": "SAD/com.google.earthengine.examples.sad.ProdesImage", "args": ["PRODES_2009"] }, { "creator": "SAD/com.google.earthengine.examples.sad.ProdesImage", "args": ["PRODES_IMAZON_2011a"] }], { "type": "FeatureCollection", "table_id": 1505198 }, "name"] }), "fields": "classHistogram" }))