Skip to content

Commit

Permalink
Add feature type
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 29, 2016
1 parent c961ad2 commit 6803ee1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/mapbox/geometry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <mapbox/geometry/point.hpp>
#include <mapbox/geometry/line_string.hpp>
#include <mapbox/geometry/polygon.hpp>
#include <mapbox/geometry/multi_point.hpp>
#include <mapbox/geometry/multi_line_string.hpp>
#include <mapbox/geometry/multi_polygon.hpp>
#include <mapbox/geometry/geometry.hpp>
#include <mapbox/geometry/feature.hpp>
33 changes: 33 additions & 0 deletions include/mapbox/geometry/feature.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <mapbox/geometry/geometry.hpp>

#include <mapbox/variant.hpp>

#include <cstdint>
#include <string>
#include <unordered_map>

namespace mapbox { namespace geometry {

using value = mapbox::util::variant<bool, int64_t, uint64_t, double, std::string>;

template <class T>
struct feature
{
using geometry_type = geometry<T>;
using property_map = std::unordered_map<std::string, value>;

geometry_type geometry;
property_map properties;
};

template <class T, template <typename...> class Cont = std::vector>
struct feature_collection : Cont<feature<T>>
{
using feature_type = feature<T>;
using container_type = Cont<feature_type>;
using container_type::container_type;
};

}}
15 changes: 14 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <mapbox/geometry/geometry.hpp>
#include <mapbox/geometry.hpp>

#include <cassert>

Expand Down Expand Up @@ -76,6 +76,17 @@ void testGeometryCollection() {
assert(gc1.size() == 0);
}

void testFeature() {
feature<double> pf { point<double>() };
assert(pf.geometry.is<point<double>>());
assert(pf.properties.size() == 0);
}

void testFeatureCollection() {
feature_collection<double> fc1;
assert(fc1.size() == 0);
}

int main() {
testPoint();
testMultiPoint();
Expand All @@ -85,5 +96,7 @@ int main() {
testMultiPolygon();
testGeometry();
testGeometryCollection();
testFeature();
testFeatureCollection();
return 0;
}

0 comments on commit 6803ee1

Please sign in to comment.