Dynamically set folium zoom and postion to geopandas dataframe extent - geopandas

I have a geopandas dataframe containing many polygons.
I wish to plot these in a folium map and have that map set the zoom and extent dynamically to fit all polygons onto the map.
I've tried the following
bounds = df.total_bounds
m.fit_bounds(bounds)
m
But get TypeError: Object of type ndarray is not JSON serializable

Try this syntax:-
m.fit_bounds([[bounds[0],bounds[1]], [bounds[2],bounds[3]]])

Related

D3.js show heatmap for each pixel (coordinate) in choropleth

In D3.js choropleth map, we assign a color to each state or city. is there any solution or example that we can assign heatmap to each coordinate (my data are values from satellites so i have a value for each coordinate).In matlab or matplotlib I plot a figure and then apply borders but it seems it's not possible in D3. i want something like this
thanks.
folium python package have geojson (choropleth) mapping function that we can define rectangles (polygons, for example zip code regions). for more information interactive choropleth map
and popuo on map. my result

Fit D3 map in SVG

In this jsfiddle I have a D3 map that I took from here, but I'm trying to fit it in an svg that is half the original size. For that, I changed:
var width = 480;
var height = 300;
.....
var path = d3.geoPath(d3.geoIdentity().translate([width/2, height/2]).scale(height*.5));
But it's not working. How to make the map fit the svg?
D3's geoIdentity exposes almost all the standard methods of a d3 projection (off the top of my head, only rotation is not possible as the identity assumes cartesian data). Most importantly here, it exposes the fitSize and fitExtent methods. These methods set translate and scale based on the coordinate extent of displayed geojson data and the pixel extent of the svg/canvas.
To scale your features with a geo identity you can use:
d3.geoIdentity().fitSize([width,height],geojsonObject)
Note that an array of geojson features won't work, but a geojson feature collection or any individual feature/geometry object works too. The width and height are of the svg/canvas.
If you want to apply a margin, you can use:
d3.geoIdentity().fitExtent([[margin,margin],[width-margin,height-margin]],geojsonObject)
The margin doesn't need to be uniform, the format is [[left,top],[right,bottom]],geojsonObject
If using fitSize or fitExtent there is no need to set center, translate or scale manually and setting these afterwards will recenter or rescale the map.

Converting a map in Cartesian projection (with spherical coordinate) to healix projection

I have a map with spherical coordinate system in Cartesian projection. The header file reads CTYPE1 = 'GLON-CAR' and CTYPE2 = 'GLAT-CAR'. I want to convert this map to healpix projection. I understand that I need to convert the map in spherical coordinate to healpix pixels using tool "ang2pix". But I am not able to understand to how to fill the pixel with the values that are available in cartesian projection.
It's easiest to not re-invent the wheel, and to benefit from the efforts of others that came before you. Check out the reproject package and in particular reproject_to_healpix(), it will do everything you need.

d3 mercator, geo, and path methods

I am following this tutorial on d3:
In it, I see this code:
var projection = d3.geo.mercator()
.scale(500)
.translate([width / 2, height / 2]);
And likewise the path generator:
var path = d3.geo.path()
.projection(projection);
What are these methods doing exactly? Is there good documentation on these d3 methods? On on the d3 docs. it says:
"# d3.geo.mercator()
"The spherical Mercator projection is commonly used by tiled mapping
libraries (such as OpenLayers and Leaflet). For an example displaying
raster tiles with the Mercator projection, see the d3.geo.tile plugin.
It is conformal; however, it introduces severe area distortion at
world scale and thus is not recommended for choropleths."
So is d3.geo.mercator just a kind of map design?
The map projection just converts points from one system (sphere/ellipsoid based latitude/longitudes) into another system (2d Cartesian plane with x/y values).
Mercator is one (very common) way of doing that. For more about map projections, take a look at http://en.wikipedia.org/wiki/Map_projection.
With the code you've posted, it sets up a Mercator projection, that when passed a [long, lat] point it will return an [x, y] point that corresponds to the x and y position that can be drawn on an svg or canvas. In this case it will be centered at [width/2, height/2].
The path generator is some d3 "magic" that converts a list of points into an svg path string. svg has it's own "language" for paths, you can find out more at http://www.w3.org/TR/SVG/paths.html, but that does get pretty technical.
Since svg talks in pixel co-ordinates, and most geo data is referenced to lat/long, the projection function allows you to easily convert from one to the other and back again.
Since drawing a path on a map is a very common activity, d3 includes the path generator that is projection "aware" and will automatically apply the projection specified to whatever data you pass to the path generator, which will result in the pixel co-ordinates getting returned, which will then be converted into the path "language" mentioned above, which can then be displayed on an svg element.

Drawing maps with d3.js which contains cities

I intend to draw maps using d3.js and geoJson.
I need to plot circles on this map.These circles when hovered should get bigger and display some data inside that.
Also,i need to create a time line scale which will increase and decrease the circles in the map based on the data for that particular time frame.
I am able to draw map with the help of geo JSON file but the problem is how to plot the circles such that when map is moved in the canvass the circle remains at same position inside the map.I mean the circles should be relative to map not relative to canvass.
Secondly I am not able to understand how the coordinate system of maps work.
Any help Please..

Resources