I am trying to create a configuration script to map shapefile coverages to coverage styles based on the shapefile attributes and a csv file. My csv file has the following structure:
I'm using this script in my configuration file:
function Process(SOURCE, COVERAGES) {
COVERAGES.EXTERNAL_ID = SOURCE["FeatId"];
COVERAGES.RULE_STYLE =GetMapping(SOURCE["LAYER"]);
return true;
}
function GetMapping(layername)
{
var data = file.ReadFile("C:/Users/XXXX/Documents/Infraworks NLCS mapping.csv");
var rows = data.split("\n");
for (var i = 0; i < rows.length; i++)
{
var cells = rows[i].split(",");
if(cells[0] == layername)
{
return cells[1];
}
}
return null;
}
The script is working fine, but the coverage style is not recognized, while the style name is correct:
When I enter the same style in the manual style, the style is correctly mapped:
Any thoughts how to fix this? Or is it a bug in Infraworks?
I typically do this by having the attributes on the shape file itself, and then employing a style rule.
Is that an option?
@gleeuwdrent I wrote a similar script a few years back. It was focused on buildings but can be modified for coverages. Let me know if it helps or if you have any questions about it.
Helllo Matt, thanks for your reply. Your example creates an afterwards mapping: first import your assets and then style them using a scripts. That gives good results, but when you re-import your assets, all modifications will be lost and you have to re run the script. That's not desirable for ease of use.
@gleeuwdrent if you want, you can import the layer AND stylize by script. Here is a sample script to import city furniture type but you can customize by modifying or adding UI to this. Please rename the .txt to .js before running. I always suggest taking a backup of the model before experimenting with a script for just-in-case situations.
Can't find what you're looking for? Ask the community or share your knowledge.