ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV, WEBDEV and WINDEV Mobile 2024 feature!
Help / WLanguage / Managing databases / HFSQL / 
  • Accessing spatial data: using spatial indexes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Calculates the distance between two geometries. For geometries other than points, this distance is calculated from the nearest points between the two geometries.

Example
Athens is PointGeo
Athens.Latitude = 37.971536
Athens.Longitude = 23.725750

Brussels is PointGeo
Brussels.Latitude = 50.8119483
Brussels.Longitude = 4.3826169

let dist = GeometryDistance(Athens, Brussels)
Trace("GeometryDistance(Athens, Brussels) = " + dist) // 2088389.078659 meters ~ 2088km
Syntax
<Result> = GeometryDistance(<Geometry A> , <Geometry B>)
<Result>: Real
Distance between nearest points of geometry A and geometry B.
  • For geometries defined with 2D coordinates, this distance is calculated using the Euclidean (Pythagorean) distance. The distance is returned in the same units as the point coordinates.
  • For geometries defined using geographic coordinates, this distance is calculated using the WGS84 reference system, which takes into account the curvature of the earth. The distance is returned in meters.
<Geometry A>: Variable containing spatial data
First geometry used. This geometry can correspond to one of the following variable types:
<Geometry B>: Variable containing spatial data
Second geometry used. This geometry can correspond to one of the following variable types:
Remarks

Accessing spatial data: using spatial indexes

In a data file, you can apply a filter on spatial data and loop through the file. For example, the filter can be based on the result of GeometryDistance.
It is recommended to use the following syntax to apply a filter on spatial data:
FOR EACH File WHERE WLanguage_function(File.Spatial_item, Spatial_variable)

where:
  • WLanguage_function corresponds to GeometryDistance.
  • Spatial_item is a spatial item in the data file. This item must:
    • be of type "Geographic data" or "Geometric data".
    • be defined as a "Spatial key".
  • Spatial_variable is a given spatial variable, used for comparison with the spatial item. This variable can be of type PolygonGeo, Polygon2D, etc.
Remark: The "FOR EACH File" syntax is available but not recommended, as it doesn't use spatial indexes and is therefore not optimized. In this case, the entire data file is looped through: spatial indexes are not used.
FOR EACH File
IF WLanguage_function(File.Spatial_item, Spatial_variable) = True THEN
   ...
   END
END
Example:
// Define a triangle delimiting a geographic area
// Store this triangle in a variable of type PolygonGeo 
polyGeo is PolygonGeo
polyGeo.Outline.AddPoint(0n48.8187479172765, 0n1.9550104465229536)
polyGeo.Outline.AddPoint(0n48.685649220185574, 0n2.023674998054354)
polyGeo.Outline.AddPoint(0n48.82612543243871, 0n2.2106580854197566)
polyGeo = GeometryCorrect(polyGeo)

// Search for municipalities with territory within the specified triangle
NumberOfRecords is int
// Distance less than 10 km from the boundaries of the triangle => 10,000 meters
FOR EACH MunicipalityData where GeometryDistance(MunicipalityData.geometry, polyGeo) <= 10000 
	// Name of municipality in a trace window
	Trace(MunicipalityData.MunicipalityName)
END
Business / UI classification: Business Logic
Component: wd290hf.dll
Minimum version required
  • Version 2024
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/28/2024

Send a report | Local help