1

I am trying to create an autofill format on QGIS, based on an atlas.

There will be some dynamic text fields and some boxes which should be checked with an "x" in case the atlas geometry intersects a group of other geometries. Something like "IF $atlasgeometry intersects layer X OR Y OR.. OR Z, THEN check the box". Those layers are grouped, so it would be nice if i could call them all together in the script. The point is that i cannot find a single tutorial explaining how i should call map layers within the formulas, all the examples i see are about single geometries, and i have hundreds of them, so that would not work.

Could anyone explain me how that should work? And how the formula stucture should be?


Let me try to explain:

  1. We have a map layer on which there are some objects stored: they describe the geographic positions of some buildings. Each geometry is a building. Let's call the layer "Projects"
  2. We have some other layers containing the perimeters (=polygons) of the areas where some kind of jobs cannot be done or must have some features. Let's call them "Restraints A" "Restraints B" ...
  3. I need a script which says "IF "projects" intersects Restraints A, then write X in a certain text box.

The goal is creating a format which describes in a single sheet all the restraints i must respect in the definition of the project.

  • Could you describe a little more your dataset format and the goal of this process? From my experience, dynamic text field are pretty costly in computing time even sometime for simple fetching of a single geometry, so you'll probably need some pre-processing in your workflow. – MarHoff Oct 22 '15 at 7:04
  • Let me try to explain: 1) We have a map layer on which there are some objects stored: they describe the geographic positions of some buildings. Each geometry is a building. Let's call the layer "Projects" 2) We have some other layers containing the perimeters (=polygons) of the areas where some kind of jobs cannot be done or must have some features. Let's call them "Restraints A" "Restraints B" ... 3) I need a script which says "IF "projects" intersects Restraints A, then write X in a certain text box. – 987mies Oct 22 '15 at 7:26
  • The goal is creating a format which describes in a single sheet all the restraints i must respect in the definition of the project. – 987mies Oct 22 '15 at 7:38
2

Got it!

But first you must prepare the data a little cause you cant expect efficiency if you try to check upon every feature of every restraints layer for each target project.

So here are the steps:

  1. Dissolve all geometry of your restraint layer so the test is simplified because there will be only on unique feature to test for each restraint

  2. Merge all restraint layer into a new one lets call it "restraint_union" AND make sure it contain a new column name "col_restraint" which will store the name of the original restraint that generated each feature "restraint1","restraint2",...

  3. Add project layer and "restraint_union" to your QGis project

  4. Add as much virtual fields as you need in the project layer following using this expression intersects( $geometry , geometry( get_feature( 'restraint_union', 'col_restraint', 'restraint1')))

    This will return a boolean 1 if the project intersect restraint1 and 0 if not Do that for all restraints. Lest call it "restraint1_test".

  5. Now you project layer contain all information information needed about whether it intersect each constraint. Make your atlas using this layer and use as many additional expression as needed to render the information. Example :

    attribute( $atlasfeature, 'restraint1_test' )


PS: Step 2 is optional but it can help you have a cleaner project. Alternatively you could also keep all dissolved restraint layer separate.

  • Just had an epiphany will writing a more complicated answer... QGis don't cease to amaze me! – MarHoff Oct 22 '15 at 8:38
  • QGis is amazing. And your idea seems quite reasonable. You're moving the problem "inside" the project layer, i got it. I am just wondering how i should make the "x" appear in the box, though. Using a "IF"? I cannot find its syntax, though. – 987mies Oct 22 '15 at 8:43
  • Yes indeed, because intersects() will always return a boolean (1 or 0), so you will need to use some conditional to translate this information into the format you need ( 'X' or '' in your case). – MarHoff Oct 22 '15 at 8:47
  • Sorry, i am not an advanced user... What do you mean by "dissolving"? Deleting all additional fields? – 987mies Oct 22 '15 at 8:49
  • Well sorry i have taken a lot of time already to answer for today, but 'im sure a quick search can help you find out. Hint: look for Vectors menu> Geoprocessing tools>Dissolve – MarHoff Oct 22 '15 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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