JamesRunnalls / leaflet-contour

A customisable Leaflet contour plugin. Uses d3-contour under the hood.
16 stars 3 forks source link

Need help understanding the plugin's usage #1

Open abismailinglist opened 2 years ago

abismailinglist commented 2 years ago

Hey, I wasn't quite able to understand the plugin's usage. Can you help me out? In MatPlotLib, you have to create a 2D array whose indexes are the latitude and longitude. So for instance something like this

latitude=59.4
longitude=32.4
print(myarray[latitude][longitude]) //this will print the "Z" value

How is the data supposed to be structured for this plugin instead? I see that there are a lot of nulls and stuff, I suppose that you created it programmatically, but how? Let's say for example that you wanted to draw a contour starting from this GeoJSON data (which is just a pentagon really), how would you do that?

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              9.129638671875,
              46.32417161725691
            ],
            [
              8.3331298828125,
              45.832626782661535
            ],
            [
              8.8330078125,
              45.4524242413431
            ],
            [
              9.6405029296875,
              45.40230699238177
            ],
            [
              9.849243164062498,
              45.744526980468436
            ],
            [
              9.129638671875,
              46.32417161725691
            ]
          ]
        ]
      }
    }
  ]
}

image

PalleZ commented 2 years ago

This is a bit fuzzy for me as well but if you look at the code and d3-contour that it uses you can see that it takes the rectangular array/matrix of z-values and pushes it into d3-contour and then the output is mapped to the geographical coordinates. So you need to map your z-values to a rectangular array/matrix in some way that makes sense, like some kind of "spatial binning" (?). In you example you don't really have any z-values which makes it hard to come with any recommendation. But if the polygon has the same z-value all over then put it into a bounding box, decide the array dimensions of the bounding box and project it onto the bounding box array/matrix in some way.

JamesRunnalls commented 2 years ago

Sorry for the slow response. The input data needs to be a object with the following format {x: [[]], y:[[]], z:[[]]}. Where each of the values is a 2D matrix.

e.g. {x: [[9.1, 9.2, 9.3],[9.1, 9.2, 9.3],[9.1, 9.2, 9.3]], y:[[46.1, 46.1, 46.1],[46.05, 46.05, 46.05],[46, 46, 46]], z:[[1,1.2,1.3],[1.1,1.5,1.3],[1.4,1.1,1.1]]}

Jason-Air commented 2 years ago

Hi James, I have got a 200 lat, lon, value array. I couldn't figure out how should I split them into 2d array. Could you explain the 2d array that make sense for us.