Line Object Service

Service for accessing the line object. It is possible to use a Get and Set method for getting object specific data. Line objects can be e.g. roughness or elevation data. A small example can be found below.

import time
import os
from windproapi.utils import get_windpro_sample_path
from windproapi import WindProApi
from windproapi import nan_to_skipvalue

# Opening windPRO
_windproapi = WindProApi()
working_dir = os.path.join(get_windpro_sample_path('3.6'), 'Ebeltoft - Denmark\\3.6')
project_path = os.path.join(working_dir, 'DEMO - Ebeltoft, DK.w36p')

_windproapi.start_windpro_random_port()

# Services
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
obj_line_service = _windproapi.get_service('ObjLineService')

# Loading project
project_service.LoadFromFile(filename=project_path)

objs = objects_service.GetObjects(apiObjType='HCData')

# Loading are object specific data
area_obj = obj_line_service.GetLineObject(objs[0].Handle)
print(area_obj)

A line object can be added with the ObjectService. But to make it usable it needs to be connected to a file containing the line data. Most elevation data in windPRO’s online data catalogue is provided as grid data. An example how to downlaod elevation grid data and convert them to a line obejct is added below:

import windproapi.windproapi
import time
import os
from windproapi.utils import get_windpro_sample_path
from windproapi import WindProApi
from windproapi import nan_to_skipvalue

# Opening windPRO
_windproapi = WindProApi()
working_dir = os.path.join(get_windpro_sample_path('3.6'), 'ObjElevationGridService')
os.makedirs(working_dir, exist_ok=True)
project_path = os.path.join(working_dir, 'ObjElevationGridService.w36p')

_windproapi.start_windpro_random_port()

# Services
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
obj_elevation_grid_service = _windproapi.get_service('ObjElevationGridService')
online_data_service = _windproapi.get_service('OnlineDataService')
obj_line_service = _windproapi.get_service('ObjLineService')

lat, lng = 52.738533, 12.405603
project_service.NewProject(lng=lng, lat=lat, filename=working_dir)

# Downloading elevation grid data from online data
online_data_service.PrepareService(dataType='ODSTerrainGrid', lat=lat, lon=lng)
handle = online_data_service.DownloadHeightData(dataType='ODSTerrainGrid',
                                                implId='DEUBRA05_Grid',
                                                userDesc='German Brandenburg Elevation Model',
                                                lat=lat,
                                                lon=lng,
                                                width=3_000,
                                                height=3_000,
                                                useAsTin=False)

# Getting information of the object
grid_obj = obj_elevation_grid_service.GetElevationGridObject(handle=handle)
print(grid_obj)

# Settings used later for conversion: No single hill tops and troughs. connects lines that are not closed.
grid_obj.GridToHcSetup.Items.TApiGridToHCSetupItem[0].AddMonoAreas = False
grid_obj.GridToHcSetup.Items.TApiGridToHCSetupItem[0].ConnectLines = True
nan_to_skipvalue(grid_obj)
obj_elevation_grid_service.SetElevationGridObject(grid_obj)

# Path by name of layer and converting
temp_path = os.path.join(working_dir, 'converted_grid_to_line.wpo')
obj_elevation_grid_service.ConvertToLines(handle=handle, filename=temp_path)

# Making a new line object and adding the previously generated file to it
new_handle = objects_service.AddObject(apiObjType='HCData',
                                       lat=grid_obj.Lat,
                                       lng=grid_obj.Lng,
                                       userDesc=grid_obj.UserDescription).Handle
line_obj = obj_line_service.GetLineObject(new_handle)
line_obj.Filename = temp_path
nan_to_skipvalue(line_obj)
res = obj_line_service.SetLineObject(line_obj)