Transform a map visualization into a json payload compatible with the windshaft API.
341149
function serialize (layersCollection, dataviewsCollection) {
  return {
    buffersize: { mvt: 0 },
    layers: LayerSerializer.serialize(layersCollection),
    dataviews: DataviewSerializer.serialize(dataviewsCollection),
    analyses: AnalisysSerializer.serialize(layersCollection, dataviewsCollection)
  };
}
822529
def save_map(self, map_path, map_data):
    """"""
    return self._client.send(save_map=sc_pb.RequestSaveMap(
        map_path=map_path, map_data=map_data))
408761
def ip_to_geojson(ipaddress, name="Point"):
    """"""

    geo = ip_to_geo(ipaddress)

    point = {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": {
                    "name": name
                },
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        geo["longitude"],
                        geo["latitude"]
                    ]
                }
            }
        ]
    }

    return point
1118554
def dump(obj, fp, **user_kwargs):
    
    return json.dump(obj, fp, **_encoder_kwargs(user_kwargs))
319957
function processJson (json) {
                        if (json.length != 1) {
                            renderContext.renderErrors[graph.id] = "TSDB results doesn't contain exactly 1 metric, was "+json.length;
                            renderContext.renderMessages[graph.id] = "";
                            return;
                        }

                        var series = json[0];

                        if (heatmapOptions.excludeNegative) {
                            for (var i=0; i<series.dps.length; i++) {
                                if (series.dps[i][1] < 0) {
                                    series.dps[i][1] = 0;
                                }
                            }
                        }

                        var isFilteredOutFn = function(value) {
                            return false;
                        }
                        var tsdbLinkRangeLower = "";
                        var tsdbLinkRangeUpper = "";
                        if ((heatmapOptions.filterLowerBound != null && heatmapOptions.filterLowerBound != "") || (heatmapOptions.filterUpperBound != null && heatmapOptions.filterUpperBound != "")) {
                            if (heatmapOptions.filterUpperBound == null || heatmapOptions.filterUpperBound == "") {
                                try {
                                    var lower = parseInt(heatmapOptions.filterLowerBound);
                                    tsdbLinkRangeLower = lower;
                                    isFilteredOutFn = function(value) {
                                        return value < lower
                                    };
                                }
                                catch (e) {
                                    // ignore
                                }
                            }
                            else if (heatmapOptions.filterLowerBound == null || heatmapOptions.filterLowerBound == "") {
                                try {
                                    var upper = parseInt(heatmapOptions.filterUpperBound);
                                    tsdbLinkRangeUpper = upper;
                                    isFilteredOutFn = function(value) {
                                        return value > upper
                                    };
                                }
                                catch (e) {
                                    // ignore
                                }
                            }
                            else {
                                try {
                                    var lower = parseInt(heatmapOptions.filterLowerBound);
                                    var upper = parseInt(heatmapOptions.filterUpperBound);
                                    tsdbLinkRangeLower = lower;
                                    tsdbLinkRangeUpper = upper;
                                    isFilteredOutFn = function(value) {
                                        return value < lower || value > upper
                                    };
                                }
                                catch (e) {
                                    // ignore
                                }
                            }
                        }

                        // remove old heatmaps..
                        d3.select(divSelector)
                            .selectAll("svg")
                            .remove();

                        var heatmap = renderer.heatmap()
                            .cellSize(cellSize)
                            .scale(d3.scale.quantize())
                            .dps(series.dps)
                            .width(width)
                            .height(height)
                            .colourScheme(heatmapOptions.colourScheme);

                        if (style == "week_day") {
                            heatmap.weekDayRender(divSelector, fromYear, toYear, isFilteredOutFn);
                        }
                        else if (style == "day_hour") {
                            heatmap.dayHourRender(divSelector, fromMonth, toMonth, isFilteredOutFn);
                        }

                        if (heatmapOptions.excludeNegative && true && (tsdbLinkRangeLower == "" || tsdbLinkRangeLower < 0)) {
                            tsdbLinkRangeLower = 0;
                        }
                        var yAxisParams = {
                            range: "[" + tsdbLinkRangeLower + ":" + tsdbLinkRangeUpper + "]"
                        };
                        ret.tsdb_export_link = graphServices.tsdbGraphUrl("/#", renderContext, config, global, graph, queries, "x1y1", downsampleOverrideFn, yAxisParams, /*y2AxisParams*/null, /*keyParams*/{}, /*lineSmoothing*/false, /*style*/null, /*globalAnnotations*/false);
                        renderContext.renderMessages[graph.id] = "";
                        renderContext.graphRendered(graph.id);
                        return;
                    }
1119611
private static Map<String, Map<String, String>> getStatsMap(String json)
      throws IOException {
    if (json == null || json.isEmpty()) {
      return new HashMap<String, Map<String, String>>();
    }
    TypeReference<Map<String, Map<String, String>>> type = new TypeReference<Map<String, Map<String, String>>>() {
    };
    return mapper.readValue(json, type);
  }
1227470
def geojson(self, feature_id):
        """"""
        if self._geojson.get('id', feature_id) == feature_id:
            return self._geojson
        else:
            geo = self._geojson.copy()
            geo['id'] = feature_id
            return geo
91211
def to_json(self):
    """"""
    result = {
        "mapper_handler_spec": self.handler_spec,
        "mapper_input_reader": self.input_reader_spec,
        "mapper_params": self.params,
        "mapper_shard_count": self.shard_count
    }
    if self.output_writer_spec:
      result["mapper_output_writer"] = self.output_writer_spec
    return result
400823
def map_overlay_obs(self):
        """"""
        return json.loads(self._query(LAYER, OBSERVATIONS, ALL, CAPABILITIES, "").decode(errors="replace"))
1325610
function (renderable) {
                if (!(renderable instanceof WorldWind.SurfaceEllipse)) {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "GeoJSONExporter", "exportSurfaceEllipse",
                            "invalidTypeOfRenderable"));
                }

                var sb = '{';
                sb = sb + '"' + GeoJSONConstants.FIELD_TYPE + '":"' + GeoJSONConstants.TYPE_POLYGON + '",';
                sb = sb + '"' + GeoJSONConstants.FIELD_COORDINATES + '":[';
                sb = sb + '[';
                for (var i = 0; i < renderable._boundaries.length; i++) {
                    sb = sb + '[' + renderable._boundaries[i].longitude + ',' +
                        renderable._boundaries[i].latitude + ']';
                    sb = sb + ',';

                    if (i === renderable._boundaries.length - 1) {
                        sb = sb + '[' + renderable._boundaries[0].longitude + ',' +
                            renderable._boundaries[0].latitude + ']';
                    }
                }
                sb = sb + ']';
                sb = sb + ']';
                sb = sb + '}';
                return sb;
            }
1271617
def contourf_to_geojson(contourf, geojson_filepath=None, min_angle_deg=None,
                        ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
                        geojson_properties=None, strdump=False, serialize=True):
    """"""
    polygon_features = []
    mps = []
    contourf_idx = 0
    for coll in contourf.collections:
        color = coll.get_facecolor()
        for path in coll.get_paths():
            for coord in path.to_polygons():
                if min_angle_deg:
                    coord = keep_high_angle(coord, min_angle_deg)
                coord = np.around(coord, ndigits) if ndigits else coord
                op = MP(contourf.levels[contourf_idx], rgb2hex(color[0]))
                if op in mps:
                    for i, k in enumerate(mps):
                        if k == op:
                            mps[i].add_coords(coord.tolist())
                else:
                    op.add_coords(coord.tolist())
                    mps.append(op)
        contourf_idx += 1
    # starting here the multipolys will be extracted
    contourf_idx = 0
    for muli in mps:
        polygon = muli.mpoly()
        fcolor = muli.color
        properties = set_contourf_properties(stroke_width, fcolor, fill_opacity, contourf.levels, contourf_idx, unit)
        if geojson_properties:
            properties.update(geojson_properties)
        feature = Feature(geometry=polygon, properties=properties)
        polygon_features.append(feature)
        contourf_idx += 1
    feature_collection = FeatureCollection(polygon_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize)
406452
def to_json(df, x, y, timeseries=False):
        """"""
        values = {k: [] for k in y}
        for i, row in df.iterrows():
            for yy in y:
                values[yy].append({
                    "x": row[x],
                    "y": row[yy]
                    })
        return {"result":  [values[k] for k in y], "date": timeseries}
92514
def to_json(self, indent=None):
        """"""

        inputs = ParameterCollection(self.inputs)

        d = {
            'meta': {
                'name': self.name,
                'description': self.description
            },
            'inputs': [],
            'workflow': [],
            'outputs': [{'name': k, 'node': v} for k, v in six.iteritems(self.output_mapping)]
        }

        for parameter in self.inputs:
            input_info = {
                'name': parameter.name,
                'type': parameter.id
            }

            args, kwargs = parameter.serialize_args()
            args = list(args)
            args.pop(0)  # 'name' is already taken care of
            kwargs.pop('required', None)  # 'required' is assumed True for workflow inputs
            if args or kwargs:
                input_info['args'] = [args, kwargs]

            d['inputs'].append(input_info)

        for node in sorted(six.itervalues(self.nodes_by_id), key=lambda x: x.id):
            task_name = node.task.name
            if not task_name:
                raise ValueError('The task {0} does not have a name and therefore cannot be serialized.'.format(
                    node.task.__class__.__name__)
                )

            node_inputs = {}
            for input_name, (source, value) in six.iteritems(node.inputs):
                input_info = {'source': source}

                if source == 'input':
                    input_info['input'] = inputs.by_name[value].name
                else:
                    input_info['node'] = value

                node_inputs[input_name] = input_info

            d['workflow'].append({
                'id': node.id,
                'task': task_name,
                'inputs': node_inputs
            })

        return json.dumps(d, indent=indent)
1369707
public JSONObject getJsonFormatted(Map<String, String> dataMap) {
        JSONObject oneRowJson = new JSONObject();

        for (int i = 0; i < outTemplate.length; i++) {
            oneRowJson.put(outTemplate[i], dataMap.get(outTemplate[i]));
        }


        return oneRowJson;
    }
1371757
def _bins_to_json(h2):
    
    south = h2.get_bin_left_edges(0)
    north = h2.get_bin_right_edges(0)
    west = h2.get_bin_left_edges(1)
    east = h2.get_bin_right_edges(1)
    return {
        "type":"FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Polygon",
                    # Note that folium and GeoJson have them swapped
                    "coordinates": [[
                        [east[j], south[i]],
                        [east[j], north[i]],
                        [west[j], north[i]],
                        [west[j], south[i]],
                        [east[j], south[i]]]],
                },
                "properties" : {
                    "count": float(h2.frequencies[i, j])
                }
            }
            for i in range(h2.shape[0])
            for j in range(h2.shape[1])
        ]
    }
8186
public String formatMap2JSON(Map<String, Object> map) {
		StringWriter stringWriter = new StringWriter();
		String json = "";
		try {
			JsonGenerator gen = new JsonFactory()
					.createJsonGenerator(stringWriter);
			MAPPER.writeValue(gen, map);
			gen.close();
			json = stringWriter.toString();
		} catch (Exception e) {
			LOGGER.error("", e);
		}
		return json;
	}
1041811
function flattenMessageMap(data) {
    var obj = {};
    var newKey;

    _.each(data, function(groupMessages, key) {
        _.each(groupMessages, function(message, subKey) {
            newKey = [key, subKey].join('.');
            obj[newKey] = message;
        });
    }, this);

    return obj;
}