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. Properties of the object can be found here TApiObjElevationGrid. A small example can be found below.

Elevationgrids 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'), '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)