@@ -1026,6 +1026,7 @@ int QgsOgrProvider::capabilities() const
1026
1026
ability |= ChangeGeometries;
1027
1027
}
1028
1028
1029
+ #if 0
1029
1030
if ( OGR_L_TestCapability( ogrLayer, "FastSpatialFilter" ) )
1030
1031
// TRUE if this layer implements spatial filtering efficiently.
1031
1032
// Layers that effectively read all features, and test them with the
@@ -1059,25 +1060,20 @@ int QgsOgrProvider::capabilities() const
1059
1060
{
1060
1061
// No use required for this QGIS release.
1061
1062
}
1063
+ #endif
1062
1064
1063
- if ( 1 )
1065
+ // OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
1066
+ if ( ogrDriverName == " ESRI Shapefile" )
1064
1067
{
1065
- // Ideally this should test for Shapefile type and GDAL >= 1.2.6
1066
- // In reality, createSpatialIndex() looks after itself.
1068
+ # if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1260
1069
+ // test for Shapefile type and GDAL >= 1.2.6
1067
1070
ability |= CreateSpatialIndex;
1068
- }
1069
-
1071
+ #endif
1070
1072
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
1071
- // adding attributes was added in GDAL 1.6
1072
- if ( ogrDriverName.startsWith ( " ESRI" ) )
1073
- {
1073
+ // adding attributes was added in GDAL 1.6
1074
1074
ability |= AddAttributes;
1075
- }
1076
1075
#endif
1077
1076
1078
- // OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
1079
- if ( ogrDriverName.startsWith ( " ESRI" ) )
1080
- {
1081
1077
if ( mAttributeFields .size () == 0 )
1082
1078
{
1083
1079
QgsDebugMsg ( " OGR doesn't handle shapefile without attributes well, ie. missing DBFs" );
@@ -1586,10 +1582,12 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
1586
1582
1587
1583
OGR_DS_Destroy ( dataSource );
1588
1584
1589
- if ( uri.endsWith ( " .shp" , Qt::CaseInsensitive ) )
1585
+ QString driverName = OGR_Dr_GetName ( driver );
1586
+
1587
+ if ( driverName == " ESRI Shapefile" )
1590
1588
{
1591
- QString layerName = uri.left ( uri.length () - 4 );
1592
- QFile prjFile ( layerName + " .prj " );
1589
+ QString layerName = uri.left ( uri.indexOf ( " .shp " , Qt::CaseInsensitive ) );
1590
+ QFile prjFile ( layerName + " .qpj " );
1593
1591
if ( prjFile.open ( QIODevice::WriteOnly ) )
1594
1592
{
1595
1593
QTextStream prjStream ( &prjFile );
@@ -1598,7 +1596,7 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
1598
1596
}
1599
1597
else
1600
1598
{
1601
- QgsDebugMsg ( " Couldn't open file " + layerName + " .prj " );
1599
+ QgsDebugMsg ( " Couldn't open file " + layerName + " .qpj " );
1602
1600
}
1603
1601
}
1604
1602
@@ -1618,6 +1616,29 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()
1618
1616
1619
1617
QgsCoordinateReferenceSystem srs;
1620
1618
1619
+ if ( ogrDriver )
1620
+ {
1621
+ QString driverName = OGR_Dr_GetName ( ogrDriver );
1622
+
1623
+ if ( driverName == " ESRI Shapefile" )
1624
+ {
1625
+ QString layerName = mFilePath .left ( mFilePath .indexOf ( " .shp" , Qt::CaseInsensitive ) );
1626
+ QFile prjFile ( layerName + " .qpj" );
1627
+ if ( prjFile.open ( QIODevice::ReadOnly ) )
1628
+ {
1629
+ QTextStream prjStream ( &prjFile );
1630
+ QString myWktString = prjStream.readLine ();
1631
+ prjFile.close ();
1632
+
1633
+ // create CRS from Wkt
1634
+ srs.createFromWkt ( myWktString );
1635
+
1636
+ if ( srs.isValid () )
1637
+ return srs;
1638
+ }
1639
+ }
1640
+ }
1641
+
1621
1642
OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef ( ogrLayer );
1622
1643
if ( mySpatialRefSys == NULL )
1623
1644
{
@@ -1626,10 +1647,10 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()
1626
1647
else
1627
1648
{
1628
1649
// get the proj4 text
1629
- char * ppszProj4;
1650
+ char *ppszProj4;
1630
1651
OSRExportToProj4 ( mySpatialRefSys, &ppszProj4 );
1631
1652
QgsDebugMsg ( ppszProj4 );
1632
- char *pszWkt = NULL ;
1653
+ char *pszWkt = NULL ;
1633
1654
OSRExportToWkt ( mySpatialRefSys, &pszWkt );
1634
1655
QString myWktString = QString ( pszWkt );
1635
1656
OGRFree ( pszWkt );
0 commit comments