MySql drivers for .NET do not support the Polygon framework, right?

I am trying to get Polygon data from MySQL in my C # application.

I precisely defined in one table the Polygon field where geodata are stored.

Evidence:

 SELECT GeometryType(GeomFromText(AsWKT(object))) as `type` FROM geo.data; 

Return:

enter image description here

Thus, the object in the table is accurate and correct.

C # has the source code:

http://ideone.com/bn1urQ

And the main lines are (73-76):

 //var polygon = (byte[])reader["object"]; //var obj = new MySqlGeometry(MySqlDbType.Blob, polygon); var polygon = reader["object"].ToString(); var obj = MySqlGeometry.Parse(polygon); 

I commented on this, but it is not an obstacle to tell you about all the operations:

  • extract as a BLOB with the following deserialization
  • parsing a string using the MySqlGeometry.Parse(System.String) method MySqlGeometry.Parse(System.String)

Download BLOB

Well, I'll start with the commented part of the code, let's imagine that these lines are uncommented and there are no lines 75 and 76 with parsing of the lines.

There is also another correction, the SQL query that is sent to the MySQL server should look like this:

 SELECT AsWKB(object) as 'object' FROM geo.data 

I just changed the AsWKT() function to AsWKT() in a SQL query (from text to binary formatting in MySQL).

So, the result of this query will be:

enter image description here

In the lines:

 var polygon = (byte[])reader["object"]; var obj = new MySqlGeometry(MySqlDbType.Blob, polygon); 

You can see that I am extracting a BLOB object and then converting it to a System.Byte[] array, and only then I try to create MySqlGeomerty , but I am very sorry and it looks like MySQL Libraries identify this object as a POINT , not a Polygon .

Evidence:

enter image description here

But!!! I definitely have a Polygon object in MySQL with the following SQL query:

 SELECT GeometryType(GeomFromText(AsWKT(object))) as `type`, AsWKT(object) as `data` FROM geo.data 

Evidence:

enter image description here

It was a BLOB object.

Parsing geometry from System.String

Now ... Submit the original source with BLOB comments.

Let's look at the lines:

 var polygon = reader["object"].ToString(); var obj = MySqlGeometry.Parse(polygon); 

And change the SQL query in the source code of the C # application to:

 SELECT AsWKT(object) as 'object' FROM geo.data 

Yes ... MySQL libraries for .NET provide an allegedly different style of building geometries, from System.String .

But, when I try to parse var polygon , which is extracted correctly, as you saw above, I get the following error:

 System.FormatException: String does not contain a valid geometry value 

Evidence:

enter image description hereenter image description here

It all looks like this: MySQL libraries do not provide complete structures for binding data from the MySQL server.

+8
c # mysql serialization geometry blob
source share
1 answer

I also asked a similar question in the official MySQL forum, here:

http://forums.mysql.com/read.php?38,596620,596620

One person from the Oracle team ... Roberto Ezequiel Garcia Ballesteros answered me that the MySQL.NET driver does not currently support this type of geometry:

http://forums.mysql.com/read.php?38,596620,596746#msg-596746

Hi Oleg,

I am afraid that we support only Point and not Polygon. I apologize for the inconvenience.

Cheers, Roberto

0
source share

All Articles