Lxml's current FAQ includes a method of transforming xml to a dict of dicts, but not JSON. The mismatch between a dict of dicts and JSON occurs when an element has mulitple children with the same tag name. Under JSON conventions, multiple children of the same name are equivalent to an array or tuple. The below python functions attempt to add the repeated tags to list functionality. I'd appreciate suggestions for improvements.
The mapbox updating choropleth example uses a precomputed legend: both the stops and the colors they correspond to are already written into the webpage. In maps that follow Tobler's law that "everything is related to everything else, but near things are more related than distant things", some regions will contain features that have small but significant differences from each other that are difficult to see on a pre-computed legend. Here are two solutions: change the style and change the legend to match the displayed data (adapt_style
and adapt_legend.js
, respectively).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Functions to extract geojson from pandas.DataFrames" | |
import pandas as pd | |
import geojson | |
def to_list(pd_series): | |
"Shorthand: Coerce a pd.Series to a list of its elements" | |
return pd_series.tolist() | |
def make_position(df, lat, lon): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Correct all schemaLocation paths with new relative or absolute paths to the | |
* .xsd files. | |
* @param {String} inputStr a string of an .xsd file to reprocess | |
* @param {String|Object} dirOrLocations a string directory containing all | |
* imported/included schemas or an object mapping the current schema filename | |
* with an optional extension .xsd to a new location | |
* @returns {String} the xsd file with all schemaLocations replaced with | |
* corrected relative or absolute paths | |
* @throws {Error} throws an error if schema location translations are missing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2016 Stuart Powers | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
NewerOlder