这可能会对您有所帮助,但它在 Perl 中进行了测试。
编辑您需要一个正则表达式处理工具来管理此类工作。
我使用了RegexFormat4它采用了带括号的字符串并格式化以获得缩进。然后它逃脱了文字。我将零件剪切并粘贴在一起,分别压缩,然后压缩整个东西。在 Perl 中测试,大约需要 10 分钟。
您可以添加您需要的任何其他组合,但我建议使用该工具来处理此类事情。
祝你好运!
# (MULTIPOLYGON\(\(\([^)]+\)\)\))|(MULTIPOLYGON\(\(\([^)]+\)(?:,\([^)]+\))+\)\))|(MULTIPOLYGON\(\(\([^)]+\)\)(?:,\(\([^)]+\)\))+\))|(MULTIPOLYGON\((?:(?:(?:(?<=\)),|)\(\([^)]+\)\))*(?:(?:(?<=\)),|)\(\([^)]+\)(?:,\([^)]+\))+\))+(?:(?:(?<=\)),|)\(\([^)]+\)\))*)+\))
( # (1)
# A single multipolygon with no holes:
# MULTIPOLYGON\(\(\([^)]+\)\)\)
MULTIPOLYGON
\(
\(
\( [^)]+ \)
\)
\)
)
|
( # (2)
# A single multipolygon with one (or more) hole:
# MULTIPOLYGON\(\(\([^)]+\)(?:,\([^)]+\))+\)\)
MULTIPOLYGON
\(
\(
\( [^)]+ \)
(?: , \( [^)]+ \) )+
\)
\)
)
|
( # (3)
# Several multipolygons with no holes:
# MULTIPOLYGON\(\(\([^)]+\)\)(?:,\(\([^)]+\)\))+\)
MULTIPOLYGON
\(
\(
\( [^)]+ \)
\)
(?:
,
\(
\( [^)]+ \)
\)
)+
\)
)
|
( # (4)
# Several multipolygons where at least one has a hole:
# MULTIPOLYGON\((?:(?:(?:(?<=\)),|)\(\([^)]+\)\))*(?:(?:(?<=\)),|)\(\([^)]+\)(?:,\([^)]+\))+\))+(?:(?:(?<=\)),|)\(\([^)]+\)\))*)+\)
MULTIPOLYGON
\(
(?:
(?:
(?:
(?<= \) )
,
|
)
\(
\( [^)]+ \)
\)
)*
(?:
(?:
(?<= \) )
,
|
)
\(
\( [^)]+ \)
(?: , \( [^)]+ \) )+
\)
)+
(?:
(?:
(?<= \) )
,
|
)
\(
\( [^)]+ \)
\)
)*
)+
\)
)
Perl 测试用例
my $str = <DATA>;
while ( $str =~ /(MULTIPOLYGON\(\(\([^)]+\)\)\))|(MULTIPOLYGON\(\(\([^)]+\)(?:,\([^)]+\))+\)\))|(MULTIPOLYGON\(\(\([^)]+\)\)(?:,\(\([^)]+\)\))+\))|(MULTIPOLYGON\((?:(?:(?:(?<=\)),|)\(\([^)]+\)\))*(?:(?:(?<=\)),|)\(\([^)]+\)(?:,\([^)]+\))+\))+(?:(?:(?<=\)),|)\(\([^)]+\)\))*)+\))/g )
{
if ( defined $1 )
{ print "1 - '$1'\n----------\n"; }
if ( defined $2 )
{ print "2 - '$2'\n----------\n"; }
if ( defined $3 )
{ print "3 - '$3'\n----------\n"; }
if ( defined $4 )
{ print "4 - '$4'\n----------\n"; }
}
__DATA__
A single multipolygon with no holes:
MULTIPOLYGON(((11 -17, -8 -1, 14 -8, 18 -17, 3 -11, 0 18, -17 -12, -17 -10, -10 -13)))
A single multipolygon with one hole:
MULTIPOLYGON(((14 7, -12 18, -13 -12, -7 19, 0 -16, 11 16, 19 18),(5 -11, -12 1, 0 -4, 1 -1)))
Several multipolygons with no holes:
MULTIPOLYGON(((14 11, -14 -16, 16 18, 6 -8, -14 6, -20 -5, 12 -1, 2 -19, -15 10, 7 2)),((-16 -15, -16 -15, 19 -2, -2 -13, 3 -19, -16 14, -1 -20)),((0 2, -18 8, -20 17, 12 5, 13 17, -9 -8, -20 -8, 20 -6, -12 0, -9 -4, -5 -14, -16 -19)),((-15 -16, -14 2, 19 -18, 4 8, 18 -1, -2 -13)),((-10 9, -12 15, -16 20, -15 -13, -17 16, -11 3, 18 -13, -3 13, -6 1, 2 12)))
Several multipolygons where at least one has a hole:
MULTIPOLYGON(((-8 0, 10 -7, 15 0, 0 14, -11 -13, -15 -5),(-6 -19, -18 -8, -9 -18, -1 2, 10 -8, -1 -12, -9 -16)),((0 19, -8 -10, -12 -12, 15 -20, 9 9, 16 5),(8 4, 8 0, 2 7, -17 8, 13 17, -6 -7)),((-9 -1, 19 9, -15 -11, -4 -14, -3 18),(-4 -15, 7 8, 5 -6, 20 13, 0 7, -10 -18)),((19 0, -13 1, -10 -12, -8 7, -1 14, 17 11),(0 -10, -1 -20, -14 7)),((-20 -7, 3 -7, 15 2, -7 -7),(9 -18, 13 -2, -15 -8, -2 -9)),((-18 8, 4 15, -1 -12, -13 18, 8 -17, -14 -19, -7 -13, 1 2, -11 -15, 5 20, 12 -14, 4 -10, -17 8, -6 15, -18 15)),((15 -2, 14 2, 17 -2, 6 3, -16 2),(7 0, 17 10, 17 -17, 13 -3, 1 -8)))
输出>>
1 - 'MULTIPOLYGON(((11 -17, -8 -1, 14 -8, 18 -17, 3 -11, 0 18, -17 -12, -17 -10,
-10 -13)))'
----------
2 - 'MULTIPOLYGON(((14 7, -12 18, -13 -12, -7 19, 0 -16, 11 16, 19 18),(5 -11, -
12 1, 0 -4, 1 -1)))'
----------
3 - 'MULTIPOLYGON(((14 11, -14 -16, 16 18, 6 -8, -14 6, -20 -5, 12 -1, 2 -19, -1
5 10, 7 2)),((-16 -15, -16 -15, 19 -2, -2 -13, 3 -19, -16 14, -1 -20)),((0 2, -1
8 8, -20 17, 12 5, 13 17, -9 -8, -20 -8, 20 -6, -12 0, -9 -4, -5 -14, -16 -19)),
((-15 -16, -14 2, 19 -18, 4 8, 18 -1, -2 -13)),((-10 9, -12 15, -16 20, -15 -13,
-17 16, -11 3, 18 -13, -3 13, -6 1, 2 12)))'
----------
4 - 'MULTIPOLYGON(((-8 0, 10 -7, 15 0, 0 14, -11 -13, -15 -5),(-6 -19, -18 -8, -
9 -18, -1 2, 10 -8, -1 -12, -9 -16)),((0 19, -8 -10, -12 -12, 15 -20, 9 9, 16 5)
,(8 4, 8 0, 2 7, -17 8, 13 17, -6 -7)),((-9 -1, 19 9, -15 -11, -4 -14, -3 18),(-
4 -15, 7 8, 5 -6, 20 13, 0 7, -10 -18)),((19 0, -13 1, -10 -12, -8 7, -1 14, 17
11),(0 -10, -1 -20, -14 7)),((-20 -7, 3 -7, 15 2, -7 -7),(9 -18, 13 -2, -15 -8,
-2 -9)),((-18 8, 4 15, -1 -12, -13 18, 8 -17, -14 -19, -7 -13, 1 2, -11 -15, 5 2
0, 12 -14, 4 -10, -17 8, -6 15, -18 15)),((15 -2, 14 2, 17 -2, 6 3, -16 2),(7 0,
17 10, 17 -17, 13 -3, 1 -8)))'
----------