dotConnect for PostgreSQL Documentation
In This Topic
    Area and Distance Units
    In This Topic

    Some PostgreSQL functions accept an additional argument "unit", that allows setting measurement unit for function result. Particularly this applies to the functions, returning the length of an object, distances between objects, and area of objects.

    DbGeometry/DbGeography classes have their own methods to get these values (Length, Area, and Distance), however they cannot use this PostgreSQL-specific feature of selecting measurement units directly.

    User can specify the necessary measurement units with GeometryDistanceUnit / GeographyDistanceUnit and GeometryAreaUnit / GeographyAreaUnit settings. The default values of these settings are DistanceMeasurementUnit.Default and AreaMeasurementUnit.Default.

    var config = PgSqlEntityProviderConfig.Instance;
    config.SpatialOptions.GeometryDistanceUnit = DistanceMeasurementUnit.Meter;
    config.SpatialOptions.GeographyDistanceUnit = DistanceMeasurementUnit.Mile;
    config.SpatialOptions.GeometryAreaUnit = AreaMeasurementUnit.SquareKilometer;
    config.SpatialOptions.GeographyAreaUnit = AreaMeasurementUnit.Acre;
    
    
    Dim config = PgSqlEntityProviderConfig.Instance
    config.SpatialOptions.GeometryDistanceUnit = DistanceMeasurementUnit.Meter
    config.SpatialOptions.GeographyDistanceUnit = DistanceMeasurementUnit.Mile
    config.SpatialOptions.GeometryAreaUnit = AreaMeasurementUnit.SquareKilometer
    config.SpatialOptions.GeographyAreaUnit = AreaMeasurementUnit.Acre
    
    

    Alternatively, you may specify measurement units in the project config file. For this, you need to update or add the configSections element like it is described in the Entity Framework Provider Configuration section and then add the following Devart.Data.PostgreSql.Entity tag to the configuration tag:

     <Devart.Data.PostgreSql.Entity xmlns="http://devart.com/schemas/Devart.Data.PostgreSql.Entity/1.0">
      <SpatialOptions
        GeometryDistanceUnit="Meter" 
        GeographyDistanceUnit="Mile"
        GeometryAreaUnit="SquareKilometer"
        GeographyAreaUnit="Acre" />
     </Devart.Data.PostgreSql.Entity>
    

    Note: If you need to set multiple Entity Framework provider options for dotConnect for PostgreSQL, don't add multiple Devart.Data.PostgreSql.Entity tags. Specify all settings in one Devart.Data.PostgreSql.Entity tag.

    The following measurement units are available:

    DistanceMeasurementUnit:

    AreaMeasurementUnit:

    See Also

    Choosing Spatial Service  | Default SRID