Joining GeoJSON to another GeoJSON

I have some geographical boundaries in which I have a GeoJSON endpoint for .

I also have some variables that are stored in a separate GeoJSON endpoint , which has no coordinates, but has the variable that I want for a later thematic map style followed by D3. This is updated weekly.

Both answers call the identifier lga_name (Local Area Area Name), which I am trying to join. It seems that there are many examples of how to join GeoJSON with CSV, but not GeoJSON with GeoJSON.

I had a hit in an attempt to build an application , but still struggling with the connection.

// Load LGAs from ArcGIS Online (The GeoJSON with geoms) d3.json("the url to the Geoms", function(error, data) { // Load Crash Stats from ArcGIS Online (the total persons involved, summarised down to LGA names) d3.json("the url to the table", function(error, data2) { var lga = data.features; var crashStats = data2.features; // Not working var joined = lga.forEach(function(item) { item.properties.LGA_NAME = crashStats[item.properties.lga_name]; }); 

Can someone give me some pointers to help me move? Just trying to learn more about D3 and Javascript in general.

+5
source share
1 answer

You have data quality problems that may cause some problems:

  • Names (lga_name) of functions - all caps in one json, but not others
  • Function names include characters / phrases such as "(" or "-" or "Big" in one json, but not in the other.
  • There are functions that have coordinates but no entry in another json (Unincorporated Vic)
  • There are duplicate values โ€‹โ€‹in json that stores non-geographic properties (you stated that you want to join and not summarize any data, my solution uses only one record from json properties (one without coordinates))

You can achieve your goal (use the second json to get the โ€œvariable that I want to map thematically later styleโ€) in different ways, here I will use two different methods:

  • Create one valid geojson that contains all your functions and properties.
  • Create functions from json coordinates and create them based on json properties, using the name as a common identifier.

Create one valid geojson that contains all your functions and properties

Using d3.map() , we can easily add non-geographic json properties:

 var lookup = d3.map(data.features, function(d) { return d.properties.lga_name; }); geographic.features.forEach(function(d) { d.properties = lookup.get(d.properties.LGA_NAME).properties; }); 

Now you have one geojson that has the properties of one json and the coordinates of another.

Since your identifiers are not standardized, I created a function to standardize the names between two files to make the data work. I also added a check to make sure that the properties exist for this function. See the block .

Creating functions using one JSON and style based on another JSON

You do not need to actually join the data, but to achieve style. Using d3.map() , you can search for the properties of each function when styling. For example, you can fill out a form:

 var lookup = d3.map(data.features, function(d) { return d.properties.lga_name; }); regions.attr("fill",function(d) { return color(lookup.get(d.properties.LGA_NAME).properties.total_pers); }) 

Again, since your identifiers are not standardized, I created a function for standardizing names between two files. As above, there is also a check to see if there is a function in non-geographic json (and therefore the properties used for styling). See the block .

+3
source

Source: https://habr.com/ru/post/1270825/


All Articles