[seiscomp, scanloc] Install, add .gitignore

This commit is contained in:
2025-10-09 15:07:02 +02:00
commit 20f5301bb1
2848 changed files with 1315858 additions and 0 deletions

View File

@ -0,0 +1,152 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_BOUNDINGBOX_H
#define SEISCOMP_GEO_BOUNDINGBOX_H
#include <seiscomp/geo/coordinate.h>
#include <ostream>
namespace Seiscomp {
namespace Geo {
class SC_SYSTEM_CORE_API GeoBoundingBox {
public:
typedef GeoCoordinate::ValueType ValueType;
enum Relation {
Disjunct,
Contains,
Intersects
};
public:
GeoBoundingBox();
GeoBoundingBox(ValueType south, ValueType west,
ValueType north, ValueType east);
public:
bool operator==(const GeoBoundingBox &other) const;
GeoBoundingBox &operator+=(const GeoBoundingBox &other);
GeoBoundingBox operator+(const GeoBoundingBox &other) const;
bool operator&(const GeoBoundingBox &other) const;
public:
GeoBoundingBox &normalize();
bool isEmpty() const;
bool isNull() const;
/**
* @brief Sets this box empty. After that call @isEmpty() will
* return true.
*/
void reset();
bool coversFullLongitude() const;
ValueType width() const;
ValueType height() const;
bool crossesDateLine() const;
static bool crossesDateLine(ValueType east, ValueType west);
GeoCoordinate center() const;
bool contains(const GeoCoordinate &v) const;
/**
* @brief Checks whether other is fully contained in this. If false
* is returned then both boxes can still intersect.
* @param other The boundingbox that is being checked to be contained
* in this.
* @return true if other is contained in this, false otherwise
*/
bool contains(const GeoBoundingBox &other) const;
/**
* @brief Categorizes the relation of this and other. This basically
* returns whether the boxes are disjunct, contain each other
* or just intersect.
* @param other The other box to test
* @return A Relation enumeration value
*/
Relation relation(const GeoBoundingBox &other) const;
/**
* @brief Extends this boundingbox to contain also the other.
* @param other The boundingbox to be merged with this
*/
void merge(const GeoBoundingBox &other);
/**
* @brief intersects
* @param other The boundingbox to check against
* @return true if this and other intersect, false otherwise
*/
bool intersects(const GeoBoundingBox &other) const;
void fromPolygon(size_t n, const GeoCoordinate *coords,
bool isClosed = true);
public:
union {
ValueType north;
ValueType latMax;
};
union {
ValueType south;
ValueType latMin;
};
union {
ValueType east;
ValueType lonMax;
};
union {
ValueType west;
ValueType lonMin;
};
static GeoBoundingBox Empty;
};
#include <seiscomp/geo/boundingbox.ipp>
std::ostream &operator<<(std::ostream &os, const GeoBoundingBox &box);
template <>
std::ostream &operator<<(std::ostream &os, const OStreamFormat<GeoBoundingBox> &);
}
}
#endif

View File

@ -0,0 +1,125 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoBoundingBox &GeoBoundingBox::operator+=(const GeoBoundingBox &other) {
merge(other);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoBoundingBox GeoBoundingBox::operator+(const GeoBoundingBox &other) const {
GeoBoundingBox r(*this);
r.merge(other);
return r;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::operator&(const GeoBoundingBox &other) const {
return intersects(other);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::isEmpty() const {
return *this == Empty;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::isNull() const {
return (north == south) && (east == west);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline void GeoBoundingBox::reset() {
*this = Empty;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::coversFullLongitude() const {
return width() >= 360;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoBoundingBox::ValueType GeoBoundingBox::width() const {
return GeoCoordinate::width(west, east);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoBoundingBox::ValueType GeoBoundingBox::height() const {
return fabs(north - south);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::crossesDateLine() const {
return crossesDateLine(east, west);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoBoundingBox::crossesDateLine(ValueType east, ValueType west) {
return (east < west) || (east == 180 && west == -180);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

View File

@ -0,0 +1,120 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_GEOCOORDINATE_H
#define SEISCOMP_GEO_GEOCOORDINATE_H
#include <seiscomp/math/geo.h>
#include <ostream>
namespace Seiscomp {
namespace Geo {
class SC_SYSTEM_CORE_API GeoCoordinate {
public:
using ValueType = double;
public:
GeoCoordinate();
GeoCoordinate(ValueType lat_, ValueType lon_);
public:
void set(ValueType lat, ValueType lon);
ValueType latitude() const;
ValueType longitude() const;
bool operator==(const GeoCoordinate &other) const;
bool operator!=(const GeoCoordinate &other) const;
GeoCoordinate &normalize();
static ValueType width(ValueType lon0, ValueType lon1);
static ValueType normalizeLat(ValueType lat);
static ValueType normalizeLon(ValueType lon);
static void normalizeLatLon(ValueType &lat, ValueType &lon);
static ValueType distanceLon(ValueType lon0, ValueType lon1);
public:
ValueType lat;
ValueType lon;
};
//! Added with API 14.1
bool contains(const GeoCoordinate &v, const GeoCoordinate *polygon, size_t sides);
//! Added with API 14.1
bool contains(const GeoCoordinate &v, const GeoCoordinate *polygon, size_t sides, double &area);
//! Added with API 14.1
double area(const GeoCoordinate *polygon, size_t sides);
// For backwards compatibility, define Vertex as GeoCoordinate
typedef GeoCoordinate Vertex;
#include <seiscomp/geo/coordinate.ipp>
struct formatted_lat {
formatted_lat(double lat) : v(lat) {}
double v;
};
struct formatted_lon {
formatted_lon(double lon) : v(lon) {}
double v;
};
template <typename T>
struct OStreamFormat {
OStreamFormat(const T &r) : ref(r) {}
const T &ref;
};
template <typename T>
OStreamFormat<T> format(const T &ref) { return OStreamFormat<T>(ref); }
std::ostream &operator<<(std::ostream &os, const GeoCoordinate &);
std::ostream &operator<<(std::ostream &os, const formatted_lat &);
std::ostream &operator<<(std::ostream &os, const formatted_lon &);
template <typename T>
std::ostream &operator<<(std::ostream &os, const OStreamFormat<T> &f) {
os << f.ref;
return os;
}
template <>
std::ostream &operator<<(std::ostream &os, const OStreamFormat<GeoCoordinate> &);
}
}
#endif

View File

@ -0,0 +1,127 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::GeoCoordinate() {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::GeoCoordinate(ValueType lat_, ValueType lon_)
: lat(lat_)
, lon(lon_) {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline void GeoCoordinate::set(ValueType lat_, ValueType lon_) {
lat = lat_;
lon = lon_;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::ValueType GeoCoordinate::latitude() const {
return lat;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::ValueType GeoCoordinate::longitude() const {
return lon;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoCoordinate::operator==(const GeoCoordinate &other) const {
return lat == other.lat && lon == other.lon;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline bool GeoCoordinate::operator!=(const GeoCoordinate &other) const {
return lat != other.lat || lon != other.lon;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::ValueType GeoCoordinate::width(ValueType lon0, ValueType lon1) {
ValueType width = lon1 - lon0;
if ( width > 360 )
width = 360;
else {
while ( width < 0 )
width += 360;
}
return width;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate &GeoCoordinate::normalize() {
normalizeLatLon(lat, lon);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline GeoCoordinate::ValueType GeoCoordinate::distanceLon(ValueType lon0, ValueType lon1) {
ValueType distanceToThis = lon1 - lon0;
if ( distanceToThis < -180 )
distanceToThis += 360;
else if ( distanceToThis > 180 )
distanceToThis -= 360;
return distanceToThis;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

View File

@ -0,0 +1,147 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_FEATURE_H
#define SEISCOMP_GEO_FEATURE_H
#include <seiscomp/core/baseobject.h>
#include <seiscomp/geo/coordinate.h>
#include <seiscomp/geo/boundingbox.h>
#include <map>
namespace Seiscomp {
namespace Geo {
DEFINE_SMARTPOINTER(Category);
DEFINE_SMARTPOINTER(GeoFeature);
struct SC_SYSTEM_CORE_API Category {
unsigned int id;
std::string name;
std::string localName;
const Category* parent;
std::string dataDir;
Category(unsigned int id, std::string name = "",
const Category* parent = nullptr) :
id(id), name(name), parent(parent) {}
};
class SC_SYSTEM_CORE_API GeoFeature : public Core::BaseObject {
public:
typedef std::map<std::string, std::string> Attributes;
GeoFeature(const Category* category = nullptr, unsigned int rank = 1);
GeoFeature(const std::string& name, const Category* category,
unsigned int rank);
GeoFeature(const std::string& name, const Category* category,
unsigned int rank, const Attributes& attributes);
virtual ~GeoFeature();
public:
void setName(const std::string &name) { _name = name; }
const std::string &name() const { return _name; }
const Category *category() const { return _category; }
void setRank(unsigned int rank);
unsigned int rank() const { return _rank; }
void setAttribute(const std::string &name, const std::string &value);
const Attributes &attributes() const { return _attributes; }
/** Adds a vertex to the GeoFeature and changes the BBox if
* applicable. If newSubFeature is set to true */
void addVertex(const GeoCoordinate &vertex, bool newSubFeature = false);
void addVertex(float lat, float lon, bool newSubFeature = false) {
addVertex(GeoCoordinate(lat, lon), newSubFeature);
}
bool closedPolygon() const { return _closedPolygon; }
void setClosedPolygon(bool closed) { _closedPolygon = closed; }
void updateBoundingBox();
// Inverts the point order from counter-clockwise to clockwise or
// vice versa.
void invertOrder();
/**
* @brief Sorts all subfeatures according to their area and containment
* from largest to smallest.
*/
void sort();
/**
* @brief Sets an arbitrary pointer for user data. It is not touched
* and/or utilized by the geo library.
*/
void setUserData(void*);
void *userData() const;
const std::vector<GeoCoordinate> &vertices() const { return _vertices; }
const GeoBoundingBox &bbox() const { return _bbox; }
const std::vector<size_t> &subFeatures() const { return _subFeatures; }
bool contains(const GeoCoordinate &v) const;
double area() const;
/**
* @deprecated This method is deprecated and will be removed in future
* releases. Use Seiscomp::Geo::area instead.
*/
static double area(const GeoCoordinate *polygon, size_t sides) __attribute__((deprecated));
private:
typedef std::vector<GeoCoordinate> GeoCoordinates;
std::string _name;
const Category *_category;
void *_userData;
unsigned int _rank;
GeoFeature::Attributes _attributes;
GeoCoordinates _vertices;
bool _closedPolygon;
GeoBoundingBox _bbox;
/** Index of verticies marking the start of a sub feature.
* E.g. if the GeoFeature defines a main area and a group of
* islands this vector would contain the indices of the start
* point of each island */
std::vector<size_t> _subFeatures;
};
inline void *GeoFeature::userData() const {
return _userData;
}
} // of ns Geo
} // of ns Seiscomp
#endif // SEISCOMP_GEO_GEOFEATURE_H__

View File

@ -0,0 +1,191 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_FEATURESET_H
#define SEISCOMP_GEO_FEATURESET_H
#include <seiscomp/core.h>
#include <seiscomp/geo/feature.h>
#include <vector>
#include <boost/filesystem/path.hpp>
namespace Seiscomp {
namespace Geo {
class GeoFeatureSet;
class SC_SYSTEM_CORE_API GeoFeatureSetObserver {
public:
GeoFeatureSetObserver();
virtual ~GeoFeatureSetObserver();
public:
//! Signals that the feature set has been updated.
virtual void geoFeatureSetUpdated() = 0;
private:
GeoFeatureSet *_observedSet;
friend class GeoFeatureSet;
};
class SC_SYSTEM_CORE_API GeoFeatureSet : public Core::BaseObject {
public:
/** Default constructor */
GeoFeatureSet();
/** Destructor */
virtual ~GeoFeatureSet();
/** Copy operator, intentionally left undefined */
GeoFeatureSet & operator=(const GeoFeatureSet &);
public:
bool registerObserver(GeoFeatureSetObserver*);
bool unregisterObserver(GeoFeatureSetObserver*);
public:
/**
* Removes and destructs all elements from the _features and
* _categories vectors
*/
void clear();
/**
* @brief Loads the default geofeature dataset
*/
void load();
/**
* Initializes the _feature vector with all BNA-files of the specified
* directory. The directory is searched recursively. The name of any
* subdirectory is used as a category.
* The feature set is cleared prior to reading the files.
*
* @deprecated This method is deprecated and will be removed in future
* releases. Consider readDir() instead.
*/
size_t readBNADir(const std::string &dirPath) __attribute__((deprecated));
/**
* Reads one BNA-file
* @deprecated This method is deprecated and will be removed in future
* releases. Consider readFile() or Seiscomp::Geo::readBNA() instead.
*/
bool readBNAFile(const std::string& filename, const Category* category) __attribute__((deprecated));
/**
* Initializes the _feature vector with all files (*.bna, *.geojson) of
* the specified directory. The directory is searched recursively.
* The name of any subdirectory is used as a category.
*
* All files found are added to the current feature set. It is not
* cleared automatically.
*/
size_t readDir(const std::string &dirPath);
/**
* @brief Reads a geo feature vector file of any supported format.
* This method might throw an exception to signal an error.
*
* @param filename The filename to be read. The file extension is being
* used to determine the file format.
* @param category An optional category.
* @return Number of features read. If a negative number is returned
* then this file was ignored because its file extension is
* unknown.
* @since SeisComP API version 14.3.0
*/
ssize_t readFile(const std::string& filename, const Category* category);
bool addFeature(GeoFeature *feature);
/** Returns reference to GeoFeature vector */
const std::vector<GeoFeature*> &features() const { return _features; };
/** Returns reference to Category vector */
const std::vector<Category*> &categories() const { return _categories; };
private:
/** Copy constructor, private -> non copyable */
GeoFeatureSet(const GeoFeatureSet &);
/** Reads a BNADir recursively, used by readBNADir() */
size_t readBNADirRecursive(const boost::filesystem::path &directory,
Category *category);
/** Reads a GeoJSONDir recursively, used by readGeoJSONDir() */
size_t readDirRecursive(const boost::filesystem::path &directory,
Category *category);
/** Prints the number of polygons read */
const std::string initStatus(const std::string &directory,
unsigned int fileCount) const;
/** Compares two GeoFeatures by their rank */
static bool compareByRank(const GeoFeature* gf1, const GeoFeature* gf2);
/**
* Creates and inserts a new Category object into the Category vector.
* The name of the new category is set to the name parameter, prefixed
* (if available) by the name of the parent category.
*/
Category* addNewCategory(const std::string name,
const Category* parent = nullptr);
private:
/** Vector of GeoFeatures */
std::vector<GeoFeature*> _features;
/** Vector of Categories */
std::vector<Category*> _categories;
typedef std::vector<GeoFeatureSetObserver*> ObserverList;
ObserverList _observers;
};
class SC_SYSTEM_CORE_API GeoFeatureSetSingleton {
public:
/** Returns the singleton instance of this class */
static GeoFeatureSet &getInstance();
private:
/** Default constructor */
GeoFeatureSetSingleton();
private:
GeoFeatureSet _geoFeatureSet;
};
} // of ns Geo
} // of ns Seiscomp
#endif // SEISCOMP_GEO_FEATURESET_H__

View File

@ -0,0 +1,83 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_FORMATS_BNA_H
#define SEISCOMP_GEO_FORMATS_BNA_H
#include <seiscomp/geo/featureset.h>
namespace Seiscomp {
namespace Geo {
/**
* @brief Reads one BNA file. A BNA file may contain multiple segments
* consisting of multiple points which define a non closed polyline.
*
* A new segment is introduced by the following line:
* '"arbitrary segment name","rank <#rank>",<#points>'
* e.g.
* '"test segment","rank 1",991'
*
* A point or vertex is defined by the following line:
* '<latitude>,<longitude>'
* e.g.
* '31.646944,25.151389'
*
* In addition the BNA file format supports complex areas such as main land and
* islands. The coordinate pairs representing the islands are separated from
* each other by repeating the initial coordinate of the main area. The
* following sample file illustrates a complex area:
*
* "Test Area","rank 1",17
* 2,2 --begin main area
* 2,1
* 1,1
* 1,2
* 2,2 --end of main area
* 4,4 --begin island #1
* 4,3
* 3,3
* 3,4
* 4,4 --end island #1
* 2,2 --end main area
* 7,7 --begin island #2
* 7,5
* 6,4
* 5,6
* 7,7 --end of island #2
* 2,2 --end of main area
*
* @param featureSet The target feature that will hold the read features
* @param filename The path to the GeoJSON file
* @param category An optional category attached to all read features
* @return The number of features read
*/
size_t readBNA(GeoFeatureSet &featureSet, const std::string &path,
const Category *category = nullptr);
}
}
#endif

View File

@ -0,0 +1,48 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_FORMATS_GEOJSON_H
#define SEISCOMP_GEO_FORMATS_GEOJSON_H
#include <seiscomp/geo/featureset.h>
namespace Seiscomp {
namespace Geo {
/**
* @brief Reads a GeoJSON file and adds found features to the feature set.
* In case of an error an exception is thrown.
* @param featureSet The target feature that will hold the read features
* @param filename The path to the GeoJSON file
* @param category An optional category attached to all read features
* @return The number of features read
*/
size_t readGeoJSON(GeoFeatureSet &featureSet, const std::string &path,
const Category *category = nullptr);
}
}
#endif

View File

@ -0,0 +1,135 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_GEO_INDEX_QUADTREE_H
#define SEISCOMP_GEO_INDEX_QUADTREE_H
#include <seiscomp/geo/featureset.h>
#include <boost/function.hpp>
#include <vector>
#include <ostream>
namespace Seiscomp {
namespace Geo {
class SC_SYSTEM_CORE_API QuadTree {
public:
typedef boost::function<bool (const GeoFeature *)> VisitFunc;
public:
QuadTree();
public:
/**
* @brief Adds a feature to the tree.
* @param feature The feature const pointer. The ownership is not transferred.
*/
void addItem(const GeoFeature *feature);
//! Adds all features of the feature set
void add(const GeoFeatureSet &featureSet);
const GeoBoundingBox &bbox() const;
void query(const GeoCoordinate &gc, const VisitFunc &) const;
void query(const GeoBoundingBox &bb, const VisitFunc &, bool clipOnlyNodes = false) const;
/**
* Visits the features of a quadtree by descending from the root to
* the leaves or from the leaves to the root. The visitor is an
* arbitrary class that should implement the following methods:
*
* bool accept(const BoundingBox &box) const;
* bool visit(const GeoFeature *feature) const;
*
* If either of those methods returns false, then traversing the
* tree is aborted.
*
* @param visitor The visitor instance
* @param topDown Either traverse the quadtree top-down (from root
* to leaves) or bottom-up (from leaves to root).
*/
template <typename VISITOR>
void accept(const VISITOR &visitor, bool topDown = true);
const GeoFeature *findFirst(const GeoCoordinate &gc);
const GeoFeature *findLast(const GeoCoordinate &gc);
//! Dumps the tree to an output stream
std::ostream &dump(std::ostream &os) const;
private:
typedef std::vector<const GeoFeature*> Features;
enum NodeIndex {
InvalidIndex = -1,
UpperRight = 0,
UpperLeft = 1,
LowerLeft = 2,
LowerRight = 3
};
DEFINE_SMARTPOINTER(Node);
struct Node : public Core::BaseObject {
Node();
NodeIndex findAndCreateNode(const GeoFeature *f);
void addItem(const GeoFeature *f, int depth);
void dump(std::ostream &os, int indent) const;
void visit(const GeoCoordinate &gc, const VisitFunc &) const;
void visit(const GeoBoundingBox &bb, const VisitFunc &, bool clipOnlyNodes = false) const;
template <typename VISITOR>
bool acceptTopDown(const VISITOR &visitor);
template <typename VISITOR>
bool acceptButtomUp(const VISITOR &visitor);
const GeoFeature *findFirst(const GeoCoordinate &gc);
const GeoFeature *findLast(const GeoCoordinate &gc);
GeoBoundingBox bbox;
Features features;
bool isLeaf;
NodePtr children[4];
};
private:
Node _root;
};
#include <seiscomp/geo/index/quadtree.ipp>
std::ostream &operator<<(std::ostream &os, const Seiscomp::Geo::QuadTree &tree);
}
}
#endif

View File

@ -0,0 +1,100 @@
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline QuadTree::Node::Node() : isLeaf(true) {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline const GeoBoundingBox &QuadTree::bbox() const {
return _root.bbox;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename VISITOR>
inline void QuadTree::accept(const VISITOR &visitor, bool topDown) {
if ( topDown )
_root.acceptTopDown(visitor);
else
_root.acceptButtomUp(visitor);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename VISITOR>
inline bool QuadTree::Node::acceptTopDown(const VISITOR &visitor) {
if ( !visitor.accept(bbox) ) return true;
for ( size_t i = 0; i < features.size(); ++i ) {
if ( !visitor.visit(features[i]) )
return false;
}
for ( size_t i = 0; i < 4; ++i ) {
if ( children[i] ) {
if ( !children[i]->acceptTopDown(visitor) )
return false;
}
}
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename VISITOR>
inline bool QuadTree::Node::acceptButtomUp(const VISITOR &visitor) {
if ( !visitor.accept(bbox) ) return true;
for ( size_t i = 0; i < 4; ++i ) {
if ( children[i] ) {
if ( !children[i]->acceptButtomUp(visitor) )
return false;
}
}
for ( size_t i = features.size(); i > 0; --i ) {
if ( !visitor.visit(features[i-1]) )
return false;
}
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>