Skip to content

Commit f6bc74c

Browse files
authored
Merge pull request #4952 from nyalldawson/otf_transform_upgrade
When upgrading 2.x projects to 3.0, default to enabling a valid project projection instead of defaulting to no CRS
2 parents c5f6af7 + b808c56 commit f6bc74c

File tree

3 files changed

+255
-9
lines changed

3 files changed

+255
-9
lines changed

src/core/qgsprojectfiletransform.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,6 @@ void QgsProjectFileTransform::transform2990()
656656
if ( canvasNodes.count() > 0 )
657657
{
658658
QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
659-
QDomNodeList projectionsNodes = canvasElem.elementsByTagName( QStringLiteral( "projections" ) );
660-
bool hasOtf = false;
661-
if ( projectionsNodes.count() > 0 )
662-
{
663-
QDomElement projectionsElem = projectionsNodes.at( 0 ).toElement();
664-
hasOtf = projectionsElem.text().toInt();
665-
}
666-
667659
QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral( "spatialrefsys" ) );
668660
if ( canvasSrsNodes.count() > 0 )
669661
{
@@ -727,7 +719,7 @@ void QgsProjectFileTransform::transform2990()
727719
projectCrsIdElem.appendChild( srsidText );
728720
QDomElement projectionsEnabledElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
729721
projectionsEnabledElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
730-
QDomText projectionsEnabledText = mDom.createTextNode( hasOtf ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
722+
QDomText projectionsEnabledText = mDom.createTextNode( QStringLiteral( "1" ) );
731723
projectionsEnabledElem.appendChild( projectionsEnabledText );
732724
srsElem.appendChild( proj4Elem );
733725
srsElem.appendChild( projectCrsElem );

tests/src/python/test_qgsproject.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,15 @@ def test_zip_unzip(self):
751751
project2.clear()
752752
self.assertFalse(project2.isZipped())
753753

754+
def testUpgradeOtfFrom2x(self):
755+
"""
756+
Test that upgrading a 2.x project correctly brings across project CRS and OTF transformation settings
757+
"""
758+
prj = QgsProject.instance()
759+
prj.read(os.path.join(TEST_DATA_DIR, 'projects', 'test_memory_layer_proj.qgs'))
760+
self.assertTrue(prj.crs().isValid())
761+
self.assertEqual(prj.crs().authid(), 'EPSG:2056')
762+
754763

755764
if __name__ == '__main__':
756765
unittest.main()
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2+
<qgis projectname="" version="2.18.10">
3+
<title></title>
4+
<autotransaction active="0"/>
5+
<evaluateDefaultValues active="0"/>
6+
<layer-tree-group expanded="1" checked="Qt::Checked" name="">
7+
<customproperties/>
8+
<layer-tree-layer expanded="1" providerKey="memory" checked="Qt::Checked" id="New_scratch_layer20170802173624782" source="point?crs=EPSG:2056&amp;memoryid={71fdfef1-9be0-4d72-9d2f-16b17b748323}" name="New scratch layer">
9+
<customproperties/>
10+
</layer-tree-layer>
11+
</layer-tree-group>
12+
<relations/>
13+
<mapcanvas>
14+
<units>meters</units>
15+
<extent>
16+
<xmin>2671057.63456883002072573</xmin>
17+
<ymin>1211312.30044019035995007</ymin>
18+
<xmax>2697247.79382618423551321</xmax>
19+
<ymax>1236593.02145395800471306</ymax>
20+
</extent>
21+
<rotation>0</rotation>
22+
<projections>0</projections>
23+
<destinationsrs>
24+
<spatialrefsys>
25+
<proj4>+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs</proj4>
26+
<srsid>47</srsid>
27+
<srid>2056</srid>
28+
<authid>EPSG:2056</authid>
29+
<description>CH1903+ / LV95</description>
30+
<projectionacronym>somerc</projectionacronym>
31+
<ellipsoidacronym>bessel</ellipsoidacronym>
32+
<geographicflag>false</geographicflag>
33+
</spatialrefsys>
34+
</destinationsrs>
35+
<rendermaptile>0</rendermaptile>
36+
<layer_coordinate_transform_info/>
37+
</mapcanvas>
38+
<layer-tree-canvas>
39+
<custom-order enabled="0">
40+
<item>New_scratch_layer20170802173624782</item>
41+
</custom-order>
42+
</layer-tree-canvas>
43+
<legend updateDrawingOrder="true">
44+
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="New scratch layer" showFeatureCount="0">
45+
<filegroup open="true" hidden="false">
46+
<legendlayerfile isInOverview="0" layerid="New_scratch_layer20170802173624782" visible="1"/>
47+
</filegroup>
48+
</legendlayer>
49+
</legend>
50+
<projectlayers>
51+
<maplayer simplifyAlgorithm="0" minimumScale="0" maximumScale="1e+08" simplifyDrawingHints="1" minLabelScale="0" maxLabelScale="1e+08" simplifyDrawingTol="1" readOnly="0" geometry="Point" simplifyMaxScale="1" type="vector" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
52+
<id>New_scratch_layer20170802173624782</id>
53+
<datasource>memory?geometry=Point&amp;crs=EPSG:2056</datasource>
54+
<keywordList>
55+
<value></value>
56+
</keywordList>
57+
<layername>New scratch layer</layername>
58+
<srs>
59+
<spatialrefsys>
60+
<proj4>+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs</proj4>
61+
<srsid>47</srsid>
62+
<srid>2056</srid>
63+
<authid>EPSG:2056</authid>
64+
<description>CH1903+ / LV95</description>
65+
<projectionacronym>somerc</projectionacronym>
66+
<ellipsoidacronym>bessel</ellipsoidacronym>
67+
<geographicflag>false</geographicflag>
68+
</spatialrefsys>
69+
</srs>
70+
<provider encoding="UTF-8">memory</provider>
71+
<vectorjoins/>
72+
<layerDependencies/>
73+
<expressionfields/>
74+
<map-layer-style-manager current="">
75+
<map-layer-style name=""/>
76+
</map-layer-style-manager>
77+
<edittypes/>
78+
<renderer-v2 forceraster="0" symbollevels="0" type="singleSymbol" enableorderby="0">
79+
<symbols>
80+
<symbol alpha="1" clip_to_extent="1" type="marker" name="0">
81+
<layer pass="0" class="SimpleMarker" locked="0">
82+
<prop k="angle" v="0"/>
83+
<prop k="color" v="203,253,94,255"/>
84+
<prop k="horizontal_anchor_point" v="1"/>
85+
<prop k="joinstyle" v="bevel"/>
86+
<prop k="name" v="circle"/>
87+
<prop k="offset" v="0,0"/>
88+
<prop k="offset_map_unit_scale" v="0,0,0,0,0,0"/>
89+
<prop k="offset_unit" v="MM"/>
90+
<prop k="outline_color" v="0,0,0,255"/>
91+
<prop k="outline_style" v="solid"/>
92+
<prop k="outline_width" v="0"/>
93+
<prop k="outline_width_map_unit_scale" v="0,0,0,0,0,0"/>
94+
<prop k="outline_width_unit" v="MM"/>
95+
<prop k="scale_method" v="diameter"/>
96+
<prop k="size" v="2"/>
97+
<prop k="size_map_unit_scale" v="0,0,0,0,0,0"/>
98+
<prop k="size_unit" v="MM"/>
99+
<prop k="vertical_anchor_point" v="1"/>
100+
</layer>
101+
</symbol>
102+
</symbols>
103+
<rotation/>
104+
<sizescale scalemethod="diameter"/>
105+
</renderer-v2>
106+
<labeling type="simple"/>
107+
<customproperties/>
108+
<blendMode>0</blendMode>
109+
<featureBlendMode>0</featureBlendMode>
110+
<layerTransparency>0</layerTransparency>
111+
<displayfield></displayfield>
112+
<label>0</label>
113+
<labelattributes>
114+
<label fieldname="" text="Label"/>
115+
<family fieldname="" name="Sans Serif"/>
116+
<size fieldname="" units="pt" value="12"/>
117+
<bold fieldname="" on="0"/>
118+
<italic fieldname="" on="0"/>
119+
<underline fieldname="" on="0"/>
120+
<strikeout fieldname="" on="0"/>
121+
<color fieldname="" red="0" blue="0" green="0"/>
122+
<x fieldname=""/>
123+
<y fieldname=""/>
124+
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
125+
<angle fieldname="" value="0" auto="0"/>
126+
<alignment fieldname="" value="center"/>
127+
<buffercolor fieldname="" red="255" blue="255" green="255"/>
128+
<buffersize fieldname="" units="pt" value="1"/>
129+
<bufferenabled fieldname="" on=""/>
130+
<multilineenabled fieldname="" on=""/>
131+
<selectedonly on=""/>
132+
</labelattributes>
133+
<annotationform></annotationform>
134+
<aliases/>
135+
<excludeAttributesWMS/>
136+
<excludeAttributesWFS/>
137+
<attributeactions default="-1"/>
138+
<attributetableconfig actionWidgetStyle="dropDown" sortExpression="" sortOrder="-2085748272">
139+
<columns/>
140+
</attributetableconfig>
141+
<editform></editform>
142+
<editforminit/>
143+
<editforminitcodesource>0</editforminitcodesource>
144+
<editforminitfilepath></editforminitfilepath>
145+
<editforminitcode><![CDATA[]]></editforminitcode>
146+
<featformsuppress>0</featformsuppress>
147+
<editorlayout>generatedlayout</editorlayout>
148+
<widgets/>
149+
<conditionalstyles>
150+
<rowstyles/>
151+
<fieldstyles/>
152+
</conditionalstyles>
153+
<defaults/>
154+
<previewExpression></previewExpression>
155+
</maplayer>
156+
</projectlayers>
157+
<properties>
158+
<WMSContactPerson type="QString"></WMSContactPerson>
159+
<Variables>
160+
<variableNames type="QStringList"/>
161+
<variableValues type="QStringList"/>
162+
</Variables>
163+
<WMSOnlineResource type="QString"></WMSOnlineResource>
164+
<WMSUseLayerIDs type="bool">false</WMSUseLayerIDs>
165+
<WMSContactOrganization type="QString"></WMSContactOrganization>
166+
<WMSKeywordList type="QStringList">
167+
<value></value>
168+
</WMSKeywordList>
169+
<WFSUrl type="QString"></WFSUrl>
170+
<Paths>
171+
<Absolute type="bool">false</Absolute>
172+
</Paths>
173+
<WMSServiceTitle type="QString"></WMSServiceTitle>
174+
<WFSLayers type="QStringList"/>
175+
<WMSContactMail type="QString"></WMSContactMail>
176+
<PositionPrecision>
177+
<DecimalPlaces type="int">2</DecimalPlaces>
178+
<Automatic type="bool">true</Automatic>
179+
<DegreeFormat type="QString">MU</DegreeFormat>
180+
</PositionPrecision>
181+
<WCSUrl type="QString"></WCSUrl>
182+
<WMSContactPhone type="QString"></WMSContactPhone>
183+
<WMSServiceCapabilities type="bool">false</WMSServiceCapabilities>
184+
<WMSServiceAbstract type="QString"></WMSServiceAbstract>
185+
<WMSContactPosition type="QString"></WMSContactPosition>
186+
<WMSAddWktGeometry type="bool">false</WMSAddWktGeometry>
187+
<Measure>
188+
<Ellipsoid type="QString">NONE</Ellipsoid>
189+
</Measure>
190+
<WMSPrecision type="QString">8</WMSPrecision>
191+
<WMSSegmentizeFeatureInfoGeometry type="bool">false</WMSSegmentizeFeatureInfoGeometry>
192+
<WFSTLayers>
193+
<Insert type="QStringList"/>
194+
<Update type="QStringList"/>
195+
<Delete type="QStringList"/>
196+
</WFSTLayers>
197+
<Gui>
198+
<SelectionColorBluePart type="int">0</SelectionColorBluePart>
199+
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
200+
<CanvasColorRedPart type="int">255</CanvasColorRedPart>
201+
<SelectionColorRedPart type="int">255</SelectionColorRedPart>
202+
<SelectionColorAlphaPart type="int">128</SelectionColorAlphaPart>
203+
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
204+
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
205+
</Gui>
206+
<Digitizing>
207+
<DefaultSnapToleranceUnit type="int">2</DefaultSnapToleranceUnit>
208+
<SnappingMode type="QString">current_layer</SnappingMode>
209+
<DefaultSnapType type="QString">off</DefaultSnapType>
210+
<DefaultSnapTolerance type="double">0</DefaultSnapTolerance>
211+
</Digitizing>
212+
<Identify>
213+
<disabledLayers type="QStringList"/>
214+
</Identify>
215+
<Macros>
216+
<pythonCode type="QString"></pythonCode>
217+
</Macros>
218+
<WMSAccessConstraints type="QString">None</WMSAccessConstraints>
219+
<WCSLayers type="QStringList"/>
220+
<Legend>
221+
<filterByMap type="bool">false</filterByMap>
222+
</Legend>
223+
<SpatialRefSys>
224+
<ProjectCRSProj4String type="QString">+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs</ProjectCRSProj4String>
225+
<ProjectCrs type="QString">EPSG:2056</ProjectCrs>
226+
<ProjectCRSID type="int">47</ProjectCRSID>
227+
</SpatialRefSys>
228+
<DefaultStyles>
229+
<Fill type="QString"></Fill>
230+
<Line type="QString"></Line>
231+
<Marker type="QString"></Marker>
232+
<RandomColors type="bool">true</RandomColors>
233+
<AlphaInt type="int">255</AlphaInt>
234+
<ColorRamp type="QString"></ColorRamp>
235+
</DefaultStyles>
236+
<WMSFees type="QString">conditions unknown</WMSFees>
237+
<WMSImageQuality type="int">90</WMSImageQuality>
238+
<Measurement>
239+
<DistanceUnits type="QString">meters</DistanceUnits>
240+
<AreaUnits type="QString">m2</AreaUnits>
241+
</Measurement>
242+
<WMSUrl type="QString"></WMSUrl>
243+
</properties>
244+
<visibility-presets/>
245+
</qgis>

0 commit comments

Comments
 (0)