@@ -446,6 +446,32 @@ bool OGRJSONFGReader::FinalizeGenerateLayerDefns(bool bStreamedLayer)
446
446
}
447
447
}
448
448
449
+ json_object *poMeasures = nullptr ;
450
+ if (json_object_object_get_ex (poObject_, " measures" , &poMeasures) &&
451
+ json_object_get_type (poMeasures) == json_type_object)
452
+ {
453
+ json_object *poEnabled = nullptr ;
454
+ if (json_object_object_get_ex (poMeasures, " enabled" , &poEnabled) &&
455
+ json_object_get_type (poEnabled) == json_type_boolean &&
456
+ json_object_get_boolean (poEnabled))
457
+ {
458
+ json_object *poUnit = nullptr ;
459
+ if (json_object_object_get_ex (poMeasures, " unit" , &poUnit) &&
460
+ json_object_get_type (poUnit) == json_type_string)
461
+ {
462
+ osMeasureUnit_ = json_object_get_string (poUnit);
463
+ }
464
+
465
+ json_object *poDescription = nullptr ;
466
+ if (json_object_object_get_ex (poMeasures, " description" ,
467
+ &poDescription) &&
468
+ json_object_get_type (poDescription) == json_type_string)
469
+ {
470
+ osMeasureDescription_ = json_object_get_string (poDescription);
471
+ }
472
+ }
473
+ }
474
+
449
475
// Finalize layer definition building and create OGRLayer objects
450
476
for (auto &oBuildContextIter : oMapBuildContext_)
451
477
{
@@ -673,6 +699,38 @@ void OGRJSONFGReader::FinalizeBuildContext(LayerDefnBuildContext &oBuildContext,
673
699
if (oBuildContext.bNeedFID64 )
674
700
poLayer->SetMetadataItem (OLMD_FID64, " YES" );
675
701
702
+ if (oBuildContext.bSameMeasureMetadata &&
703
+ (!oBuildContext.osMeasureUnit .empty () ||
704
+ !oBuildContext.osMeasureDescription .empty ()))
705
+ {
706
+ if (!oBuildContext.osMeasureUnit .empty ())
707
+ {
708
+ poLayer->SetMetadataItem (
709
+ " UNIT" , oBuildContext.osMeasureUnit .c_str (), " MEASURES" );
710
+ }
711
+
712
+ if (!oBuildContext.osMeasureDescription .empty ())
713
+ {
714
+ poLayer->SetMetadataItem (" DESCRIPTION" ,
715
+ oBuildContext.osMeasureDescription .c_str (),
716
+ " MEASURES" );
717
+ }
718
+ }
719
+ else
720
+ {
721
+ if (!osMeasureUnit_.empty ())
722
+ {
723
+ poLayer->SetMetadataItem (" UNIT" , osMeasureUnit_.c_str (),
724
+ " MEASURES" );
725
+ }
726
+
727
+ if (!osMeasureDescription_.empty ())
728
+ {
729
+ poLayer->SetMetadataItem (" DESCRIPTION" ,
730
+ osMeasureDescription_.c_str (), " MEASURES" );
731
+ }
732
+ }
733
+
676
734
if (poStreamedLayer)
677
735
{
678
736
poStreamedLayer->SetFeatureCount (oBuildContext.nFeatureCount );
@@ -1058,6 +1116,45 @@ bool OGRJSONFGReader::GenerateLayerDefnFromFeature(json_object *poObj)
1058
1116
}
1059
1117
}
1060
1118
1119
+ if (poContext->bSameMeasureMetadata )
1120
+ {
1121
+ json_object *poMeasures = nullptr ;
1122
+ if (json_object_object_get_ex (poObj, " measures" , &poMeasures) &&
1123
+ json_object_get_type (poMeasures) == json_type_object)
1124
+ {
1125
+ json_object *poEnabled = nullptr ;
1126
+ if (json_object_object_get_ex (poMeasures, " enabled" , &poEnabled) &&
1127
+ json_object_get_type (poEnabled) == json_type_boolean &&
1128
+ json_object_get_boolean (poEnabled))
1129
+ {
1130
+ json_object *poUnit = nullptr ;
1131
+ if (json_object_object_get_ex (poMeasures, " unit" , &poUnit) &&
1132
+ json_object_get_type (poUnit) == json_type_string)
1133
+ {
1134
+ if (poContext->osMeasureUnit .empty ())
1135
+ poContext->osMeasureUnit =
1136
+ json_object_get_string (poUnit);
1137
+ else if (poContext->osMeasureUnit !=
1138
+ json_object_get_string (poUnit))
1139
+ poContext->bSameMeasureMetadata = false ;
1140
+ }
1141
+
1142
+ json_object *poDescription = nullptr ;
1143
+ if (json_object_object_get_ex (poMeasures, " description" ,
1144
+ &poDescription) &&
1145
+ json_object_get_type (poDescription) == json_type_string)
1146
+ {
1147
+ if (poContext->osMeasureDescription .empty ())
1148
+ poContext->osMeasureDescription =
1149
+ json_object_get_string (poDescription);
1150
+ else if (poContext->osMeasureDescription !=
1151
+ json_object_get_string (poDescription))
1152
+ poContext->bSameMeasureMetadata = false ;
1153
+ }
1154
+ }
1155
+ }
1156
+ }
1157
+
1061
1158
/* -------------------------------------------------------------------- */
1062
1159
/* Deal with place / geometry */
1063
1160
/* -------------------------------------------------------------------- */
0 commit comments