Skip to content
Permalink
Browse files

When upgrading 2.x projects to 3.0, default to enabling a valid

project projection instead of defaulting to no CRS

Fixes #16965
  • Loading branch information
nyalldawson committed Aug 3, 2017
1 parent 139fe68 commit b808c5647ac4f60d300dd2ee09beca5ea0430bbe
@@ -656,14 +656,6 @@ void QgsProjectFileTransform::transform2990()
if ( canvasNodes.count() > 0 )
{
QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
QDomNodeList projectionsNodes = canvasElem.elementsByTagName( QStringLiteral( "projections" ) );
bool hasOtf = false;
if ( projectionsNodes.count() > 0 )
{
QDomElement projectionsElem = projectionsNodes.at( 0 ).toElement();
hasOtf = projectionsElem.text().toInt();
}

QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral( "spatialrefsys" ) );
if ( canvasSrsNodes.count() > 0 )
{
@@ -727,7 +719,7 @@ void QgsProjectFileTransform::transform2990()
projectCrsIdElem.appendChild( srsidText );
QDomElement projectionsEnabledElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projectionsEnabledElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projectionsEnabledText = mDom.createTextNode( hasOtf ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
QDomText projectionsEnabledText = mDom.createTextNode( QStringLiteral( "1" ) );
projectionsEnabledElem.appendChild( projectionsEnabledText );
srsElem.appendChild( proj4Elem );
srsElem.appendChild( projectCrsElem );
@@ -751,6 +751,15 @@ def test_zip_unzip(self):
project2.clear()
self.assertFalse(project2.isZipped())

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


if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,245 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.18.10">
<title></title>
<autotransaction active="0"/>
<evaluateDefaultValues active="0"/>
<layer-tree-group expanded="1" checked="Qt::Checked" name="">
<customproperties/>
<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">
<customproperties/>
</layer-tree-layer>
</layer-tree-group>
<relations/>
<mapcanvas>
<units>meters</units>
<extent>
<xmin>2671057.63456883002072573</xmin>
<ymin>1211312.30044019035995007</ymin>
<xmax>2697247.79382618423551321</xmax>
<ymax>1236593.02145395800471306</ymax>
</extent>
<rotation>0</rotation>
<projections>0</projections>
<destinationsrs>
<spatialrefsys>
<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>
<srsid>47</srsid>
<srid>2056</srid>
<authid>EPSG:2056</authid>
<description>CH1903+ / LV95</description>
<projectionacronym>somerc</projectionacronym>
<ellipsoidacronym>bessel</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</destinationsrs>
<rendermaptile>0</rendermaptile>
<layer_coordinate_transform_info/>
</mapcanvas>
<layer-tree-canvas>
<custom-order enabled="0">
<item>New_scratch_layer20170802173624782</item>
</custom-order>
</layer-tree-canvas>
<legend updateDrawingOrder="true">
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="New scratch layer" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="New_scratch_layer20170802173624782" visible="1"/>
</filegroup>
</legendlayer>
</legend>
<projectlayers>
<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">
<id>New_scratch_layer20170802173624782</id>
<datasource>memory?geometry=Point&amp;crs=EPSG:2056</datasource>
<keywordList>
<value></value>
</keywordList>
<layername>New scratch layer</layername>
<srs>
<spatialrefsys>
<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>
<srsid>47</srsid>
<srid>2056</srid>
<authid>EPSG:2056</authid>
<description>CH1903+ / LV95</description>
<projectionacronym>somerc</projectionacronym>
<ellipsoidacronym>bessel</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="UTF-8">memory</provider>
<vectorjoins/>
<layerDependencies/>
<expressionfields/>
<map-layer-style-manager current="">
<map-layer-style name=""/>
</map-layer-style-manager>
<edittypes/>
<renderer-v2 forceraster="0" symbollevels="0" type="singleSymbol" enableorderby="0">
<symbols>
<symbol alpha="1" clip_to_extent="1" type="marker" name="0">
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="203,253,94,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="joinstyle" v="bevel"/>
<prop k="name" v="circle"/>
<prop k="offset" v="0,0"/>
<prop k="offset_map_unit_scale" v="0,0,0,0,0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_color" v="0,0,0,255"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0"/>
<prop k="outline_width_map_unit_scale" v="0,0,0,0,0,0"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="diameter"/>
<prop k="size" v="2"/>
<prop k="size_map_unit_scale" v="0,0,0,0,0,0"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
</symbol>
</symbols>
<rotation/>
<sizescale scalemethod="diameter"/>
</renderer-v2>
<labeling type="simple"/>
<customproperties/>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>0</layerTransparency>
<displayfield></displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Label"/>
<family fieldname="" name="Sans Serif"/>
<size fieldname="" units="pt" value="12"/>
<bold fieldname="" on="0"/>
<italic fieldname="" on="0"/>
<underline fieldname="" on="0"/>
<strikeout fieldname="" on="0"/>
<color fieldname="" red="0" blue="0" green="0"/>
<x fieldname=""/>
<y fieldname=""/>
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
<angle fieldname="" value="0" auto="0"/>
<alignment fieldname="" value="center"/>
<buffercolor fieldname="" red="255" blue="255" green="255"/>
<buffersize fieldname="" units="pt" value="1"/>
<bufferenabled fieldname="" on=""/>
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<annotationform></annotationform>
<aliases/>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<attributeactions default="-1"/>
<attributetableconfig actionWidgetStyle="dropDown" sortExpression="" sortOrder="-2085748272">
<columns/>
</attributetableconfig>
<editform></editform>
<editforminit/>
<editforminitcodesource>0</editforminitcodesource>
<editforminitfilepath></editforminitfilepath>
<editforminitcode><![CDATA[]]></editforminitcode>
<featformsuppress>0</featformsuppress>
<editorlayout>generatedlayout</editorlayout>
<widgets/>
<conditionalstyles>
<rowstyles/>
<fieldstyles/>
</conditionalstyles>
<defaults/>
<previewExpression></previewExpression>
</maplayer>
</projectlayers>
<properties>
<WMSContactPerson type="QString"></WMSContactPerson>
<Variables>
<variableNames type="QStringList"/>
<variableValues type="QStringList"/>
</Variables>
<WMSOnlineResource type="QString"></WMSOnlineResource>
<WMSUseLayerIDs type="bool">false</WMSUseLayerIDs>
<WMSContactOrganization type="QString"></WMSContactOrganization>
<WMSKeywordList type="QStringList">
<value></value>
</WMSKeywordList>
<WFSUrl type="QString"></WFSUrl>
<Paths>
<Absolute type="bool">false</Absolute>
</Paths>
<WMSServiceTitle type="QString"></WMSServiceTitle>
<WFSLayers type="QStringList"/>
<WMSContactMail type="QString"></WMSContactMail>
<PositionPrecision>
<DecimalPlaces type="int">2</DecimalPlaces>
<Automatic type="bool">true</Automatic>
<DegreeFormat type="QString">MU</DegreeFormat>
</PositionPrecision>
<WCSUrl type="QString"></WCSUrl>
<WMSContactPhone type="QString"></WMSContactPhone>
<WMSServiceCapabilities type="bool">false</WMSServiceCapabilities>
<WMSServiceAbstract type="QString"></WMSServiceAbstract>
<WMSContactPosition type="QString"></WMSContactPosition>
<WMSAddWktGeometry type="bool">false</WMSAddWktGeometry>
<Measure>
<Ellipsoid type="QString">NONE</Ellipsoid>
</Measure>
<WMSPrecision type="QString">8</WMSPrecision>
<WMSSegmentizeFeatureInfoGeometry type="bool">false</WMSSegmentizeFeatureInfoGeometry>
<WFSTLayers>
<Insert type="QStringList"/>
<Update type="QStringList"/>
<Delete type="QStringList"/>
</WFSTLayers>
<Gui>
<SelectionColorBluePart type="int">0</SelectionColorBluePart>
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
<CanvasColorRedPart type="int">255</CanvasColorRedPart>
<SelectionColorRedPart type="int">255</SelectionColorRedPart>
<SelectionColorAlphaPart type="int">128</SelectionColorAlphaPart>
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
</Gui>
<Digitizing>
<DefaultSnapToleranceUnit type="int">2</DefaultSnapToleranceUnit>
<SnappingMode type="QString">current_layer</SnappingMode>
<DefaultSnapType type="QString">off</DefaultSnapType>
<DefaultSnapTolerance type="double">0</DefaultSnapTolerance>
</Digitizing>
<Identify>
<disabledLayers type="QStringList"/>
</Identify>
<Macros>
<pythonCode type="QString"></pythonCode>
</Macros>
<WMSAccessConstraints type="QString">None</WMSAccessConstraints>
<WCSLayers type="QStringList"/>
<Legend>
<filterByMap type="bool">false</filterByMap>
</Legend>
<SpatialRefSys>
<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>
<ProjectCrs type="QString">EPSG:2056</ProjectCrs>
<ProjectCRSID type="int">47</ProjectCRSID>
</SpatialRefSys>
<DefaultStyles>
<Fill type="QString"></Fill>
<Line type="QString"></Line>
<Marker type="QString"></Marker>
<RandomColors type="bool">true</RandomColors>
<AlphaInt type="int">255</AlphaInt>
<ColorRamp type="QString"></ColorRamp>
</DefaultStyles>
<WMSFees type="QString">conditions unknown</WMSFees>
<WMSImageQuality type="int">90</WMSImageQuality>
<Measurement>
<DistanceUnits type="QString">meters</DistanceUnits>
<AreaUnits type="QString">m2</AreaUnits>
</Measurement>
<WMSUrl type="QString"></WMSUrl>
</properties>
<visibility-presets/>
</qgis>

0 comments on commit b808c56

Please sign in to comment.
You can’t perform that action at this time.