/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(GeometryColumnInfo featureSetInfo, string sql) { var fType = GetGeometryType(featureSetInfo.GeometryType); SpatiaLiteFeatureSet fs = new SpatiaLiteFeatureSet(fType) { IndexMode = true, // setting the initial index mode.. Name = featureSetInfo.TableName, Filename = SqLiteHelper.GetSqLiteFileName(ConnectionString), LayerName = featureSetInfo.TableName }; using (var cmd = CreateCommand(ConnectionString, sql)) { cmd.Connection.Open(); var wkbr = new SpatiaLiteWkbReader(); var rdr = cmd.ExecuteReader(); var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); while (rdr.Read()) { var wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; var geom = wkbr.Read(wkb); var newFeature = fs.AddFeature(geom); // populate the attributes foreach (var colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); // assign projection if (featureSetInfo.Srid > 0) { var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.Srid); fs.Projection = proj; } return(fs); } }
/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="connString">sqlite db connection string</param> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(string connString, GeometryColumnInfo featureSetInfo, string sql) { var fType = GetGeometryType(featureSetInfo.GeometryType); FeatureSet fs = new SpatiaLiteFeatureSet(fType); fs.IndexMode = false; // setting the initial index mode.. using (var cmd = CreateCommand(connString, sql)) { cmd.Connection.Open(); RunInitialCommands(cmd.Connection); // DotSpatial.Topology.Utilities.WkbReader wkbr = new DotSpatial.Topology.Utilities.WkbReader(); var wkbr = new SpatiaLiteWkbReader(); var rdr = cmd.ExecuteReader(); var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); while (rdr.Read()) { var wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; var geom = wkbr.Read(wkb); var newFeature = fs.AddFeature(geom); // populate the attributes foreach (var colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); fs.Name = featureSetInfo.TableName; // HACK required for selection to work properly fs.IndexMode = true; // assign projection var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.Srid); fs.Projection = proj; return(fs); } }
/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="connString">sqlite db connection string</param> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(string connString, GeometryColumnInfo featureSetInfo, string sql) { var fType = GetGeometryType(featureSetInfo.GeometryType); FeatureSet fs = new SpatiaLiteFeatureSet(fType); fs.IndexMode = false; //setting the initial index mode.. using (var cmd = CreateCommand(connString, sql)) { cmd.Connection.Open(); RunInitialCommands(cmd.Connection); //DotSpatial.Topology.Utilities.WkbReader wkbr = new DotSpatial.Topology.Utilities.WkbReader(); var wkbr = new SpatiaLiteWkbReader(); var rdr = cmd.ExecuteReader(); var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); while (rdr.Read()) { var wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; var geom = wkbr.Read(wkb); var newFeature = fs.AddFeature(geom); //populate the attributes foreach (var colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); fs.Name = featureSetInfo.TableName; //HACK required for selection to work properly fs.IndexMode = true; //assign projection var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.SRID); fs.Projection = proj; return fs; } }