Cut out polygon from other polygon

configuration-examples Cut out polygon from other polygon

The script presents an example to cut out a polygon from another polygon.

example

unit<uint32> Square : NrofRows = 1
{
   // create a square 
   attribute<meter> left   := const(      0,.,meter);
   attribute<meter> right  := const( 280000,.,meter);
   attribute<meter> top    := const( 625000,.,meter);
   attribute<meter> bottom := const( 300000,.,meter);

   attribute<rdc_meter> left_top     := point(   top, left,  rdc_meter);
   attribute<rdc_meter> right_top    := point(   top, right, rdc_meter);
   attribute<rdc_meter> right_bottom := point(bottom, right, rdc_meter);
   attribute<rdc_meter> left_bottom  := point(bottom, left,  rdc_meter);

   unit<uint32> pointset : nrofrows = 5
   {
      attribute<rdc_meter> coordr := union_data(., left_top, right_top, right_bottom, left_bottom, left_top);
   }

   attribute<rdc_meter> geometry   (polygon) := 
      points2sequence(pointset/coord, const(0, pointset, square), id(pointset));
   attribute<ipoint>    geometry_i (polygon) := ipolygon(geometry);

    // cut out polygon is for instance the boundary of the first municipality 
      (index numbers, here referred to as cut_out_polygon. 
  attribute<rdc_meter> square_with_polygon_cut_out (poly) := 
     (geometry_i - cut_out_polygon/geometry_i[0])[rdc_meter];
}

explanation

The example first configures a square polygon for the whole of the Netherlands.

The actual cutting out is done in the bold line. The - function is used to cut out the first geometry in the cut_out_polygon domain for instance the first municipality in the Netherlands, from the square.

The ipolygon conversion function is used as these vector functions only work on integer coordinates. The casting back to [rdc_meter] at the end of the expression is used to convert the integer coordinates back to the rdc_meter values-unit.