openstreetmapoverpass-api

How to Display Municipalities Without Notaries in a Department Using Overpass Turbo?


With this query, I obtain the contours of the Gironde department as well as the municipalities where notaries are located, represented either by a node or a way. However, I would like to reverse the process, that is, to identify the municipalities where there are no notaries and draw their contours.

[out:xml][timeout:25];

// Locate the area corresponding to the Gironde department
area["ref:INSEE"="33"]->.a;

// Search for notaries within the selected area (both as nodes and ways)
(
  node(area.a)["lawyer"="notary"];
  node(area.a)["office"="notary"];
  way(area.a)["lawyer"="notary"];
  way(area.a)["office"="notary"];
)->.notaires;

// Separate nodes and ways to process them individually
node.notaires->.notaire_nodes;
way.notaires->.notaire_ways;

// Identify administrative areas where the notaries (nodes) are located
.notaire_nodes is_in -> .potential_areas_nodes;
area.potential_areas_nodes[admin_level=8]->.commune_areas_nodes;

// Identify administrative areas (communes) where the notaries (ways) are located
way.notaire_ways->.ways_notaires;
(way.ways_notaires; >;); // Retrieve all nodes from the ways
is_in -> .potential_areas_ways;
area.potential_areas_ways[admin_level=8]->.commune_areas_ways;

// Combine the communes found for both nodes and ways
(.commune_areas_nodes; .commune_areas_ways;)->.all_communes_with_notaires;

// Find the boundaries of all communes within the Gironde department (admin_level=8)
rel(area.a)["boundary"="administrative"]["admin_level"="8"]->.all_communes;

// Extract the boundaries of the communes that contain notaries
rel.all_communes(pivot.all_communes_with_notaires)->.communes_with_notaires_rel;

// Get the boundary of the entire Gironde department (admin_level=6)
rel(area.a)["boundary"="administrative"]["admin_level"="6"]->.departement;

// Display the notaries (both nodes and ways), the boundaries of communes with notaries, and the department's boundary
(   
  .notaires;
  rel.departement;
  rel.communes_with_notaires_rel;
);
out geom;

Thank you in advance for your help.


Solution

  • You can use the difference method (.a; - .b;) -> .c;.
    In your code with (.all_communes; - .communes_with_notaires_rel;) -> .communes_without_notaires_rel; as follows:

    [out:xml][timeout:25];
    
    // Locate the area corresponding to the Gironde department
    area["ref:INSEE"="33"]->.a;
    
    // Search for notaries within the selected area (both as nodes and ways)
    (
      node(area.a)["lawyer"="notary"];
      node(area.a)["office"="notary"];
      way(area.a)["lawyer"="notary"];
      way(area.a)["office"="notary"];
    )->.notaires;
    
    // Separate nodes and ways to process them individually
    node.notaires->.notaire_nodes;
    way.notaires->.notaire_ways;
    
    // Identify administrative areas where the notaries (nodes) are located
    .notaire_nodes is_in -> .potential_areas_nodes;
    area.potential_areas_nodes[admin_level=8]->.commune_areas_nodes;
    
    // Identify administrative areas (communes) where the notaries (ways) are located
    way.notaire_ways->.ways_notaires;
    (way.ways_notaires; >;); // Retrieve all nodes from the ways
    is_in -> .potential_areas_ways;
    area.potential_areas_ways[admin_level=8]->.commune_areas_ways;
    
    // Combine the communes found for both nodes and ways
    (.commune_areas_nodes; .commune_areas_ways;)->.all_communes_with_notaires;
    
    // Find the boundaries of all communes within the Gironde department (admin_level=8)
    rel(area.a)["boundary"="administrative"]["admin_level"="8"]->.all_communes;
    
    // Extract the boundaries of the communes that contain notaries
    rel.all_communes(pivot.all_communes_with_notaires)->.communes_with_notaires_rel;
    
    // Get the boundary of the entire Gironde department (admin_level=6)
    rel(area.a)["boundary"="administrative"]["admin_level"="6"]->.departement;
    
    // Get the communes without notaires
    (.all_communes; - .communes_with_notaires_rel;) -> .communes_without_notaires_rel;
    .communes_without_notaires_rel;
    
    out geom;