@@ -625,115 +625,119 @@ void QgsProjectFileTransform::transform2990()
625
625
{
626
626
// transform OTF off to "no projection" for project
627
627
QDomElement propsElem = mDom .firstChildElement ( QStringLiteral ( " qgis" ) ).toElement ().firstChildElement ( QStringLiteral ( " properties" ) );
628
- QDomNodeList srsNodes = propsElem.elementsByTagName ( QStringLiteral ( " SpatialRefSys" ) );
629
- QDomElement srsElem;
630
- QDomElement projElem;
631
- if ( srsNodes.count () > 0 )
628
+ if ( !propsElem.isNull () )
632
629
{
633
- srsElem = srsNodes.at ( 0 ).toElement ();
634
- QDomNodeList projNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectionsEnabled" ) );
635
- if ( projNodes.count () == 0 )
630
+ QDomNodeList srsNodes = propsElem.elementsByTagName ( QStringLiteral ( " SpatialRefSys" ) );
631
+ QDomElement srsElem;
632
+ QDomElement projElem;
633
+ if ( srsNodes.count () > 0 )
636
634
{
635
+ srsElem = srsNodes.at ( 0 ).toElement ();
636
+ QDomNodeList projNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectionsEnabled" ) );
637
+ if ( projNodes.count () == 0 )
638
+ {
639
+ projElem = mDom .createElement ( QStringLiteral ( " ProjectionsEnabled" ) );
640
+ projElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
641
+ QDomText projText = mDom .createTextNode ( QStringLiteral ( " 0" ) );
642
+ projElem.appendChild ( projText );
643
+ srsElem.appendChild ( projElem );
644
+ }
645
+ }
646
+ else
647
+ {
648
+ srsElem = mDom .createElement ( QStringLiteral ( " SpatialRefSys" ) );
637
649
projElem = mDom .createElement ( QStringLiteral ( " ProjectionsEnabled" ) );
638
650
projElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
639
651
QDomText projText = mDom .createTextNode ( QStringLiteral ( " 0" ) );
640
652
projElem.appendChild ( projText );
641
653
srsElem.appendChild ( projElem );
654
+ propsElem.appendChild ( srsElem );
642
655
}
643
- }
644
- else
645
- {
646
- srsElem = mDom .createElement ( QStringLiteral ( " SpatialRefSys" ) );
647
- projElem = mDom .createElement ( QStringLiteral ( " ProjectionsEnabled" ) );
648
- projElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
649
- QDomText projText = mDom .createTextNode ( QStringLiteral ( " 0" ) );
650
- projElem.appendChild ( projText );
651
- srsElem.appendChild ( projElem );
652
- propsElem.appendChild ( srsElem );
653
- }
654
- // transform map canvas CRS to project CRS - this is because project CRS was inconsistently used
655
- // prior to 3.0. In >= 3.0 main canvas CRS is forced to match project CRS, so we need to make
656
- // sure we can read the project CRS correctly
657
- QDomNodeList canvasNodes = mDom .elementsByTagName ( QStringLiteral ( " mapcanvas" ) );
658
- if ( canvasNodes.count () > 0 )
659
- {
660
- QDomElement canvasElem = canvasNodes.at ( 0 ).toElement ();
661
- QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName ( QStringLiteral ( " spatialrefsys" ) );
662
- if ( canvasSrsNodes.count () > 0 )
663
- {
664
- QDomElement canvasSrsElem = canvasSrsNodes.at ( 0 ).toElement ();
665
- QString proj;
666
- QString authid;
667
- QString srsid;
668
656
669
- QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " proj4" ) );
670
- if ( proj4Nodes.count () > 0 )
671
- {
672
- QDomElement proj4Node = proj4Nodes.at ( 0 ).toElement ();
673
- proj = proj4Node.text ();
674
- }
675
- QDomNodeList authidNodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " authid" ) );
676
- if ( authidNodes.count () > 0 )
677
- {
678
- QDomElement authidNode = authidNodes.at ( 0 ).toElement ();
679
- authid = authidNode.text ();
680
- }
681
- QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " srsid" ) );
682
- if ( srsidNodes.count () > 0 )
657
+ // transform map canvas CRS to project CRS - this is because project CRS was inconsistently used
658
+ // prior to 3.0. In >= 3.0 main canvas CRS is forced to match project CRS, so we need to make
659
+ // sure we can read the project CRS correctly
660
+ QDomNodeList canvasNodes = mDom .elementsByTagName ( QStringLiteral ( " mapcanvas" ) );
661
+ if ( canvasNodes.count () > 0 )
662
+ {
663
+ QDomElement canvasElem = canvasNodes.at ( 0 ).toElement ();
664
+ QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName ( QStringLiteral ( " spatialrefsys" ) );
665
+ if ( canvasSrsNodes.count () > 0 )
683
666
{
684
- QDomElement srsidNode = srsidNodes.at ( 0 ).toElement ();
685
- srsid = srsidNode.text ();
686
- }
667
+ QDomElement canvasSrsElem = canvasSrsNodes.at ( 0 ).toElement ();
668
+ QString proj;
669
+ QString authid;
670
+ QString srsid;
687
671
688
- // clear existing project CRS nodes
689
- QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCRSProj4String" ) );
690
- for ( int i = oldProjectProj4Nodes.count (); i >= 0 ; --i )
691
- {
692
- srsElem.removeChild ( oldProjectProj4Nodes.at ( i ) );
693
- }
694
- QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCrs" ) );
695
- for ( int i = oldProjectCrsNodes.count (); i >= 0 ; --i )
696
- {
697
- srsElem.removeChild ( oldProjectCrsNodes.at ( i ) );
698
- }
699
- QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCRSID" ) );
700
- for ( int i = oldProjectCrsIdNodes.count (); i >= 0 ; --i )
701
- {
702
- srsElem.removeChild ( oldProjectCrsIdNodes.at ( i ) );
703
- }
704
- QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectionsEnabled" ) );
705
- for ( int i = projectionsEnabledNodes.count (); i >= 0 ; --i )
706
- {
707
- srsElem.removeChild ( projectionsEnabledNodes.at ( i ) );
708
- }
672
+ QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " proj4" ) );
673
+ if ( proj4Nodes.count () > 0 )
674
+ {
675
+ QDomElement proj4Node = proj4Nodes.at ( 0 ).toElement ();
676
+ proj = proj4Node.text ();
677
+ }
678
+ QDomNodeList authidNodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " authid" ) );
679
+ if ( authidNodes.count () > 0 )
680
+ {
681
+ QDomElement authidNode = authidNodes.at ( 0 ).toElement ();
682
+ authid = authidNode.text ();
683
+ }
684
+ QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName ( QStringLiteral ( " srsid" ) );
685
+ if ( srsidNodes.count () > 0 )
686
+ {
687
+ QDomElement srsidNode = srsidNodes.at ( 0 ).toElement ();
688
+ srsid = srsidNode.text ();
689
+ }
709
690
710
- QDomElement proj4Elem = mDom .createElement ( QStringLiteral ( " ProjectCRSProj4String" ) );
711
- proj4Elem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " QString" ) );
712
- QDomText proj4Text = mDom .createTextNode ( proj );
713
- proj4Elem.appendChild ( proj4Text );
714
- QDomElement projectCrsElem = mDom .createElement ( QStringLiteral ( " ProjectCrs" ) );
715
- projectCrsElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " QString" ) );
716
- QDomText projectCrsText = mDom .createTextNode ( authid );
717
- projectCrsElem.appendChild ( projectCrsText );
718
- QDomElement projectCrsIdElem = mDom .createElement ( QStringLiteral ( " ProjectCRSID" ) );
719
- projectCrsIdElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
720
- QDomText srsidText = mDom .createTextNode ( srsid );
721
- projectCrsIdElem.appendChild ( srsidText );
722
- QDomElement projectionsEnabledElem = mDom .createElement ( QStringLiteral ( " ProjectionsEnabled" ) );
723
- projectionsEnabledElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
724
- QDomText projectionsEnabledText = mDom .createTextNode ( QStringLiteral ( " 1" ) );
725
- projectionsEnabledElem.appendChild ( projectionsEnabledText );
726
- srsElem.appendChild ( proj4Elem );
727
- srsElem.appendChild ( projectCrsElem );
728
- srsElem.appendChild ( projectCrsIdElem );
729
- srsElem.appendChild ( projectionsEnabledElem );
730
-
731
- QDomNodeList srsNodes = propsElem.elementsByTagName ( QStringLiteral ( " SpatialRefSys" ) );
732
- for ( int i = srsNodes.count (); i >= 0 ; --i )
733
- {
734
- propsElem.removeChild ( srsNodes.at ( i ) );
691
+ // clear existing project CRS nodes
692
+ QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCRSProj4String" ) );
693
+ for ( int i = oldProjectProj4Nodes.count (); i >= 0 ; --i )
694
+ {
695
+ srsElem.removeChild ( oldProjectProj4Nodes.at ( i ) );
696
+ }
697
+ QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCrs" ) );
698
+ for ( int i = oldProjectCrsNodes.count (); i >= 0 ; --i )
699
+ {
700
+ srsElem.removeChild ( oldProjectCrsNodes.at ( i ) );
701
+ }
702
+ QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectCRSID" ) );
703
+ for ( int i = oldProjectCrsIdNodes.count (); i >= 0 ; --i )
704
+ {
705
+ srsElem.removeChild ( oldProjectCrsIdNodes.at ( i ) );
706
+ }
707
+ QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName ( QStringLiteral ( " ProjectionsEnabled" ) );
708
+ for ( int i = projectionsEnabledNodes.count (); i >= 0 ; --i )
709
+ {
710
+ srsElem.removeChild ( projectionsEnabledNodes.at ( i ) );
711
+ }
712
+
713
+ QDomElement proj4Elem = mDom .createElement ( QStringLiteral ( " ProjectCRSProj4String" ) );
714
+ proj4Elem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " QString" ) );
715
+ QDomText proj4Text = mDom .createTextNode ( proj );
716
+ proj4Elem.appendChild ( proj4Text );
717
+ QDomElement projectCrsElem = mDom .createElement ( QStringLiteral ( " ProjectCrs" ) );
718
+ projectCrsElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " QString" ) );
719
+ QDomText projectCrsText = mDom .createTextNode ( authid );
720
+ projectCrsElem.appendChild ( projectCrsText );
721
+ QDomElement projectCrsIdElem = mDom .createElement ( QStringLiteral ( " ProjectCRSID" ) );
722
+ projectCrsIdElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
723
+ QDomText srsidText = mDom .createTextNode ( srsid );
724
+ projectCrsIdElem.appendChild ( srsidText );
725
+ QDomElement projectionsEnabledElem = mDom .createElement ( QStringLiteral ( " ProjectionsEnabled" ) );
726
+ projectionsEnabledElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
727
+ QDomText projectionsEnabledText = mDom .createTextNode ( QStringLiteral ( " 1" ) );
728
+ projectionsEnabledElem.appendChild ( projectionsEnabledText );
729
+ srsElem.appendChild ( proj4Elem );
730
+ srsElem.appendChild ( projectCrsElem );
731
+ srsElem.appendChild ( projectCrsIdElem );
732
+ srsElem.appendChild ( projectionsEnabledElem );
733
+
734
+ QDomNodeList srsNodes = propsElem.elementsByTagName ( QStringLiteral ( " SpatialRefSys" ) );
735
+ for ( int i = srsNodes.count (); i >= 0 ; --i )
736
+ {
737
+ propsElem.removeChild ( srsNodes.at ( i ) );
738
+ }
739
+ propsElem.appendChild ( srsElem );
735
740
}
736
- propsElem.appendChild ( srsElem );
737
741
}
738
742
}
739
743
0 commit comments