Using PgSqlLoader to populate a Postgis geometry
Posted: Tue 10 Nov 2020 13:55
Hi,
I'm trying to populate a table in Postgres containing a Postgis geometry datatype, essentially this is the code:
This will produce the following exception:
Error = {ERROR: XX000: parse error - invalid geometry}
COPY Models, line 1, column projected_geom2_d: "\001\003\000\000\000\001\000\000\000\005\000\000\000\000\000\000\000\000\000>@\000\000\000\000\000\0..."
"\0" <-- parse error at position 2 within geometry
Do you guys have any idea how to solve this?
Kinds regards Gajus.
I'm trying to populate a table in Postgres containing a Postgis geometry datatype, essentially this is the code:
Code: Select all
using System.Data.Entity.Spatial;
public class Table {
public DbGeometry ProjectedGeom2D
{
get;
set;
}
}
public void WriteToTable() {
Table table = new Table()
{
ProjectedGeom2D = DbGeometry.FromText("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))", 4326)
};
var conn = new PgSqlConnection("user id=postgres;Password=postgres;host=localhost;database=database;");
if (conn.State == ConnectionState.Closed)
conn.Open();
PgSqlLoader modelLoader = new PgSqlLoader();
modelLoader.Connection = conn;
modelLoader.TableName = "Models";
modelLoader.CreateColumns();
modelLoader.Open();
modelLoader.SetValue("projected_geom2_d", table.ProjectedGeom2D.AsBinary());
modelLoader.Close();
}
Error = {ERROR: XX000: parse error - invalid geometry}
COPY Models, line 1, column projected_geom2_d: "\001\003\000\000\000\001\000\000\000\005\000\000\000\000\000\000\000\000\000>@\000\000\000\000\000\0..."
"\0" <-- parse error at position 2 within geometry
Do you guys have any idea how to solve this?
Kinds regards Gajus.