Elevation Grid Object ServiceΒΆ

Service for accessing the elevation grid object. It is possible to use a Get and Set method for getting object specific data. Further, it is possible to convert the elevation grid to a line object with ConvertToLines A small example can be found 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)