WTG Areas Object Service

The ObjWtgAreasService is giving access to WTG area objects. To make a new wtg object, you can use the ObjectService. Then getting the properties of the wtg with the ObjWtgAreasService.GetWtgAreasObject. These properties can be manipulated and then send back to windPRO with ObjWtgAreasService.SetWtgAreasObject. Multiple areas can be added within one wtg area object. To make a new area you must use special objects that can be accessed via windproapi.get_factory('WindproService'). Make a new WTG area with factory.TApiObjWtgArea() and append points using factory.TApiGP() to it. These points are the border of the single WTG area. You can also define a WTG area as an exclusion zone by setting wtg_area.ExclusionArea=True. Properties of the object can be found here TApiObjWtgAreas.

"""
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'), 'ObjWtgAreasService')
os.makedirs(working_dir, exist_ok=True)
_windproapi.start_windpro_random_port()

# Services
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
obj_wtg_areas_aervice = _windproapi.get_service('ObjWtgAreasService')

# For more complex datatypes
factory = _windproapi.get_factory('WindproService')

# Project path and location
project_path = os.path.join(working_dir, 'ObjWtgAreasService.w36p')
lng = 11.2
lat = 56.6

# Making a new empty project and saving it
project_service.NewProject(lng=lng, lat=lat, filename=project_path)

# Making new WTG area object and getting its parameters
obj = objects_service.AddObject(apiObjType='WTGareas',
                                lat=lat,
                                lng=lng,
                                userDesc='New are for wind farm')
wtg_areas_object = obj_wtg_areas_aervice.GetWtgAreasObject(obj.Handle)

# Paramter holding multiple WTG areas in a formate understandable for windPRO
wtg_areas_object.AreaList = factory.TApiObjWtgAreaList()

# This is to make a new WTG area
# It needs some information to be set into windPRO. This is a minimal example.
wtg_area = factory.TApiObjWtgArea()
wtg_area.Name = 'New area'
# For the style of the line. See tns:TApiBrushStyle
wtg_area.Hatching = 'ApiBsClear'
# We need a list of points that define the area
print(wtg_area.Points)

lats = [56.5, 56.58, 56.68, 56.68, 56.70, 56.70, 56.60, 56.56]
lngs = [11.2, 11.20, 11.17, 11.19, 11.18, 11.21, 11.26, 11.33]
# This will be the input to the wtg_are.Points.
# Making a list of points that are appended here
wtg_area.Points = factory.TApiGPs()
for i_lat, i_lng in zip(lats, lngs):
    newGP = factory.TApiGP()
    newGP.Lat = i_lat
    newGP.Lng = i_lng
    wtg_area.Points.TApiGP.append(newGP)

# We can add e.g. a buffer zone
wtg_area.BufferZone = 500.0

# We can add minum and maximum number o fturbines
wtg_area.CountDemand = True
wtg_area.MinCount = 20
wtg_area.MaxCount = 60

# We can add a minimum and maximum power
wtg_area.EffectDemand = True
wtg_area.MinEffect = 50_000
wtg_area.MaxEffect = 200_000

# Appending the WTG area to the WTG areas. There can in principle be more than one.
wtg_areas_object.AreaList.TApiObjWtgArea.append(wtg_area)

# Giving data back to windPRO
nan_to_skipvalue(wtg_areas_object)
obj_wtg_areas_aervice.SetWtgAreasObject(wtg_areas_object)

wtg_areas_object = obj_wtg_areas_aervice.GetWtgAreasObject(obj.Handle)
print(wtg_areas_object)