Expression List

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

SAMPLE EXPRESSION - 1 Nov 2015, QGIS 2.

12
IMPORTANT
1. Name given for field are suggestion only. For more details in naming Shapefiles please refer to GDB
guidelines.
2. All newly created field MUST provide description in the comment box.
3. All Shp must be in CRS 29873 , unless specified otherwise
4. all initial data (area, length, perimeter) are generated in meter.
A. CREATE NEW ATTRIBUTE DATA
Where to use : Attribute table.

ITEM & EXPRESSION

NEW FIELD

Area in Ha

Shp : Polygon

ArGen_Ha=
$area /10000

Name : ArGen_Ha

Distance for River/road/traverse

Shp : Line

Dist_km =

$length in m , $length/1000 in km

Field: decimal, W20,P2

Perimeter of coupe/Area

Shp : Poly

$perimeter in m , $perimeter/1000 in km

Name : Peri_km
Field: decimal, W20,P2

Get Easting

Shp : Point

Peri_km =

Easting =
$x

Name : Easting
Field: decimal, W20,P3

Get Northing
5

Northing =
$y

Calculating Percentage of Area


Comt_Ha =
(Comt_Ha/5600) * 100
Create Bearing in decimal
(atan((xat(-1)-xat(0))/(yat(-1)yat(0)))) * 180/3.14159 + (180
*(((yat(-1)-yat(0)) < 0) + (((xat(-1)xat(0)) < 0 AND (yat(-1) - yat(0))
>0)*2)))

1 ha = 10,000 m2

Field: decimal, W20,P2


Name : Dist_km

NOTE

1km = 1000 m

1km = 1000 m

e.g. 818025.947

Shp : Point
Name : Northing
Field: decimal, W20,P3

e.g. 505015.934

Shp : Polygon
Name : Comt_Ha
Field: decimal, W20,P0

Field for compartment area.


5600 Total size of coupe

Shp : Line
Name : Bearing
Field: decimal, W20P5

To split line use Explode lines in


toolbox.
e.g. 311.24

B. CREATE NEW LABEL DATA


Where to use : Attribute table.

ITEM & EXPRESSION

NEW FIELD

Size of area

Shp : Poly
Name : L_ArGen

= 23,450 Ha

L_ArGen =
round(($area/10000),2) || ' Ha'

Field: text, W20

Percentage of each Compt = 11%


L_%_ArGen =
to_int((Comt_Ha/5600) * 100) || ' %'

Shp : Poly
Name : L_%_ArGen
Field: text, W5

GPS location = 4 12 34.4 , 116 25 12

Shp : Point
Name : Latitude
Field: text, W20

3
Latitude

floor ($x) || ' ' || floor((($x) - floor ($x)) * 60)


||'\'' || substr( (tostring(((($x) - floor ($x)) *
60) - floor((($x) - floor ($x)) * 60)) * 60),1,5)
|| '"'
Longitude

NOTE

(label % of Generated Area)


Get Sum of field for ArGen from
menu Vector Analysis tools,Basic
Statistics
Shpfile must be projected in CRS
4326 (not OTF)

Name : Latitude
Field: text, W20

floor ($y) || ' ' || floor((($y) - floor ($y)) * 60)


||'\'' || substr( (tostring(((($y) - floor ($y)) *
60) - floor((($y) - floor ($y)) * 60)) * 60),1,5)
|| '"'

Shp : Line
Create Bearing in DMS = 311 17' 43.19"
Name : L_Bearing
Field: text, W20
L_Bearing =
floor ((atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) <
0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))) || ' ' ||
floor((((atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0))
< 0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))) - floor ((atan((xat(-1)xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2))))) * 60) ||'\'' || substr(
(tostring(((((atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)yat(0)) < 0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))) - floor
((atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) +
(((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2))))) * 60) - floor((((atan((xat(-1)xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))) - floor ((atan((xat(-1)-xat(0))/(yat(-1)yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)-xat(0)) < 0 AND (yat(1) - yat(0)) >0)*2))))) * 60)) * 60),1,5) || '"'

2/4
2

C.FOR DIRECT LABELLING (NO NEW FIELD CREATED)


Where to use : Layer properties, Label, Label this layer with.

REQUIREMENT & EXPRESSION

FIELD DATA

Label all Main River ONLY


Rivname =
CASE WHEN "Category= MainRiver
Label all road like Jln Kg Millian 34km

Fields : RivName, Category,


Category content : Main River, Tributaries,

Roadname =
CASE WHEN "RoadName is NULL THEN '' ELSE "
RoadName " END || '\n' || CASE WHEN "
Dist_km" is NULL THEN '' ELSE (" L_Dist_km"
) END

Fields : RoadName, L_Dist_km,


Some Roadname cell is empty.
Some Dist_km cell is empty.

D. FOR DBASE MANAGEMENT


Where to use : Attribute table.

ITEM & EXPRESSION

NEW FIELD

NOTE

Add unique running number


No. =
$rownum

Name : No.
Field: text, W <5

numbers only, start from 1

Add text with unique running number

Name : Code
Field: text, W <255

Result: poly1, poly2, poly3

Code =
poly||$rownum
Convert text in ProjName and write to
L_Prjnm =
upper("ProjName)

Name : L_Prjnm
Field: text, W <255

Fields : ProjName

E. FOR QUERY
Where to use : Attribute table.
1

SAMPLE QUERY & EXPRESSION

FIELD DATA

Select only Acacia, Albizia and belian trees :

Shp type : point


Fields : TreeType

TreeType =
TreeType IN ( Acacia, Albizia,
Belian)

Content : Durian, Acacia,Albizia,Mango,Red Seraya,


White Seraya, Belian Yellow Seraya.

Select ALL Seraya Trees :


TreeType =
TreeType LIKE

%eraya%

3/4
3

E. FOR MAP COMPOSER


Where to use : Composer, Add new label, inside box under main properties:
1

SAMPLE QUERY & EXPRESSION

FIELD DATA

Printed [% now() %]

Printed 2015-11-03T11:59:14
date and time will be updated everytime map is
reprinted

4/4
4

You might also like