1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
ESRI shp/shx shapefiles.
Copyright (C) 2003 Robert Lipe, robertlipe+source@gpsbabel.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SHAPE_H_INCLUDED_
#define SHAPE_H_INCLUDED_
#include <QtCore/QString> // for QString
#include <QtCore/QVector> // for QVector
#include "defs.h" // for arglist_t, ARGTYPE_STRING, Waypoint, route_head, CET_CHARSET_ASCII, FF_CAP_RW_ALL, ff_cap, ff_type, ff_type_file
#include "format.h" // for Format
#include <shapefil.h> // for DBFHandle, SHPAPI_CALL, SHPHandle
#if SHAPELIB_ENABLED
class ShapeFormat : public Format
{
public:
QVector<arglist_t>* get_args() override
{
return &shp_args;
}
ff_type get_type() const override
{
return ff_type_file;
}
QVector<ff_cap> get_cap() const override
{
return FF_CAP_RW_ALL;
}
QString get_encode() const override
{
return CET_CHARSET_ASCII;
}
int get_fixed_encode() const override
{
return 0;
}
void rd_init(const QString& fname) override;
void read() override;
void rd_deinit() override;
void wr_init(const QString& fname) override;
void write() override;
void wr_deinit() override;
private:
static SHPHandle SHPAPI_CALL SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess);
static SHPHandle SHPAPI_CALL SHPCreateGpsbabel(const QString& pszLayer, int nShapeType);
static DBFHandle SHPAPI_CALL DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess);
static DBFHandle SHPAPI_CALL DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage);
void dump_fields() const;
void check_field_index(int fieldIdx) const;
int get_field_index(const QString& fieldName) const;
void write_wpt(const Waypoint* wpt) const;
void poly_init(const route_head* rte);
void poly_point(const Waypoint* wpt);
void poly_deinit(const route_head* rte);
SHPHandle ihandle{};
DBFHandle ihandledb{};
SHPHandle ohandle{};
DBFHandle ohandledb{};
int poly_count{};
double* polybufx{};
double* polybufy{};
double* polybufz{};
QString ifname;
QString ofname;
int nameFieldIdx{}; // the field index of the field with fieldName "name" in the output DBF.
char* opt_name = nullptr;
char* opt_url = nullptr;
QVector<arglist_t> shp_args = {
{
"name", &opt_name, "Source for name field in .dbf",
nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
},
{
"url", &opt_url, "Source for URL field in .dbf",
nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
},
};
};
#endif /* SHAPELIB_ENABLED */
#endif // SHAPE_H_INCLUDED_
|