internal static object ToDb2GeometryType(OgcGeometryType geometryType) { switch (geometryType) { case OgcGeometryType.Geometry: case OgcGeometryType.Point: case OgcGeometryType.LineString: case OgcGeometryType.Polygon: case OgcGeometryType.MultiLineString: case OgcGeometryType.MultiPoint: case OgcGeometryType.MultiPolygon: case OgcGeometryType.GeometryCollection: return(string.Format("ST_{0}", geometryType.ToString().ToUpper())); default: throw new ArgumentException(String.Format("Invalid geometry type: {0}", geometryType)); } }
/// <summary> /// Returns a formated string representation of this object. /// </summary> /// <returns>A formated string representation of this object</returns> public override String ToString() { return(Type.ToString()); }
public static void CreateDataTable <TOid>( FeatureDataTable featureDataTable, String schemaName, String tableName, String connectionString, String geometryColumnName, OgcGeometryType geometryType) { string srid = featureDataTable.GeometryFactory.SpatialReference != null ? featureDataTable.GeometryFactory.SpatialReference.AuthorityCode : DefaultSridInt.ToString(); NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder(connectionString); PostGisDbUtility util = new PostGisDbUtility(); NpgsqlConnection conn = (NpgsqlConnection)util.CreateConnection(connectionString); if (conn != null) { try { if (conn.State == ConnectionState.Closed) { conn.Open(); } if (!Has_X_Privilege(conn, "database", csb.Database, "CREATE")) { throw new PostGisException("Insufficient rights to create table!"); } if (!Has_X_Privilege(conn, "function", "addgeometrycolumn(character varying, character varying, int, character varying, int)", "EXECUTE")) { throw new PostGisException("Insufficient rights to access addgeometrycolumn function!"); } string createTableClause = string.Format( "CREATE TABLE {0}.\"{1}\" ({2}) WITH(OIDS=FALSE);", schemaName, tableName, ColumnsClause(tableName, featureDataTable.Columns, featureDataTable.Constraints)); new NpgsqlCommand(createTableClause, conn).ExecuteNonQuery(); String addGeometryColumnClause = String.Format("('{0}', '{1}', {2}, '{3}', {4})", tableName, geometryColumnName, srid, geometryType.ToString().ToUpper(), 2); //adding spatial column new NpgsqlCommand(String.Format("SELECT AddGeometryColumn {0};", addGeometryColumnClause), conn).ExecuteNonQuery(); //adding GIST index new NpgsqlCommand(String.Format("CREATE INDEX index_{0}_{1} ON {2}.\"{3}\" USING gist(\"{4}\");", tableName, geometryColumnName, schemaName, tableName, geometryColumnName), conn).ExecuteNonQuery(); } catch (NpgsqlException ex) { Trace.Write(ex.Message); throw new PostGisException(string.Format("Cannot create geometry column with type of '{0}'", geometryType)); } catch { } } conn.Close(); conn = null; PostGisProvider <TOid> prov = new PostGisProvider <TOid>( featureDataTable.GeometryFactory, connectionString, schemaName, tableName, featureDataTable.Columns[0].ColumnName, geometryColumnName); prov.Insert(featureDataTable); return; }