1414#include " ogrgeojsonutils.h"
1515#include " ogrlibjsonutils.h"
1616#include " ogr_geojson.h"
17+ #include " ogrgeojsongeometry.h"
1718#include < json.h> // JSON-C
1819#include " ogr_api.h"
1920
@@ -456,9 +457,9 @@ EstablishLayerDefn(int nPrevFieldIdx, std::vector<int> &anCurFieldIndices,
456457
457458static bool
458459ParseObjectMain (const char *pszId, json_object *poObj,
459- OGRGeoJSONDataSource *poDS, OGRGeoJSONLayer **ppoMainLayer ,
460- json_object *poArcs, ScalingParams *psParams ,
461- std::vector<int > &anCurFieldIndices,
460+ const OGRSpatialReference *poSRS, OGRGeoJSONDataSource *poDS ,
461+ OGRGeoJSONLayer **ppoMainLayer, json_object *poArcs ,
462+ ScalingParams *psParams, std::vector<int > &anCurFieldIndices,
462463 std::map<std::string, int > &oMapFieldNameToIdx,
463464 std::vector<std::unique_ptr<OGRFieldDefn>> &apoFieldDefn,
464465 gdal::DirectedAcyclicGraph<int , std::string> &dag,
@@ -495,8 +496,12 @@ ParseObjectMain(const char *pszId, json_object *poObj,
495496 OGRGeoJSONLayer *poLayer =
496497 new OGRGeoJSONLayer (pszId ? pszId : " TopoJSON" , nullptr ,
497498 wkbUnknown, poDS, nullptr );
499+ poLayer->SetSupportsZGeometries (false );
498500 OGRFeatureDefn *poDefn = poLayer->GetLayerDefn ();
499501
502+ whileUnsealing (poDefn)->GetGeomFieldDefn (0 )->SetSpatialRef (
503+ poSRS);
504+
500505 const auto nGeometries =
501506 json_object_array_length (poGeometries);
502507 // First pass to establish schema.
@@ -569,6 +574,13 @@ ParseObjectMain(const char *pszId, json_object *poObj,
569574 {
570575 *ppoMainLayer = new OGRGeoJSONLayer (
571576 " TopoJSON" , nullptr , wkbUnknown, poDS, nullptr );
577+
578+ (*ppoMainLayer)->SetSupportsZGeometries (false );
579+
580+ whileUnsealing ((*ppoMainLayer)->GetLayerDefn ())
581+ ->GetGeomFieldDefn (0 )
582+ ->SetSpatialRef (poSRS);
583+
572584 apoFieldDefn.emplace_back (
573585 std::make_unique<OGRFieldDefn>(" id" , OFTString));
574586 oMapFieldNameToIdx[" id" ] = 0 ;
@@ -629,6 +641,8 @@ void OGRTopoJSONReader::ReadLayers(OGRGeoJSONDataSource *poDS)
629641 return ;
630642 }
631643
644+ poDS->SetSupportsZGeometries (false );
645+
632646 ScalingParams sParams ;
633647 sParams .dfScale0 = 1.0 ;
634648 sParams .dfScale1 = 1.0 ;
@@ -695,6 +709,8 @@ void OGRTopoJSONReader::ReadLayers(OGRGeoJSONDataSource *poDS)
695709 if (poObjects == nullptr )
696710 return ;
697711
712+ OGRSpatialReference *poSRS = OGRGeoJSONReadSpatialReference (poGJObject_);
713+
698714 std::vector<int > anCurFieldIndices;
699715 std::map<std::string, int > oMapFieldNameToIdx;
700716 std::vector<std::unique_ptr<OGRFieldDefn>> apoFieldDefn;
@@ -711,10 +727,10 @@ void OGRTopoJSONReader::ReadLayers(OGRGeoJSONDataSource *poDS)
711727 json_object_object_foreachC (poObjects, it)
712728 {
713729 json_object *poObj = it.val ;
714- bNeedSecondPass |=
715- ParseObjectMain ( it.key , poObj, poDS, &poMainLayer, poArcs,
716- & sParams , anCurFieldIndices, oMapFieldNameToIdx ,
717- apoFieldDefn, dag, aoSetUndeterminedTypeFields);
730+ bNeedSecondPass |= ParseObjectMain (
731+ it.key , poObj, poSRS, poDS, &poMainLayer, poArcs, & sParams ,
732+ anCurFieldIndices, oMapFieldNameToIdx, apoFieldDefn, dag ,
733+ aoSetUndeterminedTypeFields);
718734 }
719735 if (bNeedSecondPass)
720736 {
@@ -745,10 +761,10 @@ void OGRTopoJSONReader::ReadLayers(OGRGeoJSONDataSource *poDS)
745761 for (auto i = decltype (nObjects){0 }; i < nObjects; i++)
746762 {
747763 json_object *poObj = json_object_array_get_idx (poObjects, i);
748- bNeedSecondPass |=
749- ParseObjectMain ( nullptr , poObj, poDS, &poMainLayer, poArcs,
750- & sParams , anCurFieldIndices, oMapFieldNameToIdx ,
751- apoFieldDefn, dag, aoSetUndeterminedTypeFields);
764+ bNeedSecondPass |= ParseObjectMain (
765+ nullptr , poObj, poSRS, poDS, &poMainLayer, poArcs, & sParams ,
766+ anCurFieldIndices, oMapFieldNameToIdx, apoFieldDefn, dag ,
767+ aoSetUndeterminedTypeFields);
752768 }
753769 if (bNeedSecondPass)
754770 {
@@ -775,4 +791,7 @@ void OGRTopoJSONReader::ReadLayers(OGRGeoJSONDataSource *poDS)
775791 poMainLayer->DetectGeometryType ();
776792 poDS->AddLayer (poMainLayer);
777793 }
794+
795+ if (poSRS)
796+ poSRS->Release ();
778797}
0 commit comments