Repository navigation
Expand file tree
/
Copy pathshapefileparser.h
More file actions
126 lines (108 loc) · 3.63 KB
/
Copy pathshapefileparser.h
File metadata and controls
126 lines (108 loc) · 3.63 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef SHAPEFILEPARSER_H
#define SHAPEFILEPARSER_H
#include "osmparser.h"
#include "geocoordhash.h"
#include <QString>
#include <QVector>
#include <QList>
#include <QHash>
#include <QFile>
#include <QIODevice>
#include <QMutex>
#include <atomic>
typedef struct {
int nSHPType;
int nShapeId;
int nParts;
int *panPartStart;
int *panPartType;
int nVertices;
double *padfX;
double *padfY;
double *padfZ;
double *padfM;
double dfXMin, dfYMin, dfZMin, dfMMin;
double dfXMax, dfYMax, dfZMax, dfMMax;
} SHPObject;
typedef void* SHPHandle;
typedef void* DBFHandle;
enum DBFFieldType {
FTString = 0,
FTInteger = 1,
FTDouble = 2,
FTDate = 4,
FTInvalid = 3
};
enum ShapeType {
SHPT_NULL = 0,
SHPT_POINT = 1,
SHPT_ARC = 3,
SHPT_POLYGON = 5,
SHPT_MULTIPOINT = 8,
SHPT_POINTZ = 11,
SHPT_ARCZ = 13,
SHPT_POLYGONZ = 15,
SHPT_MULTIPOINTZ = 18,
SHPT_POINTM = 21,
SHPT_ARCM = 23,
SHPT_POLYGONM = 25,
SHPT_MULTIPOINTM = 28,
SHPT_MULTIPATCH = 31
};
enum RingType {
RING_UNKNOWN = 0,
RING_OUTER = 1,
RING_INNER = 2
};
#define IS_ARC(x) ((x) == SHPT_ARC || (x) == SHPT_ARCZ || (x) == SHPT_ARCM)
#define IS_POLYGON(x) ((x) == SHPT_POLYGON || (x) == SHPT_POLYGONZ || (x) == SHPT_POLYGONM)
#define IS_POINT(x) ((x) == SHPT_POINT || (x) == SHPT_POINTZ || (x) == SHPT_POINTM)
#define IS_MULTIPOINT(x) ((x) == SHPT_MULTIPOINT || (x) == SHPT_MULTIPOINTZ || (x) == SHPT_MULTIPOINTM)
#define HAS_Z(x) ((x) == SHPT_POINTZ || (x) == SHPT_ARCZ || (x) == SHPT_POLYGONZ || (x) == SHPT_MULTIPOINTZ || (x) == SHPT_MULTIPATCH)
#define HAS_M(x) ((x) == SHPT_POINTM || (x) == SHPT_ARCM || (x) == SHPT_POLYGONM || (x) == SHPT_MULTIPOINTM || HAS_Z(x))
RingType determineRingType(const double *xs, const double *ys, int numPoints);
extern "C" {
SHPHandle SHPOpen(const char *filename, const char *access);
void SHPGetInfo(SHPHandle hSHP, int *pnEntities, int *pnShapeType, double *padfMinBound, double *padfMaxBound);
SHPObject* SHPReadObject(SHPHandle hSHP, int iShape);
void SHPDestroyObject(SHPObject *psShape);
void SHPClose(SHPHandle hSHP);
DBFHandle DBFOpen(const char *filename, const char *access);
int DBFGetFieldCount(DBFHandle hDBF);
int DBFGetRecordCount(DBFHandle hDBF);
DBFFieldType DBFGetFieldInfo(DBFHandle hDBF, int iField, char *pszFieldName, int *pnWidth, int *pnDecimals);
const char* DBFReadStringAttribute(DBFHandle hDBF, int iRecord, int iField);
int DBFReadIntegerAttribute(DBFHandle hDBF, int iRecord, int iField);
double DBFReadDoubleAttribute(DBFHandle hDBF, int iRecord, int iField);
void DBFClose(DBFHandle hDBF);
}
class OsmShapefileParser : public OsmAbstractParser
{
Q_OBJECT
public:
explicit OsmShapefileParser(QObject *parent = nullptr);
~OsmShapefileParser() override;
bool parse(const QString &fileName, OsmModel &model, OsmStyle &style) override;
private:
struct TagMappingRule {
QString key;
QString value;
int tagType;
};
struct FieldMapping {
int dbfIndex;
QString keyName;
bool isTypeField;
int keyIndex;
};
bool readShapefile(const QString &basePath, OsmModel &model, OsmStyle &style);
bool loadAttributeMappings(const QString &basePath, const QList<FieldMapping> &mappings);
void transformToWGS84(double &lon, double &lat);
int createTagsFromAttributes(int entityIndex, const QList<FieldMapping> &mappings);
int getTagTypeForGeometry(int shapeType, const QString &typeValue);
QList<TagMappingRule> m_tagMappingRules;
GeoCoord::CoordMap<qint64> m_nodeCache;
QMutex m_nodeCacheMutex;
std::atomic<qint64> m_nextNodeId;
};
#endif // SHAPEFILEPARSER_H