Skip to content

Commit

Permalink
rev: move point bbox into switch
Browse files Browse the repository at this point in the history
changes per #522 (comment)
and also modifies `std::make_shared` calls within the switch statement
to reflect forwarding, instead of construction before passing.
  • Loading branch information
program-- authored and mattw-nws committed Jul 18, 2023
1 parent 76f7bdf commit 0d60f58
Showing 1 changed file with 32 additions and 51 deletions.
83 changes: 32 additions & 51 deletions src/geopackage/feature.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#include "GeoPackage.hpp"

// Points don't have a bounding box, so we can say its bbox is itself
inline void build_point_bbox(const geojson::geometry& geom, std::vector<double>& bbox)
{
const auto& pt = boost::get<geojson::coordinate_t>(geom);
bbox[0] = pt.get<0>();
bbox[1] = pt.get<1>();
bbox[2] = pt.get<0>();
bbox[3] = pt.get<1>();
}

geojson::Feature geopackage::build_feature(
const sqlite_iter& row,
const std::string& geom_col
Expand All @@ -13,85 +23,56 @@ geojson::Feature geopackage::build_feature(
// Convert variant type (0-based) to FeatureType
const auto wkb_type = geojson::FeatureType(geometry.which() + 1);

// Points don't have a bounding box, so we can say its bbox is itself
if (wkb_type == geojson::FeatureType::Point) {
const auto& pt = boost::get<geojson::coordinate_t>(geometry);
bounding_box[0] = pt.get<0>();
bounding_box[1] = pt.get<1>();
bounding_box[2] = pt.get<0>();
bounding_box[3] = pt.get<1>();
}

switch(wkb_type) {
case geojson::FeatureType::Point:
return std::make_shared<geojson::PointFeature>(geojson::PointFeature(
build_point_bbox(geometry, bounding_box);
return std::make_shared<geojson::PointFeature>(
boost::get<geojson::coordinate_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
case geojson::FeatureType::LineString:
return std::make_shared<geojson::LineStringFeature>(geojson::LineStringFeature(
return std::make_shared<geojson::LineStringFeature>(
boost::get<geojson::linestring_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
case geojson::FeatureType::Polygon:
return std::make_shared<geojson::PolygonFeature>(geojson::PolygonFeature(
return std::make_shared<geojson::PolygonFeature>(
boost::get<geojson::polygon_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
case geojson::FeatureType::MultiPoint:
return std::make_shared<geojson::MultiPointFeature>(geojson::MultiPointFeature(
return std::make_shared<geojson::MultiPointFeature>(
boost::get<geojson::multipoint_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
case geojson::FeatureType::MultiLineString:
return std::make_shared<geojson::MultiLineStringFeature>(geojson::MultiLineStringFeature(
return std::make_shared<geojson::MultiLineStringFeature>(
boost::get<geojson::multilinestring_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
case geojson::FeatureType::MultiPolygon:
return std::make_shared<geojson::MultiPolygonFeature>(geojson::MultiPolygonFeature(
return std::make_shared<geojson::MultiPolygonFeature>(
boost::get<geojson::multipolygon_t>(geometry),
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
default:
return std::make_shared<geojson::CollectionFeature>(geojson::CollectionFeature(
return std::make_shared<geojson::CollectionFeature>(
std::vector<geojson::geometry>{geometry},
id,
properties,
bounding_box,
std::vector<geojson::FeatureBase*>(),
std::vector<geojson::FeatureBase*>(),
{}
));
bounding_box
);
}
}

0 comments on commit 0d60f58

Please sign in to comment.