Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading bools from shapefiles #715

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/attribute_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AttributeKeyStore {
std::map<const std::string*, uint16_t, string_ptr_less_than> keys2index;
};

enum class AttributePairType: uint8_t { Bool = 0, Float = 1, String = 2 };
enum class AttributePairType: uint8_t { String = 0, Float = 1, Bool = 2 };
// AttributePair is a key/value pair (with minzoom)
#pragma pack(push, 1)
struct AttributePair {
Expand Down
2 changes: 1 addition & 1 deletion include/shared_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct LayerDef {
bool allSourceColumns;
bool indexed;
std::string indexName;
std::map<std::string, uint> attributeMap;
std::map<std::string, uint> attributeMap; // string 0, number 1, bool 2
bool writeTo;

const bool useColumn(std::string &col) {
Expand Down
7 changes: 6 additions & 1 deletion src/shp_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void ShpProcessor::fillPointArrayFromShapefile(vector<Point> *points, SHPObject
}

// Read requested attributes from a shapefile, and encode into an OutputObject
// columnTypeMap: 0 string, 1 int, 2 double, 3 boolean
AttributeIndex ShpProcessor::readShapefileAttributes(
DBFHandle &dbf,
int recordNum, unordered_map<int,string> &columnMap, unordered_map<int,int> &columnTypeMap,
Expand All @@ -53,6 +54,7 @@ AttributeIndex ShpProcessor::readShapefileAttributes(
switch (columnTypeMap[pos]) {
case 1: in_table[key] = DBFReadIntegerAttribute(dbf, recordNum, pos); break;
case 2: in_table[key] = DBFReadDoubleAttribute(dbf, recordNum, pos); break;
case 3: in_table[key] = strcmp(DBFReadStringAttribute(dbf, recordNum, pos), "T")==0; break;
default: in_table[key] = DBFReadStringAttribute(dbf, recordNum, pos); break;
}
}
Expand Down Expand Up @@ -92,7 +94,10 @@ AttributeIndex ShpProcessor::readShapefileAttributes(
case 2: attributeStore.addAttribute(attributes, key, static_cast<float>(DBFReadDoubleAttribute(dbf, recordNum, pos)), 0);
layer.attributeMap[key] = 1;
break;
default: attributeStore.addAttribute(attributes, key, DBFReadStringAttribute(dbf, recordNum, pos), 0);
case 3: attributeStore.addAttribute(attributes, key, strcmp(DBFReadStringAttribute(dbf, recordNum, pos), "T")==0, 0);
layer.attributeMap[key] = 2;
break;
default: attributeStore.addAttribute(attributes, key, static_cast<const std::string&>(DBFReadStringAttribute(dbf, recordNum, pos)), 0);
layer.attributeMap[key] = 0;
break;
}
Expand Down
Loading