Area Object Service
The Area Object Service accesses area objects. It is possible to use a Get and Set method for getting access to the data and setting it in windPRO. It is possible to change the roughness class assigned to a certain area. Properties of the object can be found here TApiObjArea. An example to run the service can be found below.
"""
Copyright 2024 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.1'), 'New Salem', '4.1')
project_path = os.path.join(working_dir, 'New Salem.w41p')
_windproapi.start_windpro_random_port()
# Services
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
obj_area_service = _windproapi.get_service('ObjAreaService')
online_data_service = _windproapi.get_service('OnlineDataService')
windpro_service = _windproapi.get_service('WindproService')
factory = _windproapi.get_factory('WindproService')
# Loading New Salem project
project_service.LoadFromFile(filename=project_path)
# Downloading area data from online data
roughness_layer = objects_service.AddLayer(layerName='New Roughness Area', parentFolderHandle=0)
# Finding the site center latitude and longitude
site_center_obj = objects_service.GetObjects(apiObjType='SiteCenter')[0]
lat = site_center_obj.Lat
lng = site_center_obj.Lng
# Preparing download and
terrain_data_type = 'ODSRoughnessArea'
online_data_service.PrepareService(dataType=terrain_data_type, lat=lat, lon=lng)
terrain_services = online_data_service.GetServices(dataType=terrain_data_type)
print(terrain_services)
roughness_service_id = 'DataService_Rou_GlobCover'
roughness_handle = online_data_service.DownloadRoughnessData(dataType=terrain_data_type,
implId=roughness_service_id,
userDesc='Script added roughness',
lat=lat,
lon=lng,
width=30000,
height=30000)
# Loading information from the roughness file in ¨
area_obj = obj_area_service.GetAreaObject(roughness_handle)
# Setting roughness classes up for all items by 0.5
for item in area_obj.LTyp.LTypItems.TApiLTypItem:
item.Rou += 0.5
item.Name = 'increase roughness class by 0.5 from ' + item.Name
nan_to_skipvalue(area_obj)
obj_area_service.SetAreaObject(area_obj)
roughness_layer = objects_service.AddLayer(layerName='New Roughness Area imported from shape file', parentFolderHandle=0)
shape_file_path = os.path.join(os.path.dirname(__file__), '../data/shape_file/new_salem_roughness.shp')
coord_sys = windpro_service.GetCoorSysFromEPSG(32614)
obj = objects_service.AddObject(apiObjType='AreaObj',
lat = area_obj.Lat,
lng = area_obj.Lng,
userDesc = 'Imported from shape file')
# Setting the purpose of the new object to be roughness
area_obj = obj_area_service.GetAreaObject(handle=obj.Handle)
area_obj_purposes = factory.TApiAreaObjPurposes()
area_obj_purposes.TApiAreaObjPurpose.append('ApiapRoughness')
area_obj.Purposes = area_obj_purposes
area_obj.Filename = os.path.join(working_dir, 'imported_from_shp.w2r')
area_obj['RouBack'] = 1
nan_to_skipvalue(area_obj)
obj_area_service.SetAreaObject(area_obj)
res = obj_area_service.ImportFromSHPFile(handle=area_obj.Handle,
fn=shape_file_path,
DataColumn=2,
coorsys=coord_sys,
LayerNewName='',
LayerExiName='',
RadiusOrWidth=50000,
LineAsPolygon=False)
# Adding a new background roughness
# The Id needs to be -111111111 which will change in the future
area_obj = obj_area_service.GetAreaObject(handle=obj.Handle)
TApiLTypItem = factory.TApiLTypItem()
TApiLTypItem.Rou = 0.01
TApiLTypItem.Id = -111111111
TApiLTypItem.Name = 'BACKGROUND'
TApiLTypItem.IsBackRou = True
area_obj.LTyp.LTypItems.TApiLTypItem.append(TApiLTypItem)
nan_to_skipvalue(area_obj)
obj_area_service.SetAreaObject(area_obj)