P3D v4 AddAttribute & AddAttributeIfInside conundrum :S

Hi, I'm finally jumping into trying to use Scenproc :)
Here's my script so far. Now I freely admit I copied the base script from the manual because I haven't a clue where to start, and I'm trying to reverse engineer it in my head to understand it and make it work for me.

I'm first just loading in data (all in the correct WGS84 projection). Splitting the grid for the building shp file works fine.

ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_Building WGS84.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/211-212-231-241-242-243.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/231 Pasture.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/121 Industrial or commercial units.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/112 Discontinuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/111 Continuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:\Scenery Design Workshop/\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_FunctionalSite WGS84.shp|*|*|NOREPROJ
#ImportOGR|E:\Scenery Design Workshop\OS Opendata\Uni Leicester Land Use Map 2012\Master\CLC12_UK.shp|*|*|NOREPROJ
#
SplitGrid|AGN|*|FROMFILE="SW_Building WGS84.shp"
#​

Here's where it all goes pear shaped - The AddAttribute section is unchanged from the manual, yet results in no features having attributes added to them?

AddAttribute|FTYPE="POLYGON" And building="*"|Integer;BUILDTYPE|5
AddAttribute|FTYPE="POLYGON" And building="*" And BUILDTYPE=5 And FAREARAT>0.80|Integer;BUILDTYPE|1
AddAttribute|FTYPE="POLYGON" And building="*" And BUILDTYPE=5 And FNUMVERT<10 And FNUMPERPANG>3 And FNUMNOTPAR<2|Integer; BUILDTYPE|3
AddAttribute|FTYPE="POLYGON" And building="*" And BUILDTYPE=5 And FCONVEX=1|Integer;BUILDTYPE|4
#​
Then what I'm trying to do is add an attribute to parts of the buildings shpfile based on what kind of landuse polygon each building is in. Again no features have attributes added to them...

# Classify buildings
AddAttributeIfInside|FTYPE="POLYGON" And building="*"|CODE_12="*"|String;BUILDCAT|RURAL
AddAttributeIfInside|FTYPE="POLYGON" And building="*"|CODE_12=121|String;BUILDCAT|INDUSTRIAL_COMMERCIAL
AddAttributeIfInside|FTYPE="POLYGON" And building="*"|CODE_12=112|String;BUILDCAT|DISC_URBAN
AddAttributeIfInside|FTYPE="POLYGON" And building="*"|CODE_12=111|String;BUILDCAT|CONT_URBAN
AddAttributeIfInside|FTYPE="POLYGON" And building="*"|SITETHEME="Education"|String;BUILDCAT|FUNCTIONAL_SITE
I commented out the rest because I just want to get each stage working properly before moving on to the next...

#
# CreateAGNGenBuild|FROMFILE="buildings.shp" And FWIDTH<20|{1b53277c-6d5c-49fa-bb92-5580950416cf};{cf7ca399-3773-49cb-aa64-d66573904c64};{1bbbfb93-e013-4f86-a790-16599e4fc68b};{32c41cad-2dd1-4e38-b9f1-befccd41d821};{5ae04eb6-934c-4f63-bb48-5e7dee601212}|MAXRATIO=2
# CreateAGNGenBuild|FROMFILE="buildings.shp" And FWIDTH>20|{6089A0BD-CED1-4c47-9A9E-64CDD0E16983}
#
# ExportAGN|FSX|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\output texture​

Can anyone help point out where I'm going wrong please? I don't see anywhere in the manual where is it demonstrated how to add an attribute to a feature from one dataset by specifying a polygon from another specific dataset? :S

Thanks K
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
Hi,

The AddAttribute steps in the manual use building=* because that's an attribute OpenStreetMap has, but I guess your data has other attributes to identify buildings. So you need to use the right filter there to select them.
 
Easy when its obvious...Thanks Arno!

My data is split into individual sets already, so it only contains an ID code, nothing else.
When building="*" is taken out of every line, it seems everything works perfectly as logged below... :)

10:37 AddAttribute Information Adding attribute BUILDTYPE with value 5 to features FTYPE="POLYGON"
10:37 AddAttribute Information Added attribute to 134339 features
10:37 AddAttribute Information Adding attribute BUILDTYPE with value 1 to features FTYPE="POLYGON" And BUILDTYPE=5 And FAREARAT>0.80
10:37 AddAttribute Information Added attribute to 112453 features
10:37 AddAttribute Information Adding attribute BUILDTYPE with value 3 to features FTYPE="POLYGON" And BUILDTYPE=5 And FNUMVERT<10 And FNUMPERPANG>3 And FNUMNOTPAR<2
10:37 AddAttribute Information Added attribute to 9964 features
10:37 AddAttribute Information Adding attribute BUILDTYPE with value 4 to features FTYPE="POLYGON" And BUILDTYPE=5 And FCONVEX=1
10:37 AddAttribute Information Added attribute to 1517 features
10:37 AddAttributeIfInside Information Adding attribute BUILDCAT with value RURAL to features FTYPE="POLYGON" that are inside FTYPE="POLYGON" AND (CODE_12="*")
10:37 AddAttributeIfInside Information Added attribute to 126856 features
10:37 AddAttributeIfInside Information Adding attribute BUILDCAT with value INDUSTRIAL_COMMERCIAL to features FTYPE="POLYGON" that are inside FTYPE="POLYGON" AND (CODE_12="121")
10:37 AddAttributeIfInside Information Added attribute to 2104 features
10:37 AddAttributeIfInside Information Adding attribute BUILDCAT with value DISC_URBAN to features FTYPE="POLYGON" that are inside FTYPE="POLYGON" AND (CODE_12="112")
10:37 AddAttributeIfInside Information Added attribute to 61794 features
10:37 AddAttributeIfInside Information Adding attribute BUILDCAT with value CONT_URBAN to features FTYPE="POLYGON" that are inside FTYPE="POLYGON" AND (CODE_12="111")
10:37 AddAttributeIfInside Information Added attribute to 735 features
10:37 AddAttributeIfInside Information Adding attribute BUILDCAT with value FUNCTIONAL_SITE to features FTYPE="POLYGON" that are inside FTYPE="POLYGON" AND (SITETHEME="Education")
10:38 AddAttributeIfInside Information Added attribute to 913 features
10:38 SceneryProcessor Information scenProc finished processing​
 
Now I add
ReplacePolygonByBuildingRectangles|BUILDTYPE=3|0.8;4;4|0.25;2.0;0.5|Integer;BUILDTYPE|2
..as in the manual, and it processes 0 polygons, despite having processed 9964 features above...
hmmm, I think I need to understand what the parameters do a little more.

0.25;2.0;0.5 relates to the edge factors:

(From the manual)
1. The length of the edge. This is expressed as a value between 0.0 and 1.0.
So the length of the edge is divided by the length of the polygon (in the
direction of the edge). In general longer edges are a better candidate to
slice around, since these are the more characteristic edges of the polygon.
2. The distance of the edge to the center of the polygon also contributes to
the score. This is once again expressed as a value between 0.0 and 1.0.
Here 1.0 means that the edge is at the center and 0.0 means that the edge
is at the outside of the polygon.
3. The last contribution is the ratio of the distance between the closed edges
that are parallel to the selected edge. This contribution is used to give
an extra penalty to edge that would result in slicing the polygon in two
narrow polygons of equal size. Such edges get a value of 0.0, while edges
that result in polygons with different width get a higher value. These in
general give more resulting polygons for autogen.
But they don't seem to correspond to the values specified in the manual?
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
The sample parameters should be ok. They influence how the algorithm works, but won't cause no features being processed. So the cause must be somewhere else.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
I'll try to check the script you posted later. I toying this on my phone, so it's a bit hard to read now.
 
The sample parameters should be ok. They influence how the algorithm works, but won't cause no features being processed. So the cause must be somewhere else.
Where else might the cause lie? :S
I know the dataset loads ok its in the correct projection, its splits ok, it processes AddAttribute and AddAttributeIfInside apparently ok.
I know it identified 9964 polys and gives it BUILDTYPE=3

I've tried the first three parameters at 0.5,2,2 to maximise the range of data it would potentially work with to no effect.
If you say the last 3 parameters shouldn't cause no features being processed, I'm at a loss to understand what other influencing factors there might be?

Am I perhaps referencing the BUILDTYPE=3 incorrectly somehow?
:/
Cheers K
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
All these parameters influence how the algorithm works, but zero features does indicate a problem with the filter.

Can you post your current script? And put it between code tags for easier reading :)
 
I'll try to check the script you posted later. I toying this on my phone, so it's a bit hard to read now.
LOL its Christmas, prioritise your family :p I think they'll get upset if my little problem takes up your time at this time of year - it can always wait :) Cheers K
 
Code:
ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_Building WGS84.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/211-212-231-241-242-243.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/231 Pasture.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/121 Industrial or commercial units.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/112 Discontinuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/111 Continuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:\Scenery Design Workshop/\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_FunctionalSite WGS84.shp|*|*|NOREPROJ
#
SplitGrid|AGN|*|FROMFILE="SW_Building WGS84.shp"
#
AddAttribute|FTYPE="POLYGON"|Integer;BUILDTYPE|5
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FAREARAT>0.80|Integer;BUILDTYPE|1
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FNUMVERT<10 And FNUMPERPANG>3 And FNUMNOTPAR<2|Integer; BUILDTYPE|3
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FCONVEX=1|Integer;BUILDTYPE|4
# Remove complex buildings
ReplacePolygonByBuildingRectangles|BUILDTYPE=3|0.8;4;4|0.5;1.0;1.0|Integer;BUILDTYPE|2
# Classify buildings
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="*"|String;BUILDCAT|RURAL
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="121"|String;BUILDCAT|INDUSTRIAL_COMMERCIAL
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="112"|String;BUILDCAT|DISC_URBAN
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="111"|String;BUILDCAT|CONT_URBAN
AddAttributeIfInside|FTYPE="POLYGON"|SITETHEME="Education"|String;BUILDCAT|FUNCTIONAL_SITE
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
LOL its Christmas, prioritise your family I think they'll get upset if my little problem takes up your time at this time of year - it can always wait :) Cheers K
I'm currently walking outside with my son. Need to wait for him on his bicycle anyway :)
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
Code:
ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_Building WGS84.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/211-212-231-241-242-243.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/231 Pasture.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/121 Industrial or commercial units.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/112 Discontinuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/111 Continuous urban fabric.shp|*|*|NOREPROJ
ImportOGR|E:\Scenery Design Workshop/\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_FunctionalSite WGS84.shp|*|*|NOREPROJ
#
SplitGrid|AGN|*|FROMFILE="SW_Building WGS84.shp"
#
AddAttribute|FTYPE="POLYGON"|Integer;BUILDTYPE|5
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FAREARAT>0.80|Integer;BUILDTYPE|1
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FNUMVERT<10 And FNUMPERPANG>3 And FNUMNOTPAR<2|Integer; BUILDTYPE|3
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FCONVEX=1|Integer;BUILDTYPE|4
# Remove complex buildings
ReplacePolygonByBuildingRectangles|BUILDTYPE=3|0.8;4;4|0.5;1.0;1.0|Integer;BUILDTYPE|2
# Classify buildings
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="*"|String;BUILDCAT|RURAL
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="121"|String;BUILDCAT|INDUSTRIAL_COMMERCIAL
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="112"|String;BUILDCAT|DISC_URBAN
AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="111"|String;BUILDCAT|CONT_URBAN
AddAttributeIfInside|FTYPE="POLYGON"|SITETHEME="Education"|String;BUILDCAT|FUNCTIONAL_SITE
I can't spot the problem right away now.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
Got it, you got an extra space in your AddAttribute step, therefore the attribute name is " BUILDTYPE" not "BUILDTYPE" when you add the value of 3 to the features. But I needed the normal monitor and not the small smart phone to spot this one :)
 
Having a few problems with this now. Am getting a large number of oversized building rectangles generated. I saw a thread from a while back where this was solved by using autodetect instead of noreproj. That change hasn't worked for me I'm afraid as it appeared to there :(

Attached is the code, a screenshot showing the large building polys that are generated in annotator, and the txt file showing the event log from scenproc.
Any hints on where I can start looking to fix this please? Cheers K

Code:
ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_Building WGS84.shp|*|*|AUTODETECT
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/211-212-231-241-242-243.shp|*|*|AUTODETECT
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/231 Pasture.shp|*|*|AUTODETECT
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/121 Industrial or commercial units.shp|*|*|AUTODETECT
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/112 Discontinuous urban fabric.shp|*|*|AUTODETECT
ImportOGR|E:/Scenery Design Workshop/OS Opendata/OSOpenMapLocal (ESRI Shape File) SW/landuse 2012/111 Continuous urban fabric.shp|*|*|AUTODETECT
ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_FunctionalSite WGS84.shp|*|*|AUTODETECT
ImportOGR|E:\Scenery Design Workshop\OS Opendata\OSOpenMapLocal (ESRI Shape File) SW\data\SW_Woodland WGS84.shp|*|*|AUTODETECT
#
# SplitGrid|AGN|*|FROMFILE="SW_Woodland WGS84.shp"
SplitGrid|AGN|*|FROMFILE="SW_Building WGS84.shp"
#
AddAttribute|FTYPE="POLYGON"|Integer;BUILDTYPE|5
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FAREARAT>0.80|Integer;BUILDTYPE|1
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FNUMVERT<10 And FNUMPERPANG>3 And FNUMNOTPAR<2|Integer;BUILDTYPE|2
AddAttribute|FTYPE="POLYGON" And BUILDTYPE=5 And FCONVEX=1|Integer;BUILDTYPE|4
#
# Remove complex buildings
# ReplacePolygonByBuildingRectangles|BUILDTYPE=2|0.8;4;4|0.5;1.0;1.0|Integer;BUILDTYPE|3
# Classify buildings and vegetation areas
# AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="*"|String;BUILDCAT|RURAL
# AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="121"|String;BUILDCAT|INDUSTRIAL_COMMERCIAL
# AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="112"|String;BUILDCAT|DISC_URBAN
# AddAttributeIfInside|FTYPE="POLYGON"|CODE_12="111"|String;BUILDCAT|CONT_URBAN
# AddAttributeIfInside|FTYPE="POLYGON"|SITETHEME="Education"|String;BUILDCAT|FUNCTIONAL_SITE
#
# ReplacePolygonByVegetationRectangles|Landuse="311Broad"|0.0001|0.0|0.0
# ReplacePolygonByVegetationRectangles|Landuse="312Conif"|0.0001|0.0|0.0
# ReplacePolygonByVegetationRectangles|Landuse="Null"|0.0001|0.0|0.0
# Create AGN buildings and vegetation
CreateAGNGenBuild|FTYPE="POLYGON" And BUILDTYPE=1|{458b6a30-7e33-4478-b378-223cefc83f07}|MAXRATIO=2
CreateAGNGenBuild|FTYPE="POLYGON" And BUILDTYPE=2|{458b6a30-7e33-4478-b378-223cefc83f07}|MAXRATIO=2
CreateAGNGenBuild|FTYPE="POLYGON" And BUILDTYPE=3|{458b6a30-7e33-4478-b378-223cefc83f07}|MAXRATIO=2
CreateAGNGenBuild|FTYPE="POLYGON" And BUILDTYPE=4|{458b6a30-7e33-4478-b378-223cefc83f07}|MAXRATIO=2
# CreateAGNPolyVeg|FTYPE="POLYGON" And ID="Forest" And Landuse="311Broad"|{9315fa6d-469d-11db-9654-00e08161165f}
# CreateAGNPolyVeg|FTYPE="POLYGON" And ID="Forest" And Landuse="312Conif"|{8CAD12A1-6635-4ccb-9E15-02D1E8ACF209}
# CreateAGNPolyVeg|FTYPE="POLYGON" And ID="Forest" And Landuse="Null"|{fe22dca8-460b-11db-9654-00e08161165f}
# Output AGN files
SetAGNBuildingTexture|*|ES_AG_11
ExportAGN|FSX|E:\VFRGenX\VFR-Gen-X-2.0\Volume1\Area1\2.4m Photo\Texture
 

Attachments

arno

Administrator
Staff member
FSDevConf team
Resource contributor
I think the problem is that you are testing all polygons when adding the attributes. That means you also include features from the other shp files that don't contain buildings.
 
I think the problem is that you are testing all polygons when adding the attributes. That means you also include features from the other shp files that don't contain buildings.
Could I use the FROMFILE attribute to restrict the polygons tested to those from the buildings layer then? :s

EDIT: Am running it again but exporting as a shapefile this time, so I can look to see what attributes the larger rectangles have, to try to ascertain where the problem is being introduced....
 
Last edited:
EPIC FAIL
My PC has crashed, with some of the data layers open in QGIS. Those 9 data layers have been corrupted :(
It appears that most of those data layers I obtained free from Ordnance Survey some years ago under their OS VectorMap Local series but that data is now payware, so can't be obtained again :(
Consequently I think my project here is sadly at an end :(

But maybe not! I've managed to recover the source data, but its lost much of the preprocessing that I did in QGIS... so setback, but not stopped...
 
Last edited:
I think the problem is that you are testing all polygons when adding the attributes. That means you also include features from the other shp files that don't contain buildings.
You are correct, I commented out the inclusion of the other shp files and no large buildings were generated. Still trying to work out how to open multiple source files and only select polys from one of them :s Been trying to do that using the FEATCODE=15014 attribute which all the building footprint data has but it doesn't seem to be working....yet
 
Top