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_xy(left,  top,    rdc_meter);
   attribute<rdc_meter> right_top    := point_xy(right, top,    rdc_meter);
   attribute<rdc_meter> right_bottom := point_xy(right, bottom, rdc_meter);
   attribute<rdc_meter> left_bottom  := point_xy(left,  bottom, rdc_meter);

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

   attribute<rdc_meter> geometry (polygon) :=
      points2polygon(pointset/coord, const(0, pointset, Square), id(pointset));

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

explanation

The example first configures a square Polygon for the whole of the Netherlands, with its corners in clockwise order.

The actual cutting out is done in the line defining square_with_polygon_cut_out. The - operator cuts the first geometry in the cut_out_polygon domain, for instance the first municipality in the Netherlands, out of the square. For fpoint and dpoint coordinates, as rdc_meter usually is, - applies geos_difference; for spoint and ipoint coordinates it applies bp_difference. For a source polygon that is not valid, use dms_difference instead; see polygon operators for all difference operators.