1

I have street numbers with a specific field. I would like to show points with different colours based on this field and, on the same scale, display text of the street number itself, based on another field (black for apartment and red for basement shops).

Is there any way to make a condition for the colour without adding a new class (it looks like repetitions and longer procedure)?

0

1 Answer 1

1

This is an example of thematic symbolization with thematic labels. If the label filters are separate from the symbol filters, you need separate rules. This demonstrates symbolizing lines based on one field, and labelling based on another field:

  <FeatureTypeStyle>
    <Rule>
      <Name>LineColor1</Name>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>level</ogc:PropertyName>
          <ogc:Literal>Interstate</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#000000</CssParameter>
          <CssParameter name="stroke-width">7</CssParameter>
        </Stroke>
      </LineSymbolizer>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#FF0000</CssParameter>
          <CssParameter name="stroke-width">5</CssParameter>
        </Stroke>
      </LineSymbolizer>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#000000</CssParameter>
          <CssParameter name="stroke-width">1</CssParameter>
        </Stroke>
      </LineSymbolizer>
    </Rule>
  </FeatureTypeStyle>
  <FeatureTypeStyle>
    <Rule>
      <Name>LineColor2</Name>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>level</ogc:PropertyName>
          <ogc:Literal>State</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#808080</CssParameter>
          <CssParameter name="stroke-width">4</CssParameter>
        </Stroke>
      </LineSymbolizer>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#FF7F00</CssParameter>
          <CssParameter name="stroke-width">2</CssParameter>
        </Stroke>
      </LineSymbolizer>
    </Rule>
  </FeatureTypeStyle>
  <FeatureTypeStyle>
    <Rule>
      <Name>Other</Name>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>level</ogc:PropertyName>
          <ogc:Literal>Other</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#808080</CssParameter>
          <CssParameter name="stroke-width">4</CssParameter>
        </Stroke>
      </LineSymbolizer>
      <LineSymbolizer>
        <Stroke>
          <CssParameter name="stroke">#0000FF</CssParameter>
          <CssParameter name="stroke-width">2</CssParameter>
        </Stroke>
      </LineSymbolizer>
    </Rule>
  </FeatureTypeStyle>
  <FeatureTypeStyle>
    <Rule>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>type</ogc:PropertyName>
          <ogc:Literal>Major Highway</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <TextSymbolizer>
        <Label>
          <ogc:PropertyName>type</ogc:PropertyName>
        </Label>
        <Font>
          <CssParameter name="font-family">Arial</CssParameter>
          <CssParameter name="font-size">11</CssParameter>
          <CssParameter name="font-style">normal</CssParameter>
          <CssParameter name="font-weight">bold</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>0.5</AnchorPointY>
            </AnchorPoint>
          </PointPlacement>
        </LabelPlacement>
        <Fill>
          <CssParameter name="fill">#000000</CssParameter>
        </Fill>
        <VendorOption name="autoWrap">50</VendorOption>
        <VendorOption name="maxDisplacement">150</VendorOption>
        <Halo>
          <Radius>3</Radius>
          <Fill>
            <CssParameter name="fill">#FFFF0</CssParameter>
          </Fill>
        </Halo>
      </TextSymbolizer>
    </Rule>
  </FeatureTypeStyle>
  <FeatureTypeStyle>
      <Rule>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>type</ogc:PropertyName>
          <ogc:Literal>Secondary Highway</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <TextSymbolizer>
        <Label>
          <ogc:PropertyName>type</ogc:PropertyName>
        </Label>
        <Font>
          <CssParameter name="font-family">Arial</CssParameter>
          <CssParameter name="font-size">11</CssParameter>
          <CssParameter name="font-style">normal</CssParameter>
          <CssParameter name="font-weight">bold</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>0.5</AnchorPointY>
            </AnchorPoint>
          </PointPlacement>
        </LabelPlacement>
        <Fill>
          <CssParameter name="fill">#000000</CssParameter>
        </Fill>
        <VendorOption name="autoWrap">50</VendorOption>
        <VendorOption name="maxDisplacement">150</VendorOption>
        <Halo>
          <Radius>3</Radius>
          <Fill>
            <CssParameter name="fill">#808800</CssParameter>
          </Fill>
        </Halo>
      </TextSymbolizer>
    </Rule>
  </FeatureTypeStyle>

This is what it looks like:

enter image description here

3
  • Thank you for your reply, your sample looks well done, but my issue is a little bit different. Compared with yours, it’s like I have some of the “federal” with lines always orange and text with two different colours depending of other condition (for example 2, 3 or 4 lanes if we want to use your example).
    – Dario C
    Sep 14, 2021 at 5:20
  • Ok I think I slightly misunderstood what you are asking for. You'll actually need 4 rules (2 for the filters for the point symbols, and 2 for the labels). I'll update my answer later when I have time.
    – jbalk
    Sep 14, 2021 at 16:53
  • Check out my edits @DarioC
    – jbalk
    Sep 14, 2021 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.