Skip to content

Commit

Permalink
Powerlines: add 'infer_tower_locations' property to use linear points…
Browse files Browse the repository at this point in the history
… as tower locations, as before
  • Loading branch information
gwaldron committed Feb 6, 2025
1 parent afa3d65 commit 29cf5d8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/osgEarth/PowerlineLayer
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace osgEarth
public:
Options();
Options(const ConfigOptions& options);
OE_OPTION(bool, inferTowerLocations, false);
OE_OPTION(StringExpression, towerExpr);
OE_OPTION(StringExpression, cableStyleExpr);
OE_OPTION(NumericExpression, numCablesExpr);
Expand Down
42 changes: 41 additions & 1 deletion src/osgEarth/PowerlineLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void PowerlineLayer::Options::fromConfig(const Config& conf)
conf.get("tower_expr", towerExpr());
conf.get("cable_expr", cableStyleExpr());
conf.get("num_cables", numCablesExpr());
conf.get("infer_tower_locations", inferTowerLocations());

for (auto& modelConf : conf.children("tower_model"))
towerModels().push_back(ModelOptions(modelConf));
Expand All @@ -123,6 +124,7 @@ PowerlineLayer::Options::getConfig() const
conf.set("tower_expr", towerExpr());
conf.set("cable_expr", cableStyleExpr());
conf.set("num_cables", numCablesExpr());
conf.set("infer_tower_locations", inferTowerLocations());

for(auto& towerModel : towerModels())
conf.add("tower_model", towerModel.getConfig());
Expand Down Expand Up @@ -1052,7 +1054,45 @@ bool PowerlineFeatureNodeFactory::createOrUpdateNode(
{
FilterContext sharedCX = context;
FeatureList workingSet;
cursor->fill(workingSet);

if (_powerlineOptions.inferTowerLocations() == true)
{
// collect just the lines, toss the points
cursor->fill(workingSet, [&](const Feature* feature) {
return feature->getGeometry()->isLinear();
});

// add back in a point-set version of each line
int count = 0;
for (auto& feature : workingSet)
{
count += feature->getGeometry()->size();
}
FeatureList towerFeatures;
towerFeatures.reserve(count);

for (auto& feature : workingSet)
{
GeometryIterator iter(feature->getGeometry(), false);
iter.forEach([&](Geometry* geom)
{
for (auto& p : *geom)
{
auto point = new Point();
point->push_back(p);
towerFeatures.push_back(new Feature(point, feature->getSRS()));
}
});
}
workingSet.reserve(workingSet.size() + towerFeatures.size());
for (auto& f : towerFeatures)
workingSet.push_back(f);
}
else
{
// assume the feature input includes tower locations as points
cursor->fill(workingSet);
}

Style cableStyle;

Expand Down
6 changes: 4 additions & 2 deletions tests/powerline.earth
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PowerlineModel name="towers" max_range="6000" attenuation_range="1000">
<features>power-lines</features>
<infer_tower_locations>false</infer_tower_locations>
<filters>
<script>
feature.properties.power === 'line' ||
Expand Down Expand Up @@ -30,7 +31,7 @@
</styles>
</PowerlineModel>

<TiledFeatureModel name="schematics" pickable="true" open="false">
<TiledFeatureModel name="schematics" pickable="true" open="false">
<features>power-lines</features>
<styles>
<style type="text/css">
Expand Down Expand Up @@ -69,7 +70,8 @@
</TiledFeatureModel>

<XYZFeatures name="power-lines">
<url>https://readymap.org/readymap/mbtiles/osm/{z}/{x}/{-y}.pbf</url>
<url>http://vr-theworld.com/vr-theworld/mbtiles/osm/{z}/{x}/{-y}.pbf</url>
<xurl>https://readymap.org/readymap/mbtiles/osm/{z}/{x}/{-y}.pbf</xurl>
<min_level>14</min_level>
<max_level>14</max_level>
<profile>spherical-mercator</profile>
Expand Down

0 comments on commit 29cf5d8

Please sign in to comment.