2

I'm working with shapefiles of existing road surface markings, in QGIS. The shapefile with markings of road crossings (i.e. crosswalks or zebras) is of the polygon type. Hence I'm struggling how to set symbology to match the realistic rotations of each road crossing.

Is there a way to set the rotation of a polygon shapefile symbology (rotations of each feature of the polygon shapefile, really), to match the rotation of a separate line shapefile (i.e. rotations of closest features of a line shapefile - in my case the line shapefile of road alignments)?

If I set for example its symbology as a combination of a 'simple fill' and 'line pattern fill' (white-black-white or white-transparent-white, which seems realistic when printed), I can only set rotation of the symbology as an angle. Same thing with setting symbology as 'raster image fill' or 'SVG fill' type. The problem is that setting an angle at a specific value will only work for the road crossings which fit that angle, with other road crossings such a symbology might be completely perpendicular to the existing road crossing marking.

The 'line pattern fill' offers additional options of data defined override of the fill rotation, but none of the options is of any use in my case.

Screenshot:

enter image description here

Does anybody have a solution?

4
  • Can you add a screenshot?
    – BERA
    Oct 14 at 11:42
  • I'm afraid you will have to change the geometry of the objects from polygons to lines to make the style work as expected. Oct 14 at 12:02
  • As per the help center please do not include chit chat like thanks and a sign-off in your posts.
    – PolyGeo
    Oct 14 at 12:34
  • @BERA Added a screenshot. As visible, 'crosswalk2' is rotated properly and fit for print, pending minor stylistic adjustment (width of white lines etc). But 'crosswalk' uses the same rotation, which is false by 90° compared to its intended rotation.
    – Peter
    Oct 14 at 13:06
2

enter image description here

  1. Create a new angle field.
  2. Let this field update automatically on edit using the formula: main_angle($geometry)
  3. Use this style.qml (see below) file and apply it to your layer with crosswalk polygons to rotate internal lines by an amount equal to -angle (minus angle value):
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="3.20.3-Odense" styleCategories="Symbology">
 <renderer-v2 symbollevels="0" enableorderby="0" forceraster="0" type="singleSymbol">
  <symbols>
   <symbol force_rhr="0" name="0" alpha="1" clip_to_extent="1" type="fill">
    <data_defined_properties>
     <Option type="Map">
      <Option name="name" type="QString" value=""/>
      <Option name="properties"/>
      <Option name="type" type="QString" value="collection"/>
     </Option>
    </data_defined_properties>
    <layer pass="0" class="CentroidFill" enabled="1" locked="0">
     <Option type="Map">
      <Option name="clip_on_current_part_only" type="QString" value="0"/>
      <Option name="clip_points" type="QString" value="0"/>
      <Option name="point_on_all_parts" type="QString" value="1"/>
      <Option name="point_on_surface" type="QString" value="0"/>
     </Option>
     <prop k="clip_on_current_part_only" v="0"/>
     <prop k="clip_points" v="0"/>
     <prop k="point_on_all_parts" v="1"/>
     <prop k="point_on_surface" v="0"/>
     <data_defined_properties>
      <Option type="Map">
       <Option name="name" type="QString" value=""/>
       <Option name="properties"/>
       <Option name="type" type="QString" value="collection"/>
      </Option>
     </data_defined_properties>
     <symbol force_rhr="0" name="@0@0" alpha="1" clip_to_extent="1" type="marker">
      <data_defined_properties>
       <Option type="Map">
        <Option name="name" type="QString" value=""/>
        <Option name="properties"/>
        <Option name="type" type="QString" value="collection"/>
       </Option>
      </data_defined_properties>
      <layer pass="0" class="FilledMarker" enabled="1" locked="0">
       <Option type="Map">
        <Option name="angle" type="QString" value="0"/>
        <Option name="color" type="QString" value="255,0,0,255"/>
        <Option name="horizontal_anchor_point" type="QString" value="1"/>
        <Option name="name" type="QString" value="arrow"/>
        <Option name="offset" type="QString" value="0,0"/>
        <Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="offset_unit" type="QString" value="MM"/>
        <Option name="scale_method" type="QString" value="diameter"/>
        <Option name="size" type="QString" value="13.6"/>
        <Option name="size_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="size_unit" type="QString" value="MM"/>
        <Option name="vertical_anchor_point" type="QString" value="1"/>
       </Option>
       <prop k="angle" v="0"/>
       <prop k="color" v="255,0,0,255"/>
       <prop k="horizontal_anchor_point" v="1"/>
       <prop k="name" v="arrow"/>
       <prop k="offset" v="0,0"/>
       <prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="offset_unit" v="MM"/>
       <prop k="scale_method" v="diameter"/>
       <prop k="size" v="13.6"/>
       <prop k="size_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="size_unit" v="MM"/>
       <prop k="vertical_anchor_point" v="1"/>
       <data_defined_properties>
        <Option type="Map">
         <Option name="name" type="QString" value=""/>
         <Option name="properties" type="Map">
          <Option name="angle" type="Map">
           <Option name="active" type="bool" value="true"/>
           <Option name="expression" type="QString" value="&quot;angle&quot;"/>
           <Option name="type" type="int" value="3"/>
          </Option>
         </Option>
         <Option name="type" type="QString" value="collection"/>
        </Option>
       </data_defined_properties>
       <symbol force_rhr="0" name="@@0@0@0" alpha="1" clip_to_extent="1" type="fill">
        <data_defined_properties>
         <Option type="Map">
          <Option name="name" type="QString" value=""/>
          <Option name="properties"/>
          <Option name="type" type="QString" value="collection"/>
         </Option>
        </data_defined_properties>
        <layer pass="0" class="SimpleFill" enabled="1" locked="0">
         <Option type="Map">
          <Option name="border_width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
          <Option name="color" type="QString" value="255,0,0,255"/>
          <Option name="joinstyle" type="QString" value="bevel"/>
          <Option name="offset" type="QString" value="0,0"/>
          <Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
          <Option name="offset_unit" type="QString" value="MM"/>
          <Option name="outline_color" type="QString" value="35,35,35,255"/>
          <Option name="outline_style" type="QString" value="solid"/>
          <Option name="outline_width" type="QString" value="0"/>
          <Option name="outline_width_unit" type="QString" value="MM"/>
          <Option name="style" type="QString" value="solid"/>
         </Option>
         <prop k="border_width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
         <prop k="color" v="255,0,0,255"/>
         <prop k="joinstyle" v="bevel"/>
         <prop k="offset" v="0,0"/>
         <prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
         <prop k="offset_unit" v="MM"/>
         <prop k="outline_color" v="35,35,35,255"/>
         <prop k="outline_style" v="solid"/>
         <prop k="outline_width" v="0"/>
         <prop k="outline_width_unit" v="MM"/>
         <prop k="style" v="solid"/>
         <data_defined_properties>
          <Option type="Map">
           <Option name="name" type="QString" value=""/>
           <Option name="properties"/>
           <Option name="type" type="QString" value="collection"/>
          </Option>
         </data_defined_properties>
        </layer>
       </symbol>
      </layer>
     </symbol>
    </layer>
    <layer pass="0" class="SimpleLine" enabled="1" locked="0">
     <Option type="Map">
      <Option name="align_dash_pattern" type="QString" value="0"/>
      <Option name="capstyle" type="QString" value="square"/>
      <Option name="customdash" type="QString" value="5;2"/>
      <Option name="customdash_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="customdash_unit" type="QString" value="MM"/>
      <Option name="dash_pattern_offset" type="QString" value="0"/>
      <Option name="dash_pattern_offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="dash_pattern_offset_unit" type="QString" value="MM"/>
      <Option name="draw_inside_polygon" type="QString" value="0"/>
      <Option name="joinstyle" type="QString" value="bevel"/>
      <Option name="line_color" type="QString" value="0,0,0,255"/>
      <Option name="line_style" type="QString" value="solid"/>
      <Option name="line_width" type="QString" value="0.4"/>
      <Option name="line_width_unit" type="QString" value="MM"/>
      <Option name="offset" type="QString" value="0"/>
      <Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="offset_unit" type="QString" value="MM"/>
      <Option name="ring_filter" type="QString" value="0"/>
      <Option name="trim_distance_end" type="QString" value="0"/>
      <Option name="trim_distance_end_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="trim_distance_end_unit" type="QString" value="MM"/>
      <Option name="trim_distance_start" type="QString" value="0"/>
      <Option name="trim_distance_start_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="trim_distance_start_unit" type="QString" value="MM"/>
      <Option name="tweak_dash_pattern_on_corners" type="QString" value="0"/>
      <Option name="use_custom_dash" type="QString" value="0"/>
      <Option name="width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
     </Option>
     <prop k="align_dash_pattern" v="0"/>
     <prop k="capstyle" v="square"/>
     <prop k="customdash" v="5;2"/>
     <prop k="customdash_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="customdash_unit" v="MM"/>
     <prop k="dash_pattern_offset" v="0"/>
     <prop k="dash_pattern_offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="dash_pattern_offset_unit" v="MM"/>
     <prop k="draw_inside_polygon" v="0"/>
     <prop k="joinstyle" v="bevel"/>
     <prop k="line_color" v="0,0,0,255"/>
     <prop k="line_style" v="solid"/>
     <prop k="line_width" v="0.4"/>
     <prop k="line_width_unit" v="MM"/>
     <prop k="offset" v="0"/>
     <prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="offset_unit" v="MM"/>
     <prop k="ring_filter" v="0"/>
     <prop k="trim_distance_end" v="0"/>
     <prop k="trim_distance_end_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="trim_distance_end_unit" v="MM"/>
     <prop k="trim_distance_start" v="0"/>
     <prop k="trim_distance_start_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="trim_distance_start_unit" v="MM"/>
     <prop k="tweak_dash_pattern_on_corners" v="0"/>
     <prop k="use_custom_dash" v="0"/>
     <prop k="width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <data_defined_properties>
      <Option type="Map">
       <Option name="name" type="QString" value=""/>
       <Option name="properties"/>
       <Option name="type" type="QString" value="collection"/>
      </Option>
     </data_defined_properties>
    </layer>
    <layer pass="0" class="LinePatternFill" enabled="1" locked="0">
     <Option type="Map">
      <Option name="angle" type="QString" value="0"/>
      <Option name="color" type="QString" value="0,0,255,255"/>
      <Option name="distance" type="QString" value="10"/>
      <Option name="distance_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="distance_unit" type="QString" value="MM"/>
      <Option name="line_width" type="QString" value="0.26"/>
      <Option name="line_width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="line_width_unit" type="QString" value="MM"/>
      <Option name="offset" type="QString" value="0"/>
      <Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="offset_unit" type="QString" value="MM"/>
      <Option name="outline_width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
      <Option name="outline_width_unit" type="QString" value="MM"/>
     </Option>
     <prop k="angle" v="0"/>
     <prop k="color" v="0,0,255,255"/>
     <prop k="distance" v="10"/>
     <prop k="distance_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="distance_unit" v="MM"/>
     <prop k="line_width" v="0.26"/>
     <prop k="line_width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="line_width_unit" v="MM"/>
     <prop k="offset" v="0"/>
     <prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="offset_unit" v="MM"/>
     <prop k="outline_width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
     <prop k="outline_width_unit" v="MM"/>
     <data_defined_properties>
      <Option type="Map">
       <Option name="name" type="QString" value=""/>
       <Option name="properties" type="Map">
        <Option name="lineAngle" type="Map">
         <Option name="active" type="bool" value="true"/>
         <Option name="expression" type="QString" value="-&quot;angle&quot;"/>
         <Option name="type" type="int" value="3"/>
        </Option>
       </Option>
       <Option name="type" type="QString" value="collection"/>
      </Option>
     </data_defined_properties>
     <symbol force_rhr="0" name="@0@2" alpha="1" clip_to_extent="1" type="line">
      <data_defined_properties>
       <Option type="Map">
        <Option name="name" type="QString" value=""/>
        <Option name="properties"/>
        <Option name="type" type="QString" value="collection"/>
       </Option>
      </data_defined_properties>
      <layer pass="0" class="SimpleLine" enabled="1" locked="0">
       <Option type="Map">
        <Option name="align_dash_pattern" type="QString" value="0"/>
        <Option name="capstyle" type="QString" value="square"/>
        <Option name="customdash" type="QString" value="5;2"/>
        <Option name="customdash_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="customdash_unit" type="QString" value="MM"/>
        <Option name="dash_pattern_offset" type="QString" value="0"/>
        <Option name="dash_pattern_offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="dash_pattern_offset_unit" type="QString" value="MM"/>
        <Option name="draw_inside_polygon" type="QString" value="0"/>
        <Option name="joinstyle" type="QString" value="bevel"/>
        <Option name="line_color" type="QString" value="0,0,255,255"/>
        <Option name="line_style" type="QString" value="solid"/>
        <Option name="line_width" type="QString" value="0.26"/>
        <Option name="line_width_unit" type="QString" value="MM"/>
        <Option name="offset" type="QString" value="0"/>
        <Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="offset_unit" type="QString" value="MM"/>
        <Option name="ring_filter" type="QString" value="0"/>
        <Option name="trim_distance_end" type="QString" value="0"/>
        <Option name="trim_distance_end_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="trim_distance_end_unit" type="QString" value="Point"/>
        <Option name="trim_distance_start" type="QString" value="0"/>
        <Option name="trim_distance_start_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
        <Option name="trim_distance_start_unit" type="QString" value="Point"/>
        <Option name="tweak_dash_pattern_on_corners" type="QString" value="0"/>
        <Option name="use_custom_dash" type="QString" value="0"/>
        <Option name="width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
       </Option>
       <prop k="align_dash_pattern" v="0"/>
       <prop k="capstyle" v="square"/>
       <prop k="customdash" v="5;2"/>
       <prop k="customdash_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="customdash_unit" v="MM"/>
       <prop k="dash_pattern_offset" v="0"/>
       <prop k="dash_pattern_offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="dash_pattern_offset_unit" v="MM"/>
       <prop k="draw_inside_polygon" v="0"/>
       <prop k="joinstyle" v="bevel"/>
       <prop k="line_color" v="0,0,255,255"/>
       <prop k="line_style" v="solid"/>
       <prop k="line_width" v="0.26"/>
       <prop k="line_width_unit" v="MM"/>
       <prop k="offset" v="0"/>
       <prop k="offset_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="offset_unit" v="MM"/>
       <prop k="ring_filter" v="0"/>
       <prop k="trim_distance_end" v="0"/>
       <prop k="trim_distance_end_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="trim_distance_end_unit" v="Point"/>
       <prop k="trim_distance_start" v="0"/>
       <prop k="trim_distance_start_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <prop k="trim_distance_start_unit" v="Point"/>
       <prop k="tweak_dash_pattern_on_corners" v="0"/>
       <prop k="use_custom_dash" v="0"/>
       <prop k="width_map_unit_scale" v="3x:0,0,0,0,0,0"/>
       <data_defined_properties>
        <Option type="Map">
         <Option name="name" type="QString" value=""/>
         <Option name="properties"/>
         <Option name="type" type="QString" value="collection"/>
        </Option>
       </data_defined_properties>
      </layer>
     </symbol>
    </layer>
   </symbol>
  </symbols>
  <rotation/>
  <sizescale/>
 </renderer-v2>
 <blendMode>0</blendMode>
 <featureBlendMode>0</featureBlendMode>
 <layerGeometryType>2</layerGeometryType>
</qgis>

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.