I have a .map file that contains two layers: The anchorage layer, the polygon along the border of which I draw symbols.
LAYER NAME "ACHARE_6" GROUP "Berthing" METADATA "ows_title" "Anchorage area (Line)" "ows_enable_request" "*" "wfs_enable_request" "*" "gml_include_items" "all" "wms_feature_mime_type" "text/html" END PROCESSING "LABEL_NO_CLIP=True" TEMPLATE blank.html TYPE LINE STATUS ON MAXSCALEDENOM 50000 CONNECTIONTYPE OGR CONNECTION "S57-GROUP/6/CL6_ACHARE_POLYGON.shp" DATA "SELECT * FROM CL6_ACHARE_POLYGON" # id-start: 341-CS(RESTRN01)_0 STYLE SYMBOL "CTYARE51_0" COLOR 197 69 195 INITIALGAP 12.0 GAP -24.0 SIZE 4.92 WIDTH 0.75 OPACITY 100 ANGLE AUTO END END # id-end: 342-CS(RESARE)_59 END And also a layer of land.
LAYER NAME "LNDARE_6" GROUP "Berthing" METADATA "ows_title" "Land area (Polygon)" "ows_enable_request" "*" "wfs_enable_request" "*" "gml_include_items" "all" "wms_feature_mime_type" "text/html" END PROCESSING "LABEL_NO_CLIP=True" TEMPLATE blank.html TYPE POLYGON STATUS ON MAXSCALEDENOM 125000 DATA "S57-GROUP/6/CL6_LNDARE_POLYGON.shp" # id-start: 424_0 CLASS STYLE COLOR 201 185 122 OPACITY 100 END LABEL # TX EXPRESSION ("[OBJNAM]" != "") TYPE TRUETYPE FONT SC PARTIALS TRUE FORCE TRUE # MINDISTANCE 0 # DOESNT WORK WITH 0 POSITION cc MAXLENGTH 8 WRAP " " SIZE 9 OFFSET -1 -1 COLOR 7 7 7 OUTLINECOLOR 255 255 255 TEXT '[OBJNAM]' END END # id-end: 424_0 END And also a few more layers for water, symbols and other things. As a result, I get this output image: 
My question is that I want to remove the contour that intersects with the ground. I want to see this result (screenshot from the s57 editor, SeeMyENC): 
This is an example of a schematic representation of my polygon from QGIS. I want to display the contour only based on water (marked in green), but I want to remove the contour for the part of the polygon that intersects with other objects (for example, land). 
How can I do this? I use s57 maps, ogr to get .shp files and MAPSERVER to display the map.