James
James

Reputation: 561

Adding properties from one dataset to a previously created node from another dataset in Neo4j

I've created a dataset of nodes from census tract polygon areas. I want to attach census tract data (from another dataset) either as properties of each tract's corresponding node, or as relationship (tract_IDs) - [:Belongs_to] -> tract_IDs holding geometries. In this case, I think the properties makes more sense, but I'd also like to know how to do the latter. Because neo4j tutorials deal so much with creating a single node of data and not really with imported data, I can't figure out much on this. This will be attaching roughly 300 rows of tract data with IDs to the nodes containing spatial point geometry data.

This is the tract data being imported:

LOAD CSV WITH HEADERS
FROM "file:///Data-Census-clean_cen.csv" AS row
MERGE (geo_id: GEOID {GEOID: row.GEOID})
    ON CREATE SET  geo_id.Total_population = row.Total_population, geo_id.housing_units = row.Housing_unit, geo_id.number_families = row.Number_Families, geo_id.household_income = row.Household_Income, geo_id.per_black = row.Per_Black, geo_id.per_asian = row.Per_Asian, geo_id.per_white = row.Per_White;

which returns

enter image description here

enter image description here

These are the existing properties from tract nodes with GEOID being what I want to join on.

enter image description here

Upvotes: 0

Views: 33

Answers (1)

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6524

You can try the following query:

MATCH (t:Tract), (g:GEOID)
WHERE t.GEOID = g.GEOID
MERGE (t)-[:BELONGS_TO]->(g)

You could have created the relationship during the initial import as well. Make sure you have indexes setup on GEOID properties for faster queries.

Upvotes: 1

Related Questions