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 .