Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
Shapefile.hpp
Go to the documentation of this file.
1#pragma once
2#include <filesystem>
3#include <vector>
4#include <ranges>
5#include <algorithm>
6#include <string_view>
7#include <ostream>
8#include "GISFile.hpp"
9namespace fishnet{
15public:
16
17 [[nodiscard]] std::vector<std::filesystem::path> getAssociatedFiles()const;
18
19 constexpr static inline std::array<std::string,5> FILE_EXTENSIONS = {
20 ".shp",".shx",".prj",".dbf",".cpg"
21 };
22
23 constexpr static inline std::array<std::string,4> REQUIRED_FILES = {
24 ".shp",".shx",".dbf",".prj"
25 };
26
27 static bool supportsExtension(const std::filesystem::path & path){
28 return std::ranges::any_of(FILE_EXTENSIONS,[&path](const auto & ext){return ext == path.extension().string();});
29 }
30
31 static bool isValid(const std::filesystem::path & path) {
32 return std::ranges::all_of(REQUIRED_FILES,[&path](const auto & ext){return std::filesystem::exists(path.parent_path() / std::filesystem::path(path.stem().string()+ext));});
33 }
34
35 explicit Shapefile(const std::filesystem::path & path):AbstractVectorFile(path){
36 if(not supportsExtension(path))
37 throw std::invalid_argument("Not a shapefile!");
38 };
39
40 [[nodiscard]] bool exists() const noexcept{
42 }
43
44 operator bool() const noexcept {
45 return this->exists();
46 }
47
48 bool remove() const noexcept override;
49
50 GISFileType type() const noexcept override {
52 }
53
54 Shapefile & move(const std::filesystem::path & path);
55
56 Shapefile & move(const std::filesystem::path & rootPath, std::string filename);
57
58 Shapefile copy(const std::filesystem::path & path) const;
59
60 Shapefile copy(const std::filesystem::path & rootPath, std::string filename) const;
61
62 std::string toString() const noexcept;
63
64};
65static_assert(GISFile<Shapefile>);
66static_assert(VectorGISFile<Shapefile>);
67static_assert(!RasterGISFile<Shapefile>);
68}
bool exists() const noexcept
Tests if the GISFile exists on the filesystem.
Definition GISFile.hpp:79
std::filesystem::path pathToFile
Definition GISFile.hpp:49
Definition GISFile.hpp:131
Shapefile handle implementation.
Definition Shapefile.hpp:14
std::string toString() const noexcept
Definition Shapefile.cpp:62
static constexpr std::array< std::string, 5 > FILE_EXTENSIONS
Definition Shapefile.hpp:19
std::vector< std::filesystem::path > getAssociatedFiles() const
Definition Shapefile.cpp:7
Shapefile(const std::filesystem::path &path)
Definition Shapefile.hpp:35
GISFileType type() const noexcept override
Returns the type of GISFile.
Definition Shapefile.hpp:50
Shapefile & move(const std::filesystem::path &path)
static bool isValid(const std::filesystem::path &path)
Definition Shapefile.hpp:31
static bool supportsExtension(const std::filesystem::path &path)
Definition Shapefile.hpp:27
static constexpr std::array< std::string, 4 > REQUIRED_FILES
Definition Shapefile.hpp:23
Shapefile copy(const std::filesystem::path &rootPath, std::string filename) const
bool remove() const noexcept override
Removes the file from the filesystem.
Definition Shapefile.cpp:19
Shapefile copy(const std::filesystem::path &path) const
Shapefile & move(const std::filesystem::path &rootPath, std::string filename)
bool exists() const noexcept
Definition Shapefile.hpp:40
Interface for GISFile types. Implementation have to inherit from AbstractGISFile and have to printabl...
Definition GISFile.hpp:175
Interface for all Raster GISFile types.
Definition GISFile.hpp:197
Interface for all Vector GISFile types.
Definition GISFile.hpp:187
Definition BFSClustering.hpp:5
GISFileType
Definition GISFile.hpp:11