public void CanCalculateProjectBoundaryArea() { var geometryWKT = "POLYGON((-115.025723657623 36.2101347890754,-115.026281557098 36.2056332151707,-115.018041811005 36.205460072542,-115.017698488251 36.2102040420362, -115.025723657623 36.2101347890754))"; var area = GeofenceValidation.CalculateAreaSqMeters(geometryWKT); Assert.Equal(375300.594251673, area, 5); }
private async Task <int> CreateGeofenceAndAssociation(ProjectDataModel project) { var geofence = new Geofence().Setup(); geofence.GeofenceUID = Guid.NewGuid().ToString(); geofence.Name = project.Name; geofence.GeofenceType = GeofenceType.Project; geofence.GeometryWKT = project.Boundary; geofence.CustomerUID = project.CustomerUID; var area = GeofenceValidation.CalculateAreaSqMeters(project.Boundary); geofence.AreaSqMeters = area > 1000000000 ? 0 : area; geofence.IsDeleted = false; geofence.LastActionedUTC = DateTime.UtcNow; string formattedPolygon = RepositoryHelper.WKTToSpatial(project.Boundary); string insert = string.Format( "INSERT Geofence " + " (GeofenceUID, Name, Description, PolygonST, FillColor, IsTransparent, IsDeleted, fk_CustomerUID, UserUID, LastActionedUTC, fk_GeofenceTypeID, AreaSqMeters) " + " VALUES " + " (@GeofenceUID, @Name, @Description, {0}, @FillColor, @IsTransparent, @IsDeleted, @CustomerUID, @UserUID, @LastActionedUTC, @GeofenceType, @AreaSqMeters)", formattedPolygon); var upsertedCount = await ExecuteWithAsyncPolicy(insert, geofence); Log.LogDebug( $"ProjectRepository/UpsertGeofence inserted. upsertedCount {upsertedCount} rows for: geofenceUid:{geofence.GeofenceUID}"); if (upsertedCount == 1) { var projectGeofence = new ProjectGeofence() { ProjectUID = project.ProjectUID, GeofenceUID = geofence.GeofenceUID, LastActionedUTC = DateTime.UtcNow }; await AssociateProjectGeofence(projectGeofence, null); return(upsertedCount); } return(0); }
public void ValidateGeofence_CalculateArea() { var result = GeofenceValidation.CalculateAreaSqMeters(_validBoundary); Assert.Equal(14585, (int)result); }