多边形(Polygon)并不是一个简单的多边形,而是由多个多边形(环)组成,并且有可能嵌套,也就是分外环与内环,其中内环是可选项,
外环的点按顺时针排序,内环的点按逆时针排序

一个环的POLYGON:
POLYGON((121.415703 31.172893,121.415805 31.172664,121.416127 31.172751,121.41603 31.172976,121.415703 31.172893))
多个环并有内环的POLYGON:
POLYGON ((30 20, 45 40, 10 40, 30 20), (20 30, 35 35, 30 20, 20 30), (25 25, 30 35, 15 30, 25 25))

在mysql中的存储格式
        头部(Header):
            SRID
            字节顺序(Byte Order):表示二进制数据的字节顺序,通常为大端序(Big Endian)或小端序(Little Endian)。
            类型标识符(Type Identifier):标识几何对象的类型,对于多边形(Polygon)来说,它的值是十进制的3。
            环的数量(Number of Rings):表示多边形中环的数量,包括外部环和内部环(孔)。
        外部环(Exterior Ring):
            点的数量(Number of Points):表示构成外部环的点的数量。
            点的坐标(Coordinates):按照顺序列出外部环中每个点的坐标,每个点的坐标由X和Y值组成。
        内部环(Interior Rings)(可选):
            环的数量(Number of Rings):表示内部环的数量。
            点的数量(Number of Points):表示每个内部环中点的数量。
            点的坐标(Coordinates):按照顺序列出每个内部环中每个点的坐标,每个点的坐标由X和Y值组成。

单个环
POLYGON((121.415703 31.172893,121.415805 31.172664,121.416127 31.172751,121.41603 31.172976,121.415703 31.172893)
bytes[97]:
00 00 00 00, 01, 03 00 00 00, 01 00 00 00, 05 00 00 00, \
57 76 C1 E0 9A 5A 5E 40, 13 B5 34 B7 42 2C 3F 40, DA 20 93 8C 9C 5A 5E 40, 51 32 39 B5 33 2C 3F 40, E3 FE 23 D3 A1 5A 5E 40, \
EF 59 D7 68 39 2C 3F 40, EA 09 4B 3C A0 5A 5E 40, 2E FE B6 27 48 2C 3F 40, 57 76 C1 E0 9A 5A 5E 40, 13 B5 34 B7 42 2C 3F 40 
component        size(起-止) decimal      hex
SRID            4(0-3)       0            00 00 00 00
Byte order        1(4-4)     1            01
WKB type        4(5-8)       3            03 00 00 00
rings count     4(9-12)      1            01 00 00 00
外部环
points count    4(13-16)     5            05 00 00 00
X(经度)          8(17-24)    121.415703   57 76 C1 E0 9A 5A 5E 40
Y(纬度)          8(25-32)    31.172893    13 B5 34 B7 42 2C 3F 40
X(经度)          8(33-40)    121.415805   DA 20 93 8C 9C 5A 5E 40
Y(纬度)          8(41-48)    31.172664    51 32 39 B5 33 2C 3F 40
X(经度)          8(49-56)    121.416127   E3 FE 23 D3 A1 5A 5E 40
Y(纬度)          8(57-64)    31.172751    EF 59 D7 68 39 2C 3F 40
X(经度)          8(65-72)    121.41603    EA 09 4B 3C A0 5A 5E 40
Y(纬度)          8(73-80)    31.172976    2E FE B6 27 48 2C 3F 40
X(经度)          8(81-88)    121.415703   57 76 C1 E0 9A 5A 5E 40
Y(纬度)          8(89-96)    31.172893    13 B5 34 B7 42 2C 3F 40

多个环(含内部环)
POLYGON ((30 20, 45 40, 10 40, 30 20), (20 30, 35 35, 30 20, 20 30), (25 25, 30 35, 15 30, 25 25))
bytes[217]
00 00 00 00, 01, 03 00 00 00, 03 00 00 00,
04 00 00 00, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 00 34 40, 00 00 00 00 00 80 46 40, 00 00 00 00 00 00 44 40, 00 00 00 00 00 00 24 40, 00 00 00 00 00 00 44 40, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 00 34 40,
04 00 00 00, 00 00 00 00 00 00 34 40, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 80 41 40, 00 00 00 00 00 80 41 40, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 00 34 40, 00 00 00 00 00 00 34 40, 00 00 00 00 00 00 3E 40,
04 00 00 00, 00 00 00 00 00 00 39 40, 00 00 00 00 00 00 39 40, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 80 41 40, 00 00 00 00 00 00 2E 40, 00 00 00 00 00 00 3E 40, 00 00 00 00 00 00 39 40 ,00 00 00 00 00 00 39 40
component        size(起-止)   decimal      hex
SRID             4(0-3)        0            00 00 00 00
Byte order       1(4-4)        1            01
WKB type         4(5-8)        1            03 00 00 00
rings count      4(9-12)       3            03 00 00 00
外环(注意这里的外环只能有一个,如果有多个就是MultiPolygon了)
外环points数量   4(13-16)      4            04 00 00 00
X(经度)          8(17-24)     30            00 00 00 00 00 00 3E 40
Y(纬度)          8(25-32)     20            00 00 00 00 00 00 34 40
X(经度)          8(33-40)     45            00 00 00 00 00 80 46 40
Y(纬度)          8(41-48)     40            00 00 00 00 00 00 44 40
X(经度)          8(49-56)     10            00 00 00 00 00 00 24 40
Y(纬度)          8(57-64)     40            00 00 00 00 00 00 44 40
X(经度)          8(65-72)     30            00 00 00 00 00 00 3E 40
Y(纬度)          8(73-80)     20            00 00 00 00 00 00 34 40
内部环
points count     4(81-84)      4            04 00 00 00
X(经度)          8(85-92)     20            00 00 00 00 00 00 34 40
Y(纬度)          8(93-100)    30            00 00 00 00 00 00 3E 40
X(经度)          8(101-108)   35            00 00 00 00 00 80 41 40
Y(纬度)          8(109-116)   35            00 00 00 00 00 80 41 40
X(经度)          8(117-124)   30            00 00 00 00 00 00 3E 40
Y(纬度)          8(125-132)   20            00 00 00 00 00 00 34 40
X(经度)          8(133-140)   20            00 00 00 00 00 00 34 40
Y(纬度)          8(141-148)   30            00 00 00 00 00 00 3E 40
points count     4(149-152)    4            04 00 00 00
X(经度)          8(153-160)   25            00 00 00 00 00 00 39 40
Y(纬度)          8(161-168)   25            00 00 00 00 00 00 39 40
X(经度)          8(169-176)   30            00 00 00 00 00 00 3E 40
Y(纬度)          8(177-184)   35            00 00 00 00 00 80 41 40
X(经度)          8(185-192)   15            00 00 00 00 00 00 2E 40
Y(纬度)          8(193-200)   30            00 00 00 00 00 00 3E 40
X(经度)          8(201-208)   25            00 00 00 00 00 00 39 40
X(经度)          8(209-216)   25            00 00 00 00 00 00 39 40


Java解析以上结构,为了便于理解我们逐个字节解析(实际应用中不会这样解析,具体参考最后的源码)


boolean bigEndian = (bytes[4] == 0x00);
Polygon polygon = new Polygon();
//环数量
int index = 9;
int ring_count = NumberUtil.byte2int(bytes, index, 4, bigEndian);
index+=4;
//外环(只有一个)
//外环中Point数量
int point_count = NumberUtil.byte2int(bytes, index, 4, bigEndian);
index+=4;
List<Point> points = new ArrayList<>();
for(int p=0; p<point_count; p++){
	double x = NumberUtil.byte2double(bytes, index);
	index+=8;
	double y = NumberUtil.byte2double(bytes, index);
	index+=8;
	Point point = new Point(x, y);
	points.add(point);
}
Ring out = new Ring(points);
out.clockwise(true);
polygon.add(out);
if(ring_count > 1){
	//内环(可能有多个)
	for(int r=1; r<ring_count; r++){
		//内环中Point数量
		points = new ArrayList<>();
		point_count = NumberUtil.byte2int(bytes, index, 4, bigEndian);
		index+=4;
		for(int p=0; p<point_count; p++){
			double x = NumberUtil.byte2double(bytes, index);
			index+=8;
			double y = NumberUtil.byte2double(bytes, index);
			index+=8;
			Point point = new Point(x, y);
			points.add(point);
		}
		Ring in = new Ring(points);
		in.clockwise(false);
		polygon.add(in);
	}
}

源码参考:http://gitee.com/anyline/anyline/blob/master/anyline-data-jdbc-dialect/anyline-data-jdbc-mysql/src/main/java/org/anyline/data/jdbc/mysql/MySQLGeometryAdapter.java 

NumberUtil参考:http://gitee.com/anyline/anyline/blob/master/anyline-core/src/main/java/org/anyline/util/NumberUtil.java