3

I have a simple problem: I've got to spatially join records of an epidemic in forests to some plot coordinates I have gathered. Problem is, I cannot obtain the records for each year on each plot, I can either get the first record for each plot (not enough, since it's only one year) or get all those records but only after they've been transformed through either mean, min, max, median operation through the attribute summary choice I make, resulting in a single line but with data I can't exploit for my work.

I'd rather have duplicates of my rows (each corresponding to the state of the plot for a given year) so I can analyse the epidemic data year by year.

I am a first time user of QGIS: my data is stored in shapefiles, all of it (I created one out of my plot coordinates for a simple Excel sheet, and the rest was downloaded from here directly, shapefiles as well: http://www.donnees.gouv.qc.ca/?node=/donnees-details&id=2eed323f-e3fd-40cf-98c4-d0d25c52c404#meta_telechargement ; it's in French)

4
  • Welcome to GIS@SE, it would help a lot to get you sensible answers if you edited you question to specify where your data was stored? PostgreSQL, Shape Files, etc?? Oct 29, 2014 at 15:28
  • Done :) sorry about that
    – Chris. Z
    Oct 29, 2014 at 15:32
  • I may be misunderstanding the problem, but it sounds to me like a relationship issue. You have a many-to-one (records to plot) relationship. I don't know the particulars of QGIS, but ArcGIS doesn't handle this well (nor many-to-many relationships either). Similar to your experience it will return the first matching record and disregard others. The ArcGIS solution is the Make Query Table tool (where you end up with duplicate shapes for each record), or using a Relate. You might take a look at this question.
    – Chris W
    Oct 30, 2014 at 18:51
  • I'll have a look at this, thank you. I'm sorry if it was not clear in my post, I am just beginning to use the software. What I don't understand is why I can't just remove the function applied and create a separate row with the year instead of losing the information during the operation. I don't know if this is the same issue that ArgGIS has, the many-to-one relationship, but I will look into it. Thank you again.
    – Chris. Z
    Oct 30, 2014 at 20:33

3 Answers 3

2

It's a one-to-many relationship. Do an intersect instead. If you really want to keep the non relating records, use the ArcToolBox Spatial Join tool with the JOIN_ONE_TO_MANY option.

1
  • @Pierre that might work in Arc, but this question is tagged #qgis and I am looking for a QGIS way of doing the same thing... so I'd argue this question remains unanswered!?
    – Gonja
    Oct 19, 2016 at 9:53
2

You could use the Merge shapefiles to one function (Vector > Data Management > Merge shapefiles to one). This will combine all your records giving you duplicates aswell.

You can then use the Join attributes by location function (Vector > Data Management > *Join attributes by location) to spatially join your data.

The output layer should have all your records spatially joined, you can then add styles (Layer Properties > Styles) such as specific colours to filter each record by year or whatever.

Finally, because you have duplicates, you can run queries if you wish to see records for a specific year (Layer > Query...).

Hope this helps.

6
  • Thanks for your answer, but merging my .shp does not change the fact that once I go into the join tool, I still have to choose between getting the record from the first location or getting all but without being able to tell QGis I just want the raw records joined, not the transformed ones... For example, I have a record for my first plot where for 11 years, I have data on the epidemic, but I can't see each year separately.
    – Chris. Z
    Oct 29, 2014 at 15:29
  • Ahh apologies! An alternative way to join layers is via Layer Properties > Joins, provided both layers have a common field they can relate to each other with but it does depend on the attributes. Hopefully others will advise.
    – Joseph
    Oct 29, 2014 at 15:35
  • They don't really; all I have are my plot coordinates, so the spatial join was the way to go apparently.
    – Chris. Z
    Oct 29, 2014 at 15:39
  • What about selecting the Keep all records option when performing the join? I would assume this would join all the original attributes.
    – Joseph
    Oct 29, 2014 at 15:53
  • It does, and that's what I've been using from the beginning, but it does not supercede the attribute summary option to select, I can't leave all the function boxes unchecked, I have to at least select one...
    – Chris. Z
    Oct 29, 2014 at 15:56
1

It has to do with the way QGIS' spatial join is written. Based on the screenshots of it I see, there is no relationship parameter available. ArcGIS' spatial join does offer this capability.

You can't remove the function because it's a different... 'thing' or parameter of the join. The join has one attribute slot to fill, but multiple values to select from. Therefore it must use a function on the choices to get a single value or simply take the first one found. This is because all of your data has the same attribute names. For example the attribute in every source is called 'count'. If each of the yearly sources had the attribute named 'year-count' (where year varies between sources), then it would work.

Duplicating an identically named attribute is a different thing, based on the relationship of the join. The QGIS tool doesn't offer this from what I can see. The ArcGIS tool does using the Join Operation parameter (see linked help file above). If set correctly it would create a duplicate geometry for each instance of the attribute - meaning if you're creating points you get one point for each 'count' in all your sources, all stacked on top of one another.

I'm not clear on formats of your data and what your desired outcome is. It's possible that a spatial join is not the way you want to go. If you have polygons (plots) and year data (points), and you want the attributes from each year to become attributes of a single plot polygon, that method won't work (without renaming the attribute fields of the points to be unique). Other Overlay operations, such as Identity, Union, or Intersect, wouldn't work either. They would allow you to get the plot name as an attribute of the points, but not the other way around.

If you can better describe the current and desired format of your data (perhaps with screenshots of tables or just text examples), I may be able to edit a solution into this answer. Keep in mind that whatever analysis you want to do will play a role in the best way to organize the data. You might want to take a look at another question here: organizing attribute table: multiple sets of variables per point

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.