How to perform bilinear interpolation in Python

Here’s a reusable function you can use. It includes doctests and data validation: def bilinear_interpolation(x, y, points): ”’Interpolate (x,y) from values associated with four points. The four points are a list of four triplets: (x, y, value). The four points can be in any order. They should form a rectangle. >>> bilinear_interpolation(12, 5.5, … [(10, … Read more

Pre-projected geometry v getting the browser to do it (aka efficiency v flexibility)

If I use this D3 function, aren’t I still forcing the viewer’s browser to do a lot of data processing, which will worsen the performance? The point of pre-processing the data is to avoid this. Or am I overestimating the processing work involved in the d3.geoTransform() function above? Short Answer: You are overestimating the amount … Read more

Circles in Map Displayed Incorrect Location in D3 V4

Your US json is already projected, and to show it you use a null projection: var path = d3.geoPath() //.projection(projection) Without defining a projection, your topojson/geojson coordinates will be translated to straight pixel coordinates. It just so happens that this particular topojson file has pixel coordinates that are within [0,0] and [960,600], almost the same … Read more

Plotting points on a map with D3

You have a simple typo in your code — coordinates should be passed as (longitude, latitude) to the projection, not the other way round. This code should work fine: svg.selectAll(“.pin”) .data(places) .enter().append(“circle”, “.pin”) .attr(“r”, 5) .attr(“transform”, function(d) { return “translate(” + projection([ d.location.longitude, d.location.latitude ]) + “)”; });

Formulas to Calculate Geo Proximity

The Law of Cosines and the Haversine Formula will give identical results assuming a machine with infinite precision. The Haversine formula is more robust to floating point errors. However, today’s machines have double precision of the order of 15 significant figures, and the law of cosines may work just fine for you. Both these formulas … Read more

Calculate the center point of multiple latitude/longitude coordinate pairs

Thanks! Here is a C# version of OP’s solutions using degrees. It utilises the System.Device.Location.GeoCoordinate class public static GeoCoordinate GetCentralGeoCoordinate( IList<GeoCoordinate> geoCoordinates) { if (geoCoordinates.Count == 1) { return geoCoordinates.Single(); } double x = 0; double y = 0; double z = 0; foreach (var geoCoordinate in geoCoordinates) { var latitude = geoCoordinate.Latitude * Math.PI … Read more