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. Properties of the object can be found here TApiObjLine. A small example can be found below.
Line objects can be used as TIN.
You can control this with the property DefaultHC
.
If set to True it windPRO will set this property on all other elevation grid objects and line objects to False.
If no other object in the windPRO is used as TIN a newly added elevation grid will have True as default.
"""
Copyright 2023 EMD International
License for this script: MIT https://opensource.org/license/mit/
License for windPRO commercial software: https://www.emd-international.com/contact-us/general-terms-conditions-sale/
"""
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('4.0'), 'Ebeltoft - Denmark\\4.0')
project_path = os.path.join(working_dir, 'DEMO - Ebeltoft, DK.w40p')
_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 object is added below:
"""
Copyright 2023 EMD International
License for this script: MIT https://opensource.org/license/mit/
License for windPRO commercial software: https://www.emd-international.com/contact-us/general-terms-conditions-sale/
"""
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('4.0'), '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 = True
grid_obj.GridToHcSetup.Items.TApiGridToHCSetupItem[0].ConnectLines = True
# Changing the height contour lines distance to 2.0m
grid_obj.GridToHcSetup.DefaultEquidistance = 2.0
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)