# Getting landscape informations using the pythin API

**URL:** <https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963>\
**Category:** World Creation\
**Tags:** Python, landscapes, unreal-engine, Landscape, Scripting, question\
**Created:** [February 26, 2023, 2:28pm UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963 "2023-02-26T14:28:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damien220](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damien220/32/626350_2.png) [@Damien220](https://forums.unrealengine.com/u/Damien220)\
**Post date:** [February 26, 2023, 2:28pm UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/1 "2023-02-26T14:28:42Z")

</div>

Hello everyone…  
What i am trying to do is getting all information of a landscape ( width, height, num of components…), using the python API.

```auto
import unreal
l = unreal.EditorActorSubsystem().get_selected_level_actors()
all = unreal.EditorActorSubsystem().get_all_level_actors_components()
print(all)
#print(l)
#print(type(l[0]))
#print(l[0].is_editor_only_actor())
#print(unreal.Landscape().lod0_screen_size)
#print(unreal.LandscapeInfo(l[0]))
#landscape_info = l[0].get_landscape_info()
#landscape_info = l[0].create_landscape_info()

```

I was able to select the landscape in my level, but when trying to apply the methods available for the Landscape module, i always get " module Landscape has no property `method_name`", as well as there is a module named `LandscapeInfo` but it has no property or methods to use ([unreal.LandscapeInfo — Unreal Python 5.0 (Experimental) documentation](https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/LandscapeInfo.html)).  
So how can i get these information or components using the API, or even from cpp code. My goal is to use the script to make custom components because i want to train a machine learning model using that data.  
I hope i clarified my issue here, and to sum up, the python API for landscape module is not returning any useful data to use.

---

<div class="post-metadata">

**Author:** ![robeche](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robeche](https://forums.unrealengine.com/u/robeche)\
**Post date:** [April 26, 2023, 8:45am UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/2 "2023-04-26T08:45:30Z")

</div>

I’m having the same issue… did you find a solution?

Regards

Roberto

---

<div class="post-metadata">

**Author:** ![Damien220](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damien220/32/626350_2.png) [@Damien220](https://forums.unrealengine.com/u/Damien220)\
**Post date:** [May 24, 2023, 12:59pm UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/3 "2023-05-24T12:59:57Z")

</div>

Hi,  
Yeah but i did use the CPP API, and not the python API.  
If you’re intrested i can show you the code.

---

<div class="post-metadata">

**Author:** ![robeche](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robeche](https://forums.unrealengine.com/u/robeche)\
**Post date:** [May 31, 2023, 7:48am UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/4 "2023-05-31T07:48:34Z")

</div>

yes please!!

---

<div class="post-metadata">

**Author:** ![Damien220](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damien220/32/626350_2.png) [@Damien220](https://forums.unrealengine.com/u/Damien220)\
**Post date:** [June 7, 2023, 7:33pm UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/5 "2023-06-07T19:33:46Z")

</div>

Sorry for the late reply.  
Here is a snippet of the code you can use to handle landscapes in cpp:

```auto
Includes:
#include <Runtime/Landscape/Classes/Landscape.h>
//#include <Runtime/Landscape/Classes/LandscapeProxy.h>
#include <Runtime/Landscape/Classes/LandscapeInfo.h>
#include <Runtime/Landscape/Classes/landscapeComponent.h>

```

```auto
landactor = {};//holder of the landscape actor. In .h it is defined as: TArray<AActor*> landactor;

	UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), landactor);// get the landscape actor fron world and store it in a variable.
	
	for (AActor* actor : landactor) {
		//Get the landscape 
		ALandscape* land = Cast<ALandscape>(actor); // Making sure we are handling a lanscape actor.

		if (land) {
			// This will give the x,y,z of the landscape in the world.
			FTransform actorLandscapePosition = land->LandscapeActorToWorld();
			//FBox landbox = land->GetComponentsBoundingBox();

			auto comp = land->LandscapeComponents;// get components of the landscape
			if (comp.Num() > 0) {
				
				//ULandscapeInfo* landInfo = land->GetLandscapeInfo(); // not really useful
				//UE_LOG(LogTemp, Display, TEXT("the actor is %d"), comp.Num());// print the number of components
				int componentnum = 0;//for iteration
				for (auto component : comp) {
					//Loop through each component

					//if (component.IsA(ULandscapeComponent::StaticClass())) {
					ULandscapeComponent* LandComponent = Cast< ULandscapeComponent>(component); // I just make a lot of test the the code won't crash 
					//UE_LOG(LogTemp, Display, TEXT("the actor is %s"), *LandComponent->GetComponentLocation().ToString());
					if (LandComponent) {
						//Getting the center of the component x,y,z
						FBoxSphereBounds Bounds = LandComponent->CalcBounds(FTransform::Identity);
						FVector Center = Bounds.Origin;
						Center -= LandComponent->GetComponentLocation();
										
						UE_LOG(LogTemp, Warning, TEXT("Component center point: %s"), *Center.ToString());

									//this is to get the w/h of the component 
									int32 ComponentSizeQuads = LandComponent->ComponentSizeQuads;
									int32 ComponentWidth = ComponentSizeQuads + 1;
									int32 ComponentHeight = ComponentSizeQuads + 1;
									FVector componentLocation = LandComponent->GetComponentLocation();//get component location in world 

```

So here is a snippet of the code, i am just showing the classes and functions to be used and how we can use them. I hope this will get you going with handling landscapes in cpp code.  
Enjoy coding.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 7, 2023, 7:33pm UTC](https://forums.unrealengine.com/t/getting-landscape-informations-using-the-pythin-api/778963/6 "2023-07-07T19:33:57Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
