{"id":7335,"date":"2024-05-10T13:58:52","date_gmt":"2024-05-10T11:58:52","guid":{"rendered":"https:\/\/usemaps.com\/kb\/uncategorized\/simple-formulas\/"},"modified":"2024-05-10T13:58:52","modified_gmt":"2024-05-10T11:58:52","slug":"simple-formulas","status":"publish","type":"knowledgebase","link":"https:\/\/usemaps.com\/en\/usemaps-documentation\/definitions\/simple-formulas\/","title":{"rendered":"Simple Formulas"},"content":{"rendered":"<p>Simple Formulas are formulas that define automatic filling of attribute values. Attributes with a defined formula become locked for manual editing. The formula is recalculated every time the object is edited and also when the coordinate system of the data source is changed.  <\/p>\n<p><strong>Important:<\/strong><\/p>\n<ol>\n<li>Simple Formulas can only be used for calculations within a single attribute. To automate calculations across multiple attributes and layers, Advanced Formulas should be used. <\/li>\n<li>Before adding an attribute with a Simple Formula (a virtual attribute), make sure that the data source you are editing has the correct coordinate system.<\/li>\n<li><strong>How to change the coordinate system of a Data Source?<\/strong><\/li>\n<li>The default coordinate system for newly created data sources in the web version of the System is Mercator (EPSG:3857). If you choose to stay in this coordinate system but still expect correct attribute values, such as segment length, it is important to either use a function that transforms coordinates to the application\u2019s coordinate system (appropriate for your location\u2019s coordinate system: PL-2000).<\/li>\n<li>When creating virtual attributes, you should use the system field names, for example: <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">nazwa_custom<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong>What is this used for?<\/strong><\/h4>\n<p>This is a great tool when you need always up-to-date data for frequently edited objects, for example attributes like length, area, perimeter, or X and Y coordinates. A Simple Formula attribute can also be used for labeling layers, allowing this information to be included in prints. <\/p>\n<p>Using Simple Formulas simplifies and supports daily analytical work or the creation of statistics. For numeric values, it is recommended to choose the attribute data type: real number. <\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-1024x561.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-6011 size-large\" src=\"https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-1024x561.png\" alt=\"\" width=\"800\" height=\"438\" srcset=\"https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-1024x561.png 1024w, https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-300x164.png 300w, https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-768x421.png 768w, https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4-1536x841.png 1536w, https:\/\/usemaps.com\/wp-content\/uploads\/2024\/05\/Screenshot-4.png 1674w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<h4>Examples of formulas:<\/h4>\n<ul>\n<li>Combining values, i.e., concatenation of fields, for example Name and Description   <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">nazwa_custom || opis_custom<\/code><\/li>\n<li>Adding\/subtracting\/multiplying\/dividing the values of fields A and B: <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">A + B<\/code>\/ <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">A - B<\/code>\/ <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">A * B<\/code>\/<code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">A \/ B<\/code><\/li>\n<li>Maximum\/minimum\/average\/sum of field A: <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">MAX(A)<\/code>\/ <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">MIN(A)<\/code> \/ <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">AVG(A)<\/code> \/ <code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\">SUM(A)<\/code><\/li>\n<li>ST_X(geom) \u2013 the formula returns the X coordinate of a point in the data source\u2019s coordinate system<\/li>\n<li>ST_Y(geom) \u2013 the formula returns the Y coordinate of a point in the data source\u2019s coordinate system<\/li>\n<li>ST_Y(ST_Transform(geom,4326)) \u2013 the formula returns the Y value <em>\u2013 or X if changed to ST_X() \u2013<\/em> for a point in the EPSG:4326 (WGS84) coordinate system.<\/li>\n<li>ST_Length(geom) \u2013 the formula returns the length of the object in the units of the data source\u2019s coordinate system<\/li>\n<li>ST_Length(geom)::Numeric(10,2) \u2013 a variant of the above formula that returns the length in the coordinate system\u2019s units, rounded to two decimal places<\/li>\n<li><span class=\"ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">ST_Perimeter(geom) \u2013 a formula that returns the perimeter of a polygonal object, given in the units of the layer\u2019s coordinate system (usually meters)<\/span><\/li>\n<li>ST_Area(geom) \u2013 the formula returns the area of the object in the units of the coordinate system<\/li>\n<li>(ST_Area(geom)\/10000)::Numeric(10,4) \u2013 a variant of the above formula that returns the area in hectares, rounded to four decimal places, with the data type set as real number<\/li>\n<li>&#8216;https:\/\/openinframap.org\/#14.04\/&#8217; || CAST(ST_Y(ST_centroid(ST_Transform(geom,4326))) AS varchar(20)) || &#8216;\/&#8217; || CAST(ST_X(ST_centroid(ST_Transform(geom,4326))) AS varchar(20)) || &#8216;\/L,P,S&#8217; \u2013 a formula that creates a link to the OpenInfrastructureMap portal, zooming to the centroid of the polygon.<code class=\"code css-1o5d2cw\" data-renderer-mark=\"true\"><\/code><\/li>\n<\/ul>\n<p>What happens if, when trying to save an attribute using a Simple Formula, the System returns an \u201cinvalid content\u201d message to the user?<\/p>\n<p>Due to the variety of user data sources and layers, we recommend that if you receive such a message, you first replace the term <em>geom <\/em>in the formula with <em>geometry<\/em>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple Formulas are formulas that define automatic filling of attribute values. Attributes with a defined formula become locked for manual editing. The formula is recalculated every time the object is edited and also when the coordinate system of the data source is changed. Important: Simple Formulas can only be used for calculations within a single [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","knowledgebase_cat":[83],"knowledgebase_tag":[],"class_list":["post-7335","knowledgebase","type-knowledgebase","status-publish","hentry","knowledgebase_cat-definitions"],"_links":{"self":[{"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/knowledgebase\/7335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/knowledgebase"}],"about":[{"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/types\/knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/comments?post=7335"}],"version-history":[{"count":0,"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/knowledgebase\/7335\/revisions"}],"wp:attachment":[{"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/media?parent=7335"}],"wp:term":[{"taxonomy":"knowledgebase_cat","embeddable":true,"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/knowledgebase_cat?post=7335"},{"taxonomy":"knowledgebase_tag","embeddable":true,"href":"https:\/\/usemaps.com\/en\/wp-json\/wp\/v2\/knowledgebase_tag?post=7335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}