crs_in_providers.diff

Chris Crook, 2011-01-24 05:13 PM

Download (23.9 KB)

View differences:

python/core/qgscoordinatereferencesystem.sip (working copy)
23 23

  
24 24
        ~QgsCoordinateReferenceSystem();
25 25
        
26
        /*! 
27
         * Constructs a CRS object from a Wkt string
28
         * @param theWkt A String containing a valid Wkt def
26
        /*!
27
         * Constructs a CRS object from a string definition as defined in the createFromString 
28
         * member function (by default a WKT definition).
29
         * @param theDefinition A String containing a coordinate reference system definition.
29 30
         */
30
        explicit QgsCoordinateReferenceSystem(QString theWkt);
31
        explicit QgsCoordinateReferenceSystem( QString theDefinition );
31 32

  
32 33
        /*! Use this constructor when you want to create a CRS object using 
33 34
         *  a postgis SRID, an Epsg Id id or a QGIS CRS_ID.
......
38 39

  
39 40
        // Misc helper functions -----------------------
40 41

  
41
        void createFromId(const long theId, CrsType theType=PostgisCrsId);
42
        bool createFromId(const long theId, CrsType theType=PostgisCrsId);
42 43

  
43 44
        /**
44 45
         * \brief Set up this CRS from the given OGC CRS
......
70 71
         * @return bool TRUE if sucess else false
71 72
         */
72 73
        bool createFromWkt(const QString theWkt);
74
        
75
        /*! Set up this srs from a string definition, by default a WKT definition.  Otherwise
76
         * the string defines a authority, followed by a colon, followed by the definition.
77
         * The authority can be one of "epsg", "postgis", "internal" for integer definitions,
78
         * and "wkt" or "proj4" for string definitions.  The implementation of each authority
79
         * uses the corresponding createFrom... function.
80
         * @param theDefinition A String containing a coordinate reference system definition.
81
         */
82
        bool createFromString( const QString theDefinition );
73 83

  
74 84
        /*! Set up this srs by fetching the appropriate information from the 
75 85
         * sqlite backend. First the system level read only srs.db will be checked
src/core/qgscoordinatereferencesystem.cpp (working copy)
51 51
  mCRS = OSRNewSpatialReference( NULL );
52 52
}
53 53

  
54
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( QString theWkt )
54
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( QString theDefinition )
55 55
    : mMapUnits( QGis::UnknownUnit )
56 56
    , mIsValidFlag( 0 )
57 57
    , mValidationHint( "" )
58 58
{
59 59
  mCRS = OSRNewSpatialReference( NULL );
60
  createFromWkt( theWkt );
60
  createFromString( theDefinition );
61 61
}
62 62

  
63 63

  
......
75 75
  OSRDestroySpatialReference( mCRS );
76 76
}
77 77

  
78
void QgsCoordinateReferenceSystem::createFromId( const long theId, CrsType theType )
78
bool QgsCoordinateReferenceSystem::createFromId( const long theId, CrsType theType )
79 79
{
80
  bool result = false;
80 81
  switch ( theType )
81 82
  {
82 83
    case InternalCrsId:
83
      createFromSrsId( theId );
84
      result = createFromSrsId( theId );
84 85
      break;
85 86
    case PostgisCrsId:
86
      createFromSrid( theId );
87
      result = createFromSrid( theId );
87 88
      break;
88 89
    case EpsgCrsId:
89
      createFromEpsg( theId );
90
      result = createFromEpsg( theId );
90 91
      break;
91 92
    default:
92 93
      //THIS IS BAD...THIS PART OF CODE SHOULD NEVER BE REACHED...
93 94
      QgsDebugMsg( "Unexpected case reached!" );
94 95
  };
96
  return result;
95 97
}
96 98

  
99
bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition )
100
{
101
  bool result = false;
102
  QRegExp reCrsId("^(epsg|postgis|internal)\\:(\\d+)$",Qt::CaseInsensitive);
103
  if( reCrsId.indexIn(theDefinition) == 0)
104
  {
105
      QString authName = reCrsId.cap(1).toLower();
106
      CrsType type = InternalCrsId;
107
      if( authName == "epsg" ) type = EpsgCrsId;
108
      if( authName == "postgis" ) type = PostgisCrsId;
109
      long id = reCrsId.cap(2).toLong();
110
      result = createFromId(id,type);
111
  }
112
  else
113
  {
114
      QRegExp reCrsStr("^(?:(wkt|proj4)\\:)?(.+)$",Qt::CaseInsensitive);
115
      if( reCrsStr.indexIn(theDefinition) == 0 )
116
      {
117
          if( reCrsStr.cap(1).toLower() == "proj4" )
118
          {
119
             result = createFromProj4(reCrsStr.cap(2));
120
          }
121
          else
122
          {
123
              result = createFromWkt(reCrsStr.cap(2));
124
          }
125
      }
126
  }
127
  return result;
128
}
129

  
97 130
bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
98 131
{
99 132
  if ( loadFromDb( QgsApplication::srsDbFilePath(), "lower(auth_name||':'||auth_id)", theCrs.toLower() ) )
src/core/qgscoordinatereferencesystem.h (working copy)
57 57
    ~QgsCoordinateReferenceSystem();
58 58

  
59 59
    /*!
60
     * Constructs a CRS object from a Wkt string
61
     * @param theWkt A String containing a valid Wkt def
60
     * Constructs a CRS object from a string definition as defined in the createFromString 
61
     * member function (by default a WKT definition).
62
     * @param theDefinition A String containing a coordinate reference system definition.
62 63
     */
63
    explicit QgsCoordinateReferenceSystem( QString theWkt );
64
    explicit QgsCoordinateReferenceSystem( QString theDefinition );
64 65

  
65 66
    /*! Use this constructor when you want to create a CRS object using
66 67
     *  a postgis SRID, an EpsgCrsId id or a QGIS CRS_ID.
......
79 80

  
80 81
    // Misc helper functions -----------------------
81 82

  
82
    void createFromId( const long theId, CrsType theType = PostgisCrsId );
83
    bool createFromId( const long theId, CrsType theType = PostgisCrsId );
83 84

  
84 85
    /**
85 86
     * \brief Set up this CRS from the given OGC CRS
......
161 162
     * @return bool TRUE if sucess else false
162 163
     */
163 164
    bool createFromProj4( const QString theProjString );
165
    
166
    /*! Set up this srs from a string definition, by default a WKT definition.  Otherwise
167
     * the string defines a authority, followed by a colon, followed by the definition.
168
     * The authority can be one of "epsg", "postgis", "internal" for integer definitions,
169
     * and "wkt" or "proj4" for string definitions.  The implementation of each authority
170
     * uses the corresponding createFrom... function.
171
     * @param theDefinition A String containing a coordinate reference system definition.
172
     */
173
    bool createFromString( const QString theDefinition );
164 174

  
165 175
    /*! Find out whether this CRS is correctly initialised and usable */
166 176
    bool isValid() const;
src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp (working copy)
25 25
#include <QRegExp>
26 26
#include <QMessageBox>
27 27
#include <QTextStream>
28
#include <QUrl>
28 29
#include "qgslogger.h"
29 30

  
30 31
QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidget * parent, Qt::WFlags fl )
......
56 57
    delimiterRegexp->setChecked( true );
57 58
  }
58 59

  
60
  QString delimiterChars = settings.value( key + "/delimiterChars", " " ).toString();
61
  cbxDelimSpace->setChecked( delimiterChars.contains(" "));
62
  cbxDelimTab->setChecked( delimiterChars.contains("\\t"));
63
  cbxDelimColon->setChecked( delimiterChars.contains(":"));
64
  cbxDelimSemicolon->setChecked( delimiterChars.contains(":"));
65
  cbxDelimComma->setChecked( delimiterChars.contains(","));
66

  
59 67
  cmbXField->setDisabled( true );
60 68
  cmbYField->setDisabled( true );
61 69
  cmbWktField->setDisabled( true );
......
99 107
    else if ( delimiterRegexp->isChecked() )
100 108
      delimiterType = "regexp";
101 109

  
102
    QString uri = QString( "%1?delimiter=%2&delimiterType=%3" )
103
                  .arg( txtFilePath->text() )
104
                  .arg( txtDelimiter->text() )
105
                  .arg( delimiterType );
110
    QUrl url(txtFilePath->text());
111
    url.addQueryItem("delimiter",txtDelimiter->text());
112
    url.addQueryItem("delimiterType",delimiterType);
106 113

  
107 114
    if ( geomTypeXY->isChecked() )
108 115
    {
109 116
      if ( !cmbXField->currentText().isEmpty() && !cmbYField->currentText().isEmpty() )
110 117
      {
111
        uri += QString( "&xField=%1&yField=%2" )
112
               .arg( cmbXField->currentText() )
113
               .arg( cmbYField->currentText() );
118
          url.addQueryItem("xField",cmbXField->currentText());
119
          url.addQueryItem("yField",cmbYField->currentText());
114 120
      }
115 121
    }
116 122
    else
117 123
    {
118 124
      if ( ! cmbWktField->currentText().isEmpty() )
119 125
      {
120
        uri += QString( "&wktField=%1" )
121
               .arg( cmbWktField->currentText() );
126
        url.addQueryItem("wktField",cmbWktField->currentText());
122 127
      }
123 128
    }
124 129

  
125 130
    int skipLines = rowCounter->value();
126 131
    if ( skipLines > 0 )
127
      uri += QString( "&skipLines=%1" ).arg( skipLines );
132
        url.addQueryItem("skipLines",QString( "%1" ).arg( skipLines ));
128 133

  
129 134
    // add the layer to the map
135

  
136
    QString uri(url.toEncoded());
130 137
    emit drawVectorLayer( uri, txtLayerName->text(), "delimitedtext" );
131 138
    // store the settings
132 139

  
......
138 145

  
139 146
    if ( delimiterSelection->isChecked() )
140 147
      settings.setValue( key + "/delimiterType", "selection" );
141
    if ( delimiterPlain->isChecked() )
148
    else if ( delimiterPlain->isChecked() )
142 149
      settings.setValue( key + "/delimiterType", "plain" );
143 150
    else
144 151
      settings.setValue( key + "/delimiterType", "regexp" );
152
    settings.setValue( key + "/delimiterChars", selectedChars());
145 153

  
146 154
    accept();
147 155
  }
......
156 164
  reject();
157 165
}
158 166

  
167
QString QgsDelimitedTextPluginGui::selectedChars()
168
{
169
    QString chars = "";
170
    if ( cbxDelimSpace->isChecked() ) chars += " ";
171
    if ( cbxDelimTab->isChecked() ) chars += "\\t";
172
    if ( cbxDelimSemicolon->isChecked() ) chars += ";";
173
    if ( cbxDelimComma->isChecked() ) chars += ",";
174
    if ( cbxDelimColon->isChecked() ) chars += ":";
175
    return chars;
176
}
177

  
159 178
QStringList QgsDelimitedTextPluginGui::splitLine( QString line )
160 179
{
161 180
  QStringList fieldList;
......
171 190
  else if ( delimiterSelection->isChecked() )
172 191
  {
173 192
    delimiter = "[";
174
    if ( cbxDelimSpace->isChecked() ) delimiter += " ";
175
    if ( cbxDelimTab->isChecked() ) delimiter += "\t";
176
    if ( cbxDelimSemicolon->isChecked() ) delimiter += ";";
177
    if ( cbxDelimComma->isChecked() ) delimiter += ",";
178
    if ( cbxDelimColon->isChecked() ) delimiter += ":";
193
    delimiter += selectedChars();
179 194
    delimiter += "]";
180 195
    txtDelimiter->setText( delimiter );
181 196
    fieldList = line.split( QRegExp( delimiter ) );
src/plugins/delimited_text/qgsdelimitedtextplugingui.h (working copy)
37 37
    bool haveValidFileAndDelimiters();
38 38
    void updateFieldLists();
39 39
    void getOpenFileName();
40
    QString selectedChars();
40 41

  
41 42
    QgisInterface * qI;
42 43
    QAbstractButton *pbnOK;
src/plugins/delimited_text/qgsdelimitedtextpluginguibase.ui (working copy)
331 331
           <string>Name of the field containing x values. Choose a field from the list. The list is generated by parsing the header row of the delimited text file.</string>
332 332
          </property>
333 333
          <property name="editable">
334
           <bool>true</bool>
334
           <bool>false</bool>
335 335
          </property>
336 336
         </widget>
337 337
        </item>
......
366 366
           <string>Name of the field containing y values. Choose a field from the list. The list is generated by parsing the header row of the delimited text file.</string>
367 367
          </property>
368 368
          <property name="editable">
369
           <bool>true</bool>
369
           <bool>false</bool>
370 370
          </property>
371 371
         </widget>
372 372
        </item>
......
409 409
         <string>Name of the field containing y values. Choose a field from the list. The list is generated by parsing the header row of the delimited text file.</string>
410 410
        </property>
411 411
        <property name="editable">
412
         <bool>true</bool>
412
         <bool>false</bool>
413 413
        </property>
414 414
       </widget>
415 415
      </item>
src/providers/delimitedtext/qgsdelimitedtextprovider.cpp (working copy)
18 18

  
19 19
#include "qgsdelimitedtextprovider.h"
20 20

  
21

  
22 21
#include <QtGlobal>
23 22
#include <QFile>
24 23
#include <QDataStream>
......
135 134
    : QgsVectorDataProvider( uri )
136 135
    , mHasWktField( false )
137 136
    , mFieldCount( 0 )
138
    , mXFieldIndex( -1 ), mYFieldIndex( -1 )
137
    , mXFieldIndex( -1 ) 
138
    , mYFieldIndex( -1 )
139 139
    , mWktFieldIndex( -1 )
140
    , mDelimiterType( "plain" )
141
    , mDelimiter( "," )
142
    , mDelimiterRegexp()
140 143
    , mWktHasZM( false )
141 144
    , mWktZMRegexp( "\\s+(?:z|m|zm)(?=\\s*\\()", Qt::CaseInsensitive )
142 145
    , mWktCrdRegexp( "(\\-?\\d+(?:\\.\\d*)?\\s+\\-?\\d+(?:\\.\\d*)?)\\s[\\s\\d\\.\\-]+" )
146
    , mSkipLines(0)
143 147
    , mFirstDataLine( 0 )
144 148
    , mShowInvalidLines( true )
145 149
    , mWkbType( QGis::WKBNoGeometry )
150
    , mCrs()
146 151
{
147
  // Get the file name and mDelimiter out of the uri
148
  mFileName = uri.left( uri.indexOf( "?" ) );
149
  // split the string up on & to get the individual parameters
150
  QStringList parameters = uri.mid( uri.indexOf( "?" ) ).split( "&", QString::SkipEmptyParts );
151 152

  
152
  QgsDebugMsg( "Parameter count after split on &" + QString::number( parameters.size() ) );
153
  QUrl url = QUrl::fromEncoded(uri.toUtf8());
153 154

  
154
  // get the individual parameters and assign values
155
  QStringList temp = parameters.filter( "delimiter=" );
156
  mDelimiter = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "";
157
  temp = parameters.filter( "delimiterType=" );
158
  mDelimiterType = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "";
159
  temp = parameters.filter( "wktField=" );
160
  QString wktField = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "";
161
  temp = parameters.filter( "xField=" );
162
  QString xField = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "";
163
  temp = parameters.filter( "yField=" );
164
  QString yField = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "";
165
  temp = parameters.filter( "skipLines=" );
166
  QString skipLines = temp.size() ? temp[0].mid( temp[0].indexOf( "=" ) + 1 ) : "0";
167
  // Decode the parts of the uri. Good if someone entered '=' as a delimiter, for instance.
168
  mFileName  = QUrl::fromPercentEncoding( mFileName.toUtf8() );
169
  mDelimiter = QUrl::fromPercentEncoding( mDelimiter.toUtf8() );
170
  mDelimiterType = QUrl::fromPercentEncoding( mDelimiterType.toUtf8() );
171
  wktField = QUrl::fromPercentEncoding( wktField.toUtf8() );
172
  xField = QUrl::fromPercentEncoding( xField.toUtf8() );
173
  yField = QUrl::fromPercentEncoding( yField.toUtf8() );
155
  // Extract the provider definition from the url
174 156

  
175
  mHasWktField = wktField != "";
157
  mFileName = url.path();
176 158

  
177
  skipLines = QUrl::fromPercentEncoding( skipLines.toUtf8() );
159
  QString wktField("");
160
  QString xField("");
161
  QString yField("");
178 162

  
179
  mSkipLines = skipLines.toInt();
163
  if( url.hasQueryItem("delimiter")) mDelimiter = url.queryItemValue("delimiter");
164
  if( url.hasQueryItem("delimiterType")) mDelimiterType = url.queryItemValue("delimiterType");
165
  if( url.hasQueryItem("wktField")) wktField = url.queryItemValue("wktField");
166
  if( url.hasQueryItem("xField")) xField = url.queryItemValue("xField");
167
  if( url.hasQueryItem("yField")) yField = url.queryItemValue("yField");
168
  if( url.hasQueryItem("skipLines")) mSkipLines = url.queryItemValue("skipLines").toInt();
169
  if( url.hasQueryItem("crs")) mCrs.createFromString( url.queryItemValue("crs"));
180 170

  
171
  mHasWktField = wktField != "";
172

  
181 173
  QgsDebugMsg( "Data source uri is " + uri );
182 174
  QgsDebugMsg( "Delimited text file is: " + mFileName );
183 175
  QgsDebugMsg( "Delimiter is: " + mDelimiter );
......
481 473
        geom = 0;
482 474
      }
483 475
      mFid++;
484
      if ( !boundsCheck( geom ) )
476
      if ( geom && !boundsCheck( geom ) )
485 477
      {
486 478
        delete geom;
487 479
        geom = 0;
......
682 674

  
683 675
QgsCoordinateReferenceSystem QgsDelimitedTextProvider::crs()
684 676
{
685
  // TODO: make provider projection-aware
686
  return QgsCoordinateReferenceSystem(); // return default CRS
677
  return mCrs;
687 678
}
688 679

  
689 680

  
src/providers/delimitedtext/qgsdelimitedtextprovider.h (working copy)
241 241
    };
242 242
    wkbPoint mWKBpt;
243 243

  
244
    // Coordinate reference sytem
245
    QgsCoordinateReferenceSystem mCrs;
246

  
244 247
    QGis::WkbType mWkbType;
245 248

  
246 249
    QString readLine( QTextStream *stream );
src/providers/memory/qgsmemoryprovider.cpp (working copy)
22 22
#include "qgsspatialindex.h"
23 23
#include "qgscoordinatereferencesystem.h"
24 24

  
25
#include <QUrl>
26
#include <QRegExp>
25 27

  
28

  
26 29
static const QString TEXT_PROVIDER_KEY = "memory";
27 30
static const QString TEXT_PROVIDER_DESCRIPTION = "Memory provider";
28 31

  
......
31 34
    mSelectRectGeom( NULL ),
32 35
    mSpatialIndex( NULL )
33 36
{
34
  if ( uri == "Point" )
37
  // Initiallize the geometry with the uri to support old style uri's 
38
  // (ie, just 'point', 'line', 'polygon')
39
  QUrl url = QUrl::fromEncoded(uri.toUtf8());
40
  QString geometry;
41
  if( url.hasQueryItem("geometry")) 
42
  {
43
      geometry = url.queryItemValue("geometry");
44
  }
45
  else
46
  {
47
      geometry = url.path();
48
  }
49

  
50
  geometry = geometry.toLower();
51
  if ( geometry == "point" )
35 52
    mWkbType = QGis::WKBPoint;
36
  else if ( uri == "LineString" )
53
  else if ( geometry == "linestring" )
37 54
    mWkbType = QGis::WKBLineString;
38
  else if ( uri == "Polygon" )
55
  else if ( geometry == "polygon" )
39 56
    mWkbType = QGis::WKBPolygon;
40
  else if ( uri == "MultiPoint" )
57
  else if ( geometry == "multipoint" )
41 58
    mWkbType = QGis::WKBMultiPoint;
42
  else if ( uri == "MultiLineString" )
59
  else if ( geometry == "multilinestring" )
43 60
    mWkbType = QGis::WKBMultiLineString;
44
  else if ( uri == "MultiPolygon" )
61
  else if ( geometry == "multipolygon" )
45 62
    mWkbType = QGis::WKBMultiPolygon;
46 63
  else
47 64
    mWkbType = QGis::WKBUnknown;
48 65

  
66
  if( url.hasQueryItem("crs"))
67
  {
68
      QString crsDef = url.queryItemValue("crs");
69
      mCrs.createFromString(crsDef);
70
  }
71

  
49 72
  mNextFeatureId = 1;
50 73

  
51 74
  mNativeTypes
......
53 76
  << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 5 )
54 77
  << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 )
55 78
  ;
79

  
80
  if( url.hasQueryItem("field"))
81
  {
82
    QList<QgsField> attributes;
83
    QRegExp reFieldDef("\\:" 
84
                       "(int|integer|real|double|string)" // type
85
                       "(?:\\((\\d+)"                // length
86
                       "(?:\\,(\\d+))?"                // precision
87
                       "\\))?"
88
                       "$", Qt::CaseInsensitive);
89
    QStringList fields = url.allQueryItemValues("field");
90
    for( int i = 0; i < fields.size(); i++ )
91
    {
92
        QString name = fields.at(i);
93
        QVariant::Type type = QVariant::String;
94
        QString typeName("string");
95
        int length = 255;
96
        int precision = 0;
97
        
98
        int pos = reFieldDef.indexIn(name);
99
        if( pos >= 0 )
100
        {
101
            name = name.mid(0,pos);
102
            typeName = reFieldDef.cap(1).toLower();
103
            if( typeName == "int" || typeName == "integer" )
104
            {
105
                type = QVariant::Int;
106
                typeName = "integer";
107
                length = 10;
108
            }
109
            else if( typeName == "real" || typeName == "double" )
110
            {
111
                type = QVariant::Double;
112
                typeName = "double";
113
                length=20;
114
                precision = 5;
115
            }
116

  
117
            if( reFieldDef.cap(2) != "" )
118
            {
119
                length = reFieldDef.cap(2).toInt();
120
            }
121
            if( reFieldDef.cap(3) != "" )
122
            {
123
                precision = reFieldDef.cap(3).toInt();
124
            }
125
        }
126
       if( name != "" ) attributes.append(QgsField(name,type,typeName,length,precision));
127
    }
128
    addAttributes(attributes);
129
  }
130

  
131
  if( url.hasQueryItem("index") && url.queryItemValue("index") == "yes" )
132
  {
133
      createSpatialIndex();
134
  }
135

  
56 136
}
57 137

  
58 138
QgsMemoryProvider::~QgsMemoryProvider()
......
61 141
  delete mSelectRectGeom;
62 142
}
63 143

  
144
QString QgsMemoryProvider::dataSourceUri() const
145
{
146
    QUrl uri("memory");
147
    QString geometry("");
148
    switch(mWkbType)
149
    {
150
    case QGis::WKBPoint :
151
        geometry="Point";
152
        break;
153
    case QGis::WKBLineString :
154
        geometry="LineString";
155
        break;
156
    case QGis::WKBPolygon :
157
        geometry="Polygon";
158
        break;
159
    case QGis::WKBMultiPoint :
160
        geometry="MultiPoint";
161
        break;
162
    case QGis::WKBMultiLineString :
163
        geometry="MultiLineString";
164
        break;
165
    case QGis::WKBMultiPolygon :
166
        geometry="MultiPolygon";
167
        break;
168
    }
169
    uri.addQueryItem("geometry",geometry);
170

  
171
    if( mCrs.isValid())
172
    {
173
        QString crsDef("");
174
        long srid = mCrs.epsg();
175
        if( srid )
176
        {
177
            crsDef = QString("epsg:%1").arg(srid);
178
        }
179
        else if(  srid=mCrs.postgisSrid() )
180
        {
181
            crsDef = QString("postgis:%1").arg(srid);
182
        }
183
        else
184
        {
185
            crsDef = QString("wkt:%1").arg(mCrs.toWkt());
186
        }
187
        uri.addQueryItem("crs",crsDef);
188
    }
189
    if( mSpatialIndex )
190
    {
191
        uri.addQueryItem("index","yes");
192
    }
193

  
194
    QgsAttributeList attrs = const_cast<QgsMemoryProvider *>(this)->attributeIndexes();
195
    for( int i = 0; i < attrs.size(); i++ )
196
    {
197
        QgsField field = mFields[attrs[i]];
198
        QString fieldDef = field.name();
199
        fieldDef.append(QString(":%2(%3,%4)").arg(field.typeName()).arg(field.length()).arg(field.precision()));
200
        uri.addQueryItem("field",fieldDef);
201
    }
202

  
203
    return QString(uri.toEncoded());
204

  
205
}
206

  
64 207
QString QgsMemoryProvider::storageType() const
65 208
{
66 209
  return "Memory storage";
......
231 374
QgsCoordinateReferenceSystem QgsMemoryProvider::crs()
232 375
{
233 376
  // TODO: make provider projection-aware
234
  return QgsCoordinateReferenceSystem(); // return default CRS
377
  return mCrs; // return default CRS
235 378
}
236 379

  
237 380

  
src/providers/memory/qgsmemoryprovider.h (working copy)
34 34
    /**
35 35
     * Returns the permanent storage type for this layer as a friendly name.
36 36
     */
37

  
38
    virtual QString dataSourceUri() const;
39

  
40
    /**
41
     * Returns the permanent storage type for this layer as a friendly name.
42
     */
37 43
    virtual QString storageType() const;
38 44

  
39 45
    /** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
......
185 191
    void updateExtent();
186 192

  
187 193
  private:
194
    // Coordinate reference system
195
    QgsCoordinateReferenceSystem mCrs;
196

  
188 197
    // fields
189 198
    QgsFieldMap mFields;
190 199
    QGis::WkbType mWkbType;